Exemple #1
0
        public HttpResponseMessage GetActions(Guid inventorizationId)
        {
            var claims              = Request.GetOwinContext().Authentication.User;
            var inventorization     = _inventorizationRepository.GetInventorization(inventorizationId);
            var actions             = inventorizationDomain.GetActions(inventorizationId);
            var zones               = _zoneRepository.GetZones(actions.Select(x => x.Zone).ToArray());
            var items               = _companyRepository.GetItems(inventorization.Company, actions.Select(x => x.BarCode).ToArray());
            List <ZoneState> states = _inventorizationRepository.GetZoneStates(inventorizationId).Where(x => x.ZoneId != Guid.Empty).ToList();
            var result              = actions.Select(x =>
            {
                var foundItem  = items.FirstOrDefault(i => i.Code == x.BarCode);
                var foundZone  = zones.First(z => z.Id == x.Zone);
                var foundState = states.FirstOrDefault(z => z.ZoneId == foundZone.Id);

                var zoneVm = new ZoneViewModel()
                {
                    ZoneId   = foundZone.Id,
                    Number   = foundZone.Number,
                    ClosedAt = foundState?.ClosedAt,
                    ClosedBy = foundState?.ClosedBy,
                    OpenedAt = foundState?.OpenedAt,
                    OpenedBy = foundState?.OpenedBy,
                    ZoneName = foundZone.Name
                };
                var res = new ViewModels.Action()
                {
                    Id              = x.Id,
                    DateTime        = x.DateTime,
                    Quantity        = x.Quantity,
                    Type            = x.Type,
                    User            = x.UserId.ToString(),
                    Inventorization = x.Inventorization,
                    Zone            = zoneVm,
                    BarCode         = x.BarCode,
                    FoundInItems    = foundItem != null,
                    Name            = foundItem != null ? foundItem.Name : "Не найдена в номенклатуре",
                    Description     = foundItem != null ? foundItem.Description : "Не найдена в номенклатуре",
                };
                return(res);
            });

            return(Request.CreateResponse(HttpStatusCode.OK, result.OrderByDescending(x => x.DateTime)));
        }
        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));
        }