Guest User

Untitled

a guest
Jan 6th, 2015
304
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        
  2. // Action that get's called
  3.         [HttpGet, Route("api/setupGroups", Name = "GetSetupGroupsPaged")]
  4.         public HttpResponseMessage GetSetupGroupsPaged(int page = 1, int pageSize = 50)
  5.         {
  6.             page        = page.ToMinimum(MinimumPageIndex);
  7.             pageSize    = pageSize.ToBounds(MinimumPageSize, MaximumPageSize);
  8.  
  9.             HttpResponseMessage result = null;
  10.  
  11.             _setupGroupRepository.TryDo(repository =>
  12.             {
  13.                 var data = (repository.GetSetupGroups() as IQueryable<SetupGroup>)
  14.                                     .With(query => query.OrderBy(m => m.Id))
  15.                                     .Project()
  16.                                     .To<SetupGroupDto>()
  17.                                     .ToPagedList(page, pageSize);
  18.  
  19.                 result = Request.CreatePagedResponse("GetSetupGroupsPaged", HttpStatusCode.OK, data);
  20.             }).Catch(exception =>
  21.             {
  22.                 // TODO: log exception
  23.                 result = Request.CreateResponse(HttpStatusCode.InternalServerError,
  24.                     AppMessages.ERROR_UNKNOWN);
  25.             });
  26.  
  27.             return result;
  28.         }
  29.  
  30. // annotated method in the same controller
  31.  
  32.                 [UnitOfWork]
  33.         [HttpPost, Route("api/setupGroups/{setupGroupId:int}/mappings")]
  34.         public virtual HttpResponseMessage CreateSetupGroupMapping(int setupGroupId, CameraDisplayMapDto data)
  35.         {
  36.             if (!ModelState.IsValid)
  37.                 return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
  38.  
  39.             HttpResponseMessage result = null;
  40.  
  41.             _setupGroupRepository.TryDo(repository =>
  42.             {
  43.                 var setupGroup = repository.GetSetupGroupById(setupGroupId);
  44.                 if (setupGroup == null)
  45.                 {
  46.                     result = Request.CreateResponse(HttpStatusCode.NotFound);
  47.                     return;
  48.                 }
  49.  
  50.                 var cameraDisplayMap = Mapper.Map<CameraDisplayMap>(data);
  51.                 setupGroup.TryDo(x =>
  52.                 {
  53.                     x.AddMapping(cameraDisplayMap);
  54.                     repository.UpdateSetupGroup(x);
  55.  
  56.                     result = Request.CreateResponse(HttpStatusCode.Created);
  57.                 }, typeof(InvalidOperationException))
  58.                     .Catch(exception =>
  59.                     {
  60.                         // TODO: log exception
  61.                         result = Request.CreateResponse(HttpStatusCode.BadRequest);
  62.                     });
  63.             });
  64.  
  65.             return result;
  66.         }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×