public async Task <IActionResult> Get(string id)
        {
            Guid guid = Guid.Parse(id);

            VerifyUser();

            GarmentExpenditureGoodReturnDto garmentExpenditureGoodReturnDto = _garmentExpenditureGoodReturnRepository.Find(o => o.Identity == guid).Select(retur => new GarmentExpenditureGoodReturnDto(retur)
            {
                Items = _garmentExpenditureGoodReturnItemRepository.Find(o => o.ReturId == retur.Identity).OrderBy(i => i.Description).ThenBy(i => i.SizeName).Select(returItem => new GarmentExpenditureGoodReturnItemDto(returItem)
                {
                }).ToList()
            }
                                                                                                                                                           ).FirstOrDefault();

            await Task.Yield();

            return(Ok(garmentExpenditureGoodReturnDto));
        }
Exemplo n.º 2
0
        public async Task<GarmentExpenditureGoodReturn> Handle(RemoveGarmentExpenditureGoodReturnCommand request, CancellationToken cancellationToken)
        {
            var ExpenditureGoodReturn = _garmentExpenditureGoodReturnRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentExpenditureGoodReturn(o)).Single();
            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && new UnitDepartmentId(a.UnitId) == ExpenditureGoodReturn.UnitId && new GarmentComodityId(a.ComodityId) == ExpenditureGoodReturn.ComodityId).Select(s => new GarmentComodityPrice(s)).Single();

            Dictionary<Guid, double> finStockToBeUpdated = new Dictionary<Guid, double>();
            Dictionary<Guid, double> exGoodToBeUpdated = new Dictionary<Guid, double>();

            _garmentExpenditureGoodReturnItemRepository.Find(o => o.ReturId == ExpenditureGoodReturn.Identity).ForEach(async expenditureReturnItem =>
            {
                if (finStockToBeUpdated.ContainsKey(expenditureReturnItem.FinishedGoodStockId))
                {
                    finStockToBeUpdated[expenditureReturnItem.FinishedGoodStockId] += expenditureReturnItem.Quantity;
                }
                else
                {
                    finStockToBeUpdated.Add(expenditureReturnItem.FinishedGoodStockId, expenditureReturnItem.Quantity);
                }

                if (exGoodToBeUpdated.ContainsKey(expenditureReturnItem.ExpenditureGoodItemId))
                {
                    exGoodToBeUpdated[expenditureReturnItem.ExpenditureGoodItemId] += expenditureReturnItem.Quantity;
                }
                else
                {
                    exGoodToBeUpdated.Add(expenditureReturnItem.ExpenditureGoodItemId, expenditureReturnItem.Quantity);
                }

                GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(a => a.ExpenditureGoodReturnItemId == expenditureReturnItem.Identity).Select(a => new GarmentFinishedGoodStockHistory(a)).Single();
                garmentFinishedGoodStockHistory.Remove();
                await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);

                expenditureReturnItem.Remove();
                await _garmentExpenditureGoodReturnItemRepository.Update(expenditureReturnItem);
            });

            foreach (var finStock in finStockToBeUpdated)
            {
                var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == finStock.Key).Select(s => new GarmentFinishedGoodStock(s)).Single();
                var qty = garmentFinishingGoodStockItem.Quantity - finStock.Value;
                garmentFinishingGoodStockItem.SetQuantity(qty);
                garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (qty));
                garmentFinishingGoodStockItem.Modify();

                await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem);
            }

            foreach (var exGood in exGoodToBeUpdated)
            {
                var garmentExpenditureGoodItem = _garmentExpenditureGoodItemRepository.Query.Where(x => x.Identity == exGood.Key).Select(s => new GarmentExpenditureGoodItem(s)).Single();
                var qty = garmentExpenditureGoodItem.ReturQuantity - exGood.Value;
                garmentExpenditureGoodItem.SetReturQuantity(qty);
                garmentExpenditureGoodItem.Modify();

                await _garmentExpenditureGoodItemRepository.Update(garmentExpenditureGoodItem);
            }

            ExpenditureGoodReturn.Remove();
            await _garmentExpenditureGoodReturnRepository.Update(ExpenditureGoodReturn);

            _storage.Save();

            return ExpenditureGoodReturn;
        }