public async Task <ActionResult> CreateUnload(CreateUnloadDto dto)
        {
            var created = await _unloadService.CreateAsync(dto);

            foreach (var items in dto.UnloadDetails)
            {
                var check = await _vanStockService.CheckIfExist(items.ProductId, dto.VanId);

                var check2 = await _stockService.CheckIfExist(items.ProductId);

                if (check2 != null)
                {
                    check2.TotalPieces += items.TotalPieces;
                    check2.Amount      += items.Amount;
                    await _stockService.UpdateAsync(check2);
                }

                if (check != null)
                {
                    check.TotalPieces -= items.TotalPieces;
                    check.Amount      -= items.Amount;
                    await _vanStockService.UpdateAsync(check);
                }
            }

            return(Ok(created));
        }
Example #2
0
        public async Task <ActionResult> CreateWithdrawal(CreateWithdrawalDto dto)
        {
            var created = await _withdrawalService.CreateAsync(dto);

            foreach (var items in dto.WithdrawalDetails)
            {
                var check = await _vanStockService.CheckIfExist(items.ProductId, dto.VanId);

                var check2 = await _stockService.CheckIfExist(items.ProductId);

                if (check2 != null)
                {
                    check2.TotalPieces -= items.TotalPieces;
                    check2.Amount      -= items.Amount;
                    await _stockService.UpdateAsync(check2);
                }

                if (check != null)
                {
                    check.TotalPieces += items.TotalPieces;
                    check.Amount      += items.Amount;
                    await _vanStockService.UpdateAsync(check);
                }
                else
                {
                    var stocks = new VanStockDto
                    {
                        ProductId     = items.ProductId,
                        TotalPieces   = items.TotalPieces,
                        PricePerPiece = items.PricePerPiece,
                        Amount        = items.Amount,
                        VanId         = dto.VanId
                    };
                    await _vanStockService.CreateAsync(stocks);
                }
            }

            return(Ok(created));
        }