public async Task <ActionResult <object> > GetWarehouse([FromQuery] PaginationParametersModel pagingParameters, [FromRoute] int id)
        {
            WarehouseObjectModel warehouse = await _context.Warehouses.Include(x => x.Avatar).FirstOrDefaultAsync(x => x.Id == id);

            if (warehouse == null)
            {
                _logger.LogError("Склад не найден: id={0}", id);
                return(new ObjectResult(new ServerActionResult()
                {
                    Success = false,
                    Info = "Склад не найден",
                    Status = StylesMessageEnum.danger.ToString()
                }));
            }

            IQueryable <WarehouseDocumentsModel> wDocuments = _context.WarehouseDocuments
                                                              .Where(wDoc => wDoc.WarehouseReceiptId == id || (wDoc.Discriminator == nameof(InternalDisplacementWarehouseDocumentModel) && ((InternalDisplacementWarehouseDocumentModel)wDoc).WarehouseDebitingId == id)).OrderBy(x => x.Id);

            pagingParameters.Init(await wDocuments.CountAsync());
            if (pagingParameters.PageNum > 1)
            {
                wDocuments = wDocuments.Skip(pagingParameters.Skip);
            }

            wDocuments = wDocuments.Take(pagingParameters.PageSize)
                         .Include(wDoc => wDoc.Author)
                         .Include(wDoc => wDoc.WarehouseReceipt);

            HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString());

            return(new ObjectResult(new ServerActionResult()
            {
                Success = true,
                Info = "Запрос номенклатуры обработан",
                Status = StylesMessageEnum.success.ToString(),
                Tag = new
                {
                    warehouse.Id,
                    warehouse.Name,
                    warehouse.Information,

                    warehouse.isDisabled,
                    warehouse.isGlobalFavorite,
                    warehouse.isReadonly,

                    Documents = (await wDocuments.ToListAsync()).Select(wDoc => BodyGoodMovementDocumentModel.getDocument(wDoc, _context)),

                    Avatar = new
                    {
                        warehouse.Avatar?.Id,
                        warehouse.Avatar?.Name
                    },

                    noDelete = _context.WarehouseDocuments.Any(wDoc => wDoc.WarehouseReceiptId == id) ||
                               _context.InternalDisplacementWarehouseDocuments.Any(dwDoc => dwDoc.WarehouseDebitingId == id) ||
                               _context.InventoryGoodsBalancesWarehouses.Any(x => x.WarehouseId == id)
                }
            }));
        }
예제 #2
0
        public async Task <ActionResult <object> > GetGood([FromQuery] PaginationParametersModel pagingParameters, int id)
        {
            GoodObjectModel good = await _context.Goods
                                   .Where(x => x.Id == id)
                                   .Include(x => x.Avatar)
                                   .Include(x => x.Unit)
                                   .Include(x => x.Group)
                                   .FirstOrDefaultAsync();

            if (good == null)
            {
                _logger.LogError("Номенклатура не найдена: id={0}", id);
                return(new ObjectResult(new ServerActionResult()
                {
                    Success = false,
                    Info = "Номенклатура не найдена",
                    Status = StylesMessageEnum.danger.ToString()
                }));
            }

            IQueryable <RowGoodMovementRegisterModel> goodRegisters = _context.GoodMovementDocumentRows.Where(x => x.GoodId == id);

            pagingParameters.Init(await goodRegisters.CountAsync());

            goodRegisters = goodRegisters.OrderBy(x => x.Id);
            if (pagingParameters.PageNum > 1)
            {
                goodRegisters = goodRegisters.Skip(pagingParameters.Skip);
            }

            HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString());

            goodRegisters = goodRegisters
                            .Take(pagingParameters.PageSize)
                            .Include(x => x.BodyDocument).ThenInclude(x => x.Author);

            return(new ObjectResult(new ServerActionResult()
            {
                Success = true,
                Info = "Запрос номенклатуры обработан",
                Status = StylesMessageEnum.success.ToString(),
                Tag = new
                {
                    good.Id,
                    good.Name,
                    good.Information,
                    good.Price,
                    good.GroupId,
                    good.UnitId,

                    good.isReadonly,
                    good.isDisabled,
                    good.isGlobalFavorite,

                    noDelete = await _context.GoodMovementDocumentRows.AnyAsync(x => x.GoodId == id) || await _context.InventoryGoodsBalancesDeliveries.AnyAsync(x => x.GoodId == id) || await _context.InventoryGoodsBalancesWarehouses.AnyAsync(x => x.GoodId == id),

                    Avatar = new
                    {
                        id = good.AvatarId,
                        good.Avatar?.Name
                    },

                    Units = await _context.Units.Select(x => new
                    {
                        x.Id,
                        x.Name,
                        x.Information
                    }).ToListAsync(),
                    Groups = await _context.GroupsGoods.Select(x => new
                    {
                        x.Id,
                        x.Name,
                        x.Information
                    }).ToListAsync(),

                    Registers = await goodRegisters
                                .Select(x => new
                    {
                        x.Id,
                        Document = BodyGoodMovementDocumentModel.getDocument(x.BodyDocument, _context),
                        x.Quantity,
                        x.UnitId
                    }).ToListAsync()
                }
            }));
        }