Exemplo n.º 1
0
        public async Task <ActionResult> CreatePurchaseOrder(CreatePurchaseOrderDto dto)
        {
            await _purchaseOderService.CreateAsync(dto);

            foreach (var items in dto.PurchaseOrderDetails)
            {
                var check = await _stockService.CheckIfExist(items.ProductId);

                if (check != null)
                {
                    check.TotalPieces += items.TotalPieces;
                    check.Amount      += items.Amount;
                    await _stockService.UpdateAsync(check);
                }
                else
                {
                    var stocks = new StockDto
                    {
                        ProductId     = items.ProductId,
                        TotalPieces   = items.TotalPieces,
                        PricePerPiece = items.PricePerPiece,
                        Amount        = items.Amount
                    };

                    await _stockService.CreateAsync(stocks);
                }
            }

            return(Ok(dto));
        }
        public async Task <ActionResult> CreateStocks(CreateStockDto input)
        {
            foreach (var items in input.Stocks)
            {
                var check = await _stockService.CheckIfExist(items.ProductId);

                if (check != null)
                {
                    check.TotalPieces += items.TotalPieces;
                    check.Amount      += items.Amount;

                    await _stockService.UpdateAsync(check);
                }
                else
                {
                    var stocks = new StockDto
                    {
                        ProductId     = items.ProductId,
                        TotalPieces   = items.TotalPieces,
                        PricePerPiece = items.PricePerPiece,
                        Amount        = items.Amount
                    };

                    await _stockService.CreateAsync(stocks);
                }
            }
            return(Ok(input.Stocks));
        }