public async Task <GarmentSewingIn> Handle(RemoveGarmentSewingInCommand request, CancellationToken cancellationToken)
        {
            var garmentSewingIn = _garmentSewingInRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentSewingIn(o)).Single();

            if (garmentSewingIn == null)
            {
                throw Validator.ErrorValidation(("Id", "Invalid Id: " + request.Identity));
            }

            var garmentSewingInItems = _garmentSewingInItemRepository.Find(x => x.SewingInId == request.Identity);

            foreach (var item in garmentSewingInItems)
            {
                item.Remove();

                if (garmentSewingIn.SewingFrom == "CUTTING")
                {
                    var garmentLoadingItem = _garmentLoadingItemRepository.Query.Where(o => o.Identity == item.LoadingItemId).Select(s => new GarmentLoadingItem(s)).Single();

                    garmentLoadingItem.SetRemainingQuantity(garmentLoadingItem.RemainingQuantity + item.Quantity);

                    garmentLoadingItem.Modify();
                    await _garmentLoadingItemRepository.Update(garmentLoadingItem);
                }
                else if (garmentSewingIn.SewingFrom == "SEWING")
                {
                    var garmentSewingOutItem = _garmentSewingOutItemRepository.Query.Where(s => s.Identity == item.SewingOutItemId).Select(s => new GarmentSewingOutItem(s)).Single();

                    garmentSewingOutItem.SetRemainingQuantity(garmentSewingOutItem.RemainingQuantity + item.Quantity);

                    garmentSewingOutItem.Modify();
                    await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
                }
                else if (garmentSewingIn.SewingFrom == "FINISHING")
                {
                    var garmentFinishingOutItem = _garmentFinishingOutItemRepository.Query.Where(s => s.Identity == item.FinishingOutItemId).Select(s => new GarmentFinishingOutItem(s)).Single();

                    garmentFinishingOutItem.SetRemainingQuantity(garmentFinishingOutItem.RemainingQuantity + item.Quantity);

                    garmentFinishingOutItem.Modify();
                    await _garmentFinishingOutItemRepository.Update(garmentFinishingOutItem);
                }

                await _garmentSewingInItemRepository.Update(item);
            }

            garmentSewingIn.Remove();

            await _garmentSewingInRepository.Update(garmentSewingIn);

            _storage.Save();

            return(garmentSewingIn);
        }
Ejemplo n.º 2
0
        public async Task <GarmentLoading> Handle(UpdateGarmentLoadingCommand request, CancellationToken cancellationToken)
        {
            var loading = _garmentLoadingRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentLoading(o)).Single();

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

            _garmentLoadingItemRepository.Find(o => o.LoadingId == loading.Identity).ForEach(async loadingItem =>
            {
                var itemToBeDeleted = request.Items.Where(o => o.Id == loadingItem.Identity && o.IsSave == false).SingleOrDefault();

                var item = request.Items.Where(o => o.Id == loadingItem.Identity).Single();

                var diffSewingDOQuantity = itemToBeDeleted == null ? Math.Round(loadingItem.Quantity - item.Quantity, 2) : Math.Round(itemToBeDeleted.Quantity, 2);

                if (sewingDOItemToBeUpdated.ContainsKey(loadingItem.SewingDOItemId))
                {
                    sewingDOItemToBeUpdated[loadingItem.SewingDOItemId] += diffSewingDOQuantity;
                }
                else
                {
                    sewingDOItemToBeUpdated.Add(loadingItem.SewingDOItemId, diffSewingDOQuantity);
                }

                loadingItem.SetPrice(item.Price);
                loadingItem.SetQuantity(item.Quantity);
                loadingItem.SetRemainingQuantity(item.RemainingQuantity);

                loadingItem.Modify();

                if (itemToBeDeleted != null)
                {
                    loadingItem.Remove();
                }

                await _garmentLoadingItemRepository.Update(loadingItem);
            });

            foreach (var sewingDOItem in sewingDOItemToBeUpdated)
            {
                var garmentSewingDOItem = _garmentSewingDOItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingDOItem(s)).Single();
                garmentSewingDOItem.setRemainingQuantity(Math.Round(garmentSewingDOItem.RemainingQuantity + sewingDOItem.Value, 2));
                garmentSewingDOItem.Modify();

                await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
            }

            loading.Modify();
            await _garmentLoadingRepository.Update(loading);

            _storage.Save();

            return(loading);
        }
Ejemplo n.º 3
0
        public async Task <GarmentLoading> Handle(RemoveGarmentLoadingCommand request, CancellationToken cancellationToken)
        {
            var loading = _garmentLoadingRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentLoading(o)).Single();

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

            _garmentLoadingItemRepository.Find(o => o.LoadingId == loading.Identity).ForEach(async loadingItem =>
            {
                if (sewingDOItemToBeUpdated.ContainsKey(loadingItem.SewingDOItemId))
                {
                    sewingDOItemToBeUpdated[loadingItem.SewingDOItemId] += loadingItem.Quantity;
                }
                else
                {
                    sewingDOItemToBeUpdated.Add(loadingItem.SewingDOItemId, loadingItem.Quantity);
                }

                loadingItem.Remove();

                await _garmentLoadingItemRepository.Update(loadingItem);
            });

            foreach (var sewingDOItem in sewingDOItemToBeUpdated)
            {
                var garmentSewingDOItem = _garmentSewingDOItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingDOItem(s)).Single();
                garmentSewingDOItem.setRemainingQuantity(garmentSewingDOItem.RemainingQuantity + sewingDOItem.Value);
                garmentSewingDOItem.Modify();

                await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
            }

            loading.Remove();
            await _garmentLoadingRepository.Update(loading);

            _storage.Save();

            return(loading);
        }
Ejemplo n.º 4
0
        public async Task <GarmentLoading> Handle(PlaceGarmentLoadingCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();

            GarmentLoading garmentLoading = new GarmentLoading(
                Guid.NewGuid(),
                GenerateLoadingNo(request),
                request.SewingDOId,
                request.SewingDONo,
                new UnitDepartmentId(request.UnitFrom.Id),
                request.UnitFrom.Code,
                request.UnitFrom.Name,
                request.RONo,
                request.Article,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.LoadingDate,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name
                );

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

            foreach (var item in request.Items)
            {
                if (item.IsSave)
                {
                    GarmentLoadingItem garmentLoadingItem = new GarmentLoadingItem(
                        Guid.NewGuid(),
                        garmentLoading.Identity,
                        item.SewingDOItemId,
                        new SizeId(item.Size.Id),
                        item.Size.Size,
                        new ProductId(item.Product.Id),
                        item.Product.Code,
                        item.Product.Name,
                        item.DesignColor,
                        item.Quantity,
                        item.RemainingQuantity,
                        item.BasicPrice,
                        new UomId(item.Uom.Id),
                        item.Uom.Unit,
                        item.Color,
                        item.Price
                        );

                    if (sewingDOItemToBeUpdated.ContainsKey(item.SewingDOItemId))
                    {
                        sewingDOItemToBeUpdated[item.SewingDOItemId] += item.Quantity;
                    }
                    else
                    {
                        sewingDOItemToBeUpdated.Add(item.SewingDOItemId, item.Quantity);
                    }

                    await _garmentLoadingItemRepository.Update(garmentLoadingItem);
                }
            }

            foreach (var sewingDOItem in sewingDOItemToBeUpdated)
            {
                var garmentSewingDOItem = _garmentSewingDOItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingDOItem(s)).Single();
                garmentSewingDOItem.setRemainingQuantity(garmentSewingDOItem.RemainingQuantity - sewingDOItem.Value);
                garmentSewingDOItem.Modify();

                await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
            }

            await _garmentLoadingRepository.Update(garmentLoading);

            _storage.Save();

            return(garmentLoading);
        }
        public async Task <GarmentSewingIn> Handle(PlaceGarmentSewingInCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true).ToList();

            GarmentSewingIn garmentSewingIn = new GarmentSewingIn(
                Guid.NewGuid(),
                GenerateSewingInNo(request),
                request.SewingFrom,
                request.LoadingId,
                request.LoadingNo,
                new UnitDepartmentId(request.UnitFrom.Id),
                request.UnitFrom.Code,
                request.UnitFrom.Name,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.RONo,
                request.Article,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                request.SewingInDate.GetValueOrDefault()
                );

            foreach (var item in request.Items)
            {
                GarmentSewingInItem garmentSewingInItem = new GarmentSewingInItem(
                    Guid.NewGuid(),
                    garmentSewingIn.Identity,
                    item.SewingOutItemId,
                    item.SewingOutDetailId,
                    item.LoadingItemId,
                    item.FinishingOutItemId,
                    item.FinishingOutDetailId,
                    new ProductId(item.Product.Id),
                    item.Product.Code,
                    item.Product.Name,
                    item.DesignColor,
                    new SizeId(item.Size.Id),
                    item.Size.Size,
                    item.Quantity,
                    new UomId(item.Uom.Id),
                    item.Uom.Unit,
                    item.Color,
                    item.Quantity,
                    item.BasicPrice,
                    item.Price
                    );

                if (request.SewingFrom == "CUTTING")
                {
                    var garmentLoadingItem = _garmentLoadingItemRepository.Query.Where(o => o.Identity == item.LoadingItemId).Select(s => new GarmentLoadingItem(s)).Single();

                    garmentLoadingItem.SetRemainingQuantity(garmentLoadingItem.RemainingQuantity - item.Quantity);

                    garmentLoadingItem.Modify();
                    await _garmentLoadingItemRepository.Update(garmentLoadingItem);
                }
                else if (request.SewingFrom == "SEWING")
                {
                    var garmentSewingOutItem = _garmentSewingOutItemRepository.Query.Where(s => s.Identity == item.SewingOutItemId).Select(s => new GarmentSewingOutItem(s)).Single();

                    garmentSewingOutItem.SetRemainingQuantity(garmentSewingOutItem.RemainingQuantity - item.Quantity);

                    garmentSewingOutItem.Modify();
                    await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
                }
                else if (request.SewingFrom == "FINISHING")
                {
                    var garmentFinishingOutItem = _garmentFinishingOutItemRepository.Query.Where(s => s.Identity == item.FinishingOutItemId).Select(s => new GarmentFinishingOutItem(s)).Single();

                    garmentFinishingOutItem.SetRemainingQuantity(garmentFinishingOutItem.RemainingQuantity - item.Quantity);

                    garmentFinishingOutItem.Modify();
                    await _garmentFinishingOutItemRepository.Update(garmentFinishingOutItem);
                }

                await _garmentSewingInItemRepository.Update(garmentSewingInItem);
            }

            await _garmentSewingInRepository.Update(garmentSewingIn);

            _storage.Save();

            return(garmentSewingIn);
        }