Exemple #1
0
        public async Task <GarmentAvalComponent> Handle(PlaceGarmentAvalComponentCommand request, CancellationToken cancellationToken)
        {
            GarmentComodity garmentComodity = request.Comodity ?? new GarmentComodity(0, null, null);

            var avalComponentNo = GenerateNo(request);

            GarmentAvalComponent garmentAvalComponent = new GarmentAvalComponent(
                Guid.NewGuid(),
                avalComponentNo,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.AvalComponentType,
                request.RONo,
                request.Article,
                new GarmentComodityId(garmentComodity.Id),
                garmentComodity.Code,
                garmentComodity.Name,
                request.Date.GetValueOrDefault()
                );

            foreach (var item in request.Items.Where(w => w.IsSave))
            {
                SizeValueObject sizeValueObject = item.Size ?? new SizeValueObject(0, null);

                GarmentAvalComponentItem garmentAvalComponentItem = new GarmentAvalComponentItem(
                    Guid.NewGuid(),
                    garmentAvalComponent.Identity,
                    item.CuttingInDetailId,
                    item.SewingOutItemId,
                    item.SewingOutDetailId,
                    new ProductId(item.Product.Id),
                    item.Product.Code,
                    item.Product.Name,
                    item.DesignColor,
                    item.Color,
                    item.Quantity,
                    item.Quantity,
                    new SizeId(sizeValueObject.Id),
                    sizeValueObject.Size,
                    item.Price,
                    item.BasicPrice
                    );

                await _garmentAvalComponentItemRepository.Update(garmentAvalComponentItem);

                if (garmentAvalComponent.AvalComponentType == "CUTTING")
                {
                    var cuttingInDetail = _garmentCuttingInDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.CuttingInDetailId).SingleOrDefault();

                    if (cuttingInDetail == null)
                    {
                        throw new Exception($"CuttingInDetail {garmentAvalComponentItem.CuttingInDetailId} not found");
                    }
                    else
                    {
                        cuttingInDetail.SetRemainingQuantity(cuttingInDetail.RemainingQuantity - garmentAvalComponentItem.Quantity);
                        cuttingInDetail.Modify();
                        await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                    }
                }
                else if (garmentAvalComponent.AvalComponentType == "SEWING")
                {
                    //if (item.IsDifferentSize)
                    //{
                    //    var sewingOutDetail = _garmentSewingOutDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutDetailId).SingleOrDefault();

                    //    if (sewingOutDetail == null)
                    //    {
                    //        throw new Exception($"SewingOutDetail {garmentAvalComponentItem.SewingOutDetailId} not found");
                    //    }
                    //    //else
                    //    //{
                    //    //    sewingOutDetail.Modify();
                    //    //    await _garmentSewingOutDetailRepository.Update(sewingOutDetail);
                    //    //}
                    //}
                    //else
                    //{
                    var sewingOutItem = _garmentSewingOutItemRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutItemId).SingleOrDefault();

                    if (sewingOutItem == null)
                    {
                        throw new Exception($"SewingOutItem {garmentAvalComponentItem.SewingOutItemId} not found");
                    }
                    else
                    {
                        sewingOutItem.SetRemainingQuantity(sewingOutItem.RemainingQuantity - garmentAvalComponentItem.Quantity);
                        sewingOutItem.Modify();
                        await _garmentSewingOutItemRepository.Update(sewingOutItem);
                    }
                    //}
                }
            }

            await _garmentAvalComponentRepository.Update(garmentAvalComponent);

            _storage.Save();

            return(garmentAvalComponent);
        }
Exemple #2
0
        public async Task <GarmentAvalComponent> Handle(RemoveGarmentAvalComponentCommand request, CancellationToken cancellationToken)
        {
            GarmentAvalComponent garmentAvalComponent = _garmentAvalComponentRepository.Query.Where(w => w.Identity == request.Identity).Select(s => new GarmentAvalComponent(s)).Single();

            _garmentAvalComponentItemRepository.Find(f => f.AvalComponentId == garmentAvalComponent.Identity).ForEach(async garmentAvalComponentItem =>
            {
                garmentAvalComponentItem.Remove();
                await _garmentAvalComponentItemRepository.Update(garmentAvalComponentItem);

                if (garmentAvalComponent.AvalComponentType == "CUTTING")
                {
                    var cuttingInDetail = _garmentCuttingInDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.CuttingInDetailId).SingleOrDefault();

                    if (cuttingInDetail == null)
                    {
                        throw new Exception($"CuttingInDetail {garmentAvalComponentItem.CuttingInDetailId} not found");
                    }
                    else
                    {
                        cuttingInDetail.SetRemainingQuantity(cuttingInDetail.RemainingQuantity + garmentAvalComponentItem.Quantity);
                        cuttingInDetail.Modify();
                        await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                    }
                }
                else if (garmentAvalComponent.AvalComponentType == "SEWING")
                {
                    //if (item.IsDifferentSize)
                    //{
                    //    var sewingOutDetail = _garmentSewingOutDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutDetailId).SingleOrDefault();

                    //    if (sewingOutDetail == null)
                    //    {
                    //        throw new Exception($"SewingOutDetail {garmentAvalComponentItem.SewingOutDetailId} not found");
                    //    }
                    //    //else
                    //    //{
                    //    //    sewingOutDetail.Modify();
                    //    //    await _garmentSewingOutDetailRepository.Update(sewingOutDetail);
                    //    //}
                    //}
                    //else
                    //{
                    var sewingOutItem = _garmentSewingOutItemRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutItemId).SingleOrDefault();

                    if (sewingOutItem == null)
                    {
                        throw new Exception($"SewingOutItem {garmentAvalComponentItem.SewingOutItemId} not found");
                    }
                    else
                    {
                        sewingOutItem.SetRemainingQuantity(sewingOutItem.RemainingQuantity + garmentAvalComponentItem.Quantity);
                        sewingOutItem.Modify();
                        await _garmentSewingOutItemRepository.Update(sewingOutItem);
                    }
                    //}
                }
            });

            garmentAvalComponent.Remove();
            await _garmentAvalComponentRepository.Update(garmentAvalComponent);

            _storage.Save();

            return(garmentAvalComponent);
        }