예제 #1
0
 public HttpResponseMessage Zones(Guid inventorization)
 {
     //var response = Request.CreateResponse(HttpStatusCode.Redirect);
     //response.Headers.Location = new Uri("http://www.google.com");
     //return response;
     try
     {
         IOwinContext        ctx    = Request.GetOwinContext();
         ClaimsPrincipal     user   = ctx.Authentication.User;
         IEnumerable <Claim> claims = user.Claims;
         List <ZoneState>    states = _inventorizationRepository.GetZoneStates(inventorization).Where(x => x.ZoneId != Guid.Empty).ToList();
         List <ZoneModel>    zones  = _zoneRepository.GetAllZones().OrderBy(x => x.Name).ToList();
         return(Request.CreateResponse(HttpStatusCode.OK, zones.Select(x =>
         {
             List <Business.Model.Action> actions = inventorizationDomain.GetActions(inventorization).Where(i => i.Zone == x.Id).ToList();
             var state = states.FirstOrDefault(s => x.Id == s.ZoneId);
             return new ZoneViewModel()
             {
                 ZoneId = x.Id,
                 Number = x.Number,
                 ClosedAt = state != null && state.ClosedAt != null && state.ClosedAt < DateTime.MaxValue ? state.ClosedAt : null,
                 ClosedBy = state?.ClosedBy,
                 OpenedAt = state?.OpenedAt,
                 OpenedBy = state?.OpenedBy,
                 ZoneName = x.Name,
                 Status = state.GetStatus(),
                 TotalItems = actions.Sum(a => a.Quantity)
             };
         }).OrderBy(x => x.Number)));
     }
     catch (Exception ex)
     {
         _logger.Error(ex, $"Error getting zones. InventorizationId: {inventorization}");
     }
     return(Request.CreateResponse(HttpStatusCode.NoContent));
 }