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

            VerifyUser();

            GarmentExpenditureGoodDto garmentExpenditureGoodDto = _garmentExpenditureGoodRepository.Find(o => o.Identity == guid).Select(finishOut => new GarmentExpenditureGoodDto(finishOut)
            {
                Items = _garmentExpenditureGoodItemRepository.Find(o => o.ExpenditureGoodId == finishOut.Identity).OrderBy(a => a.Description).ThenBy(i => i.SizeName).Select(finishOutItem => new GarmentExpenditureGoodItemDto(finishOutItem)
                {
                }).ToList()
            }
                                                                                                                                         ).FirstOrDefault();

            await Task.Yield();

            return(Ok(garmentExpenditureGoodDto));
        }
Beispiel #2
0
        public async Task <GarmentExpenditureGood> Handle(RemoveGarmentExpenditureGoodCommand request, CancellationToken cancellationToken)
        {
            var ExpenditureGood = _garmentExpenditureGoodRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentExpenditureGood(o)).Single();
            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && new UnitDepartmentId(a.UnitId) == ExpenditureGood.UnitId && new GarmentComodityId(a.ComodityId) == ExpenditureGood.ComodityId).Select(s => new GarmentComodityPrice(s)).Single();

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

            _garmentExpenditureGoodItemRepository.Find(o => o.ExpenditureGoodId == ExpenditureGood.Identity).ForEach(async expenditureItem =>
            {
                if (finStockToBeUpdated.ContainsKey(expenditureItem.FinishedGoodStockId))
                {
                    finStockToBeUpdated[expenditureItem.FinishedGoodStockId] += expenditureItem.Quantity;
                }
                else
                {
                    finStockToBeUpdated.Add(expenditureItem.FinishedGoodStockId, expenditureItem.Quantity);
                }

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

                expenditureItem.Remove();
                await _garmentExpenditureGoodItemRepository.Update(expenditureItem);
            });

            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);
            }

            ExpenditureGood.Remove();
            await _garmentExpenditureGoodRepository.Update(ExpenditureGood);

            _storage.Save();

            return(ExpenditureGood);
        }
        public async Task <GarmentExpenditureGood> Handle(UpdateGarmentExpenditureGoodCommand request, CancellationToken cancellationToken)
        {
            var ExpenditureGood = _garmentExpenditureGoodRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentExpenditureGood(o)).Single();

            _garmentExpenditureGoodItemRepository.Find(o => o.ExpenditureGoodId == ExpenditureGood.Identity).ForEach(async expenditureItem =>
            {
                await _garmentExpenditureGoodItemRepository.Update(expenditureItem);
            });
            ExpenditureGood.SetCarton(request.Carton);
            ExpenditureGood.SetExpenditureDate(request.ExpenditureDate);
            ExpenditureGood.SetInvoice(request.Invoice);
            ExpenditureGood.SetIsReceived(request.IsReceived);
            ExpenditureGood.Modify();
            await _garmentExpenditureGoodRepository.Update(ExpenditureGood);

            _storage.Save();

            return(ExpenditureGood);
        }