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)); }
public HttpResponseMessage Get(Guid id) { var action = _actionRepository.GetAction(id); var zone = _zoneRepository.GetZone(action.Zone); var company = _inventorizationRepository.GetInventorization(action.Inventorization).Company; var items = _companyRepository.GetItems(company, new[] { action.BarCode }); List <ZoneState> states = _inventorizationRepository.GetZoneStates(action.Inventorization).Where(x => x.ZoneId != Guid.Empty).ToList(); var foundItem = items.FirstOrDefault(i => i.Code == action.BarCode); var foundState = states.FirstOrDefault(z => z.ZoneId == zone.Id); var zoneVm = new ZoneViewModel() { ZoneId = zone.Id, Number = zone.Number, ClosedAt = foundState?.ClosedAt, ClosedBy = foundState?.ClosedBy, OpenedAt = foundState?.OpenedAt, OpenedBy = foundState?.OpenedBy, ZoneName = zone.Name }; var res = new ViewModels.Action() { Id = action.Id, DateTime = action.DateTime, Quantity = action.Quantity, Type = action.Type, User = action.UserId.ToString(), Zone = zoneVm, BarCode = action.BarCode, FoundInItems = foundItem != null, Name = foundItem != null ? foundItem.Name : "Не найдена в номенклатуре", Description = foundItem != null ? foundItem.Description : "Не найдена в номенклатуре", }; return(Request.CreateResponse(HttpStatusCode.OK, res)); }