public async Task <GarmentPreparing> Handle(RemoveGarmentPreparingCommand request, CancellationToken cancellationToken)
        {
            var garmentPreparing = _garmentPreparingRepository.Find(o => o.Identity == request.Id).FirstOrDefault();

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

            var garmentPreparingItems = _garmentPreparingItemRepository.Find(x => x.GarmentPreparingId == request.Id);

            foreach (var item in garmentPreparingItems)
            {
                item.Remove();
                await _garmentPreparingItemRepository.Update(item);
            }

            garmentPreparing.Remove();

            await _garmentPreparingRepository.Update(garmentPreparing);

            _storage.Save();

            return(garmentPreparing);
        }
        public async Task <GarmentPreparing> Handle(PlaceGarmentPreparingCommand request, CancellationToken cancellationToken)
        {
            //var garmentPreparing  = _garmentPreparingRepository.Find(o =>
            //                        o.UENId == request.UENId &&
            //                        o.UENNo == request.UENNo &&
            //                        o.UnitId == request.Unit.Id &&
            //                        o.UnitCode == request.Unit.Code &&
            //                        o.ProcessDate == request.ProcessDate &&
            //                        o.RONo == request.RONo &&
            //                        o.Article == request.Article &&
            //                        o.IsCuttingIn == request.IsCuttingIn).FirstOrDefault();
            //List<GarmentPreparingItem> garmentPreparingItem = new List<GarmentPreparingItem>();
            //if (garmentPreparing == null)
            //{
            var garmentPreparing = new GarmentPreparing(Guid.NewGuid(), request.UENId, request.UENNo, new UnitDepartmentId(request.Unit.Id), request.Unit.Code, request.Unit.Name, request.ProcessDate, request.RONo,
                                                        request.Article, request.IsCuttingIn, new Domain.Shared.ValueObjects.BuyerId(request.Buyer.Id), request.Buyer.Code, request.Buyer.Name);

            request.Items.Select(x => new GarmentPreparingItem(Guid.NewGuid(), x.UENItemId, new ProductId(x.Product.Id), x.Product.Code, x.Product.Name, x.DesignColor, x.Quantity, new UomId(x.Uom.Id), x.Uom.Unit, x.FabricType, x.RemainingQuantity, x.BasicPrice, garmentPreparing.Identity, x.ROSource)).ToList()
            .ForEach(async x => await _garmentPreparingItemRepository.Update(x));
            //}

            garmentPreparing.SetModified();

            await _garmentPreparingRepository.Update(garmentPreparing);

            _storage.Save();

            return(garmentPreparing);
        }
Exemple #3
0
        public async Task <GarmentPreparing> Handle(UpdateGarmentPreparingCommand request, CancellationToken cancellaitonToken)
        {
            var garmentPreparing = _garmentPreparingRepository.Find(o => o.Identity == request.Id).FirstOrDefault();

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

            garmentPreparing.setUENId(request.UENId);
            garmentPreparing.setUENNo(request.UENNo);
            garmentPreparing.SetUnitId(new UnitDepartmentId(request.Unit.Id));
            garmentPreparing.setUnitCode(request.Unit.Code);
            garmentPreparing.setUnitName(request.Unit.Name);
            garmentPreparing.setProcessDate(request.ProcessDate);
            garmentPreparing.setRONo(request.RONo);
            garmentPreparing.setArticle(request.Article);
            garmentPreparing.setIsCuttingIN(request.IsCuttingIn);

            var dbGarmentPreparing = _garmentPreparingItemRepository.Find(y => y.GarmentPreparingId == garmentPreparing.Identity);
            var updatedItems       = request.Items.Where(x => dbGarmentPreparing.Any(y => y.GarmentPreparingId == garmentPreparing.Identity));
            var addedItems         = request.Items.Where(x => !dbGarmentPreparing.Any(y => y.GarmentPreparingId == garmentPreparing.Identity));
            var deletedItems       = dbGarmentPreparing.Where(x => !request.Items.Any(y => y.GarmentPreparingId == garmentPreparing.Identity));

            foreach (var item in updatedItems)
            {
                var dbItem = dbGarmentPreparing.Find(x => x.Identity == item.Identity);
                dbItem.setBasicPrice(item.BasicPrice);
                dbItem.setDesignColor(item.DesignColor);
                dbItem.setFabricType(item.FabricType);
                dbItem.setProduct(new ProductId(item.Product.Id));
                dbItem.setProductCode(item.Product.Code);
                dbItem.setProductName(item.Product.Name);
                dbItem.setQuantity(item.Quantity);
                dbItem.setRemainingQuantity(item.RemainingQuantity);
                dbItem.setUenItemId(item.UENItemId);
                dbItem.setUomId(new UomId(item.Uom.Id));
                dbItem.setUomUnit(item.Uom.Unit);
                await _garmentPreparingItemRepository.Update(dbItem);
            }

            addedItems.Select(x => new GarmentPreparingItem(Guid.NewGuid(), x.UENItemId, new ProductId(x.Product.Id), x.Product.Code, x.Product.Name, x.DesignColor, x.Quantity, new UomId(x.Uom.Id), x.Uom.Unit, x.FabricType, x.RemainingQuantity, x.BasicPrice, garmentPreparing.Identity, x.ROSource)).ToList()
            .ForEach(async x => await _garmentPreparingItemRepository.Update(x));

            foreach (var item in deletedItems)
            {
                item.SetDeleted();
                await _garmentPreparingItemRepository.Update(item);
            }


            garmentPreparing.SetModified();

            await _garmentPreparingRepository.Update(garmentPreparing);

            _storage.Save();

            return(garmentPreparing);
        }
Exemple #4
0
        public async Task <int> Handle(UpdateDatesGarmentPreparingCommand request, CancellationToken cancellationToken)
        {
            List <Guid> guids = new List <Guid>();

            foreach (var id in request.Identities)
            {
                guids.Add(Guid.Parse(id));
            }
            var Preparings = _garmentPreparingRepository.Query.Where(a => guids.Contains(a.Identity)).Select(a => new GarmentPreparing(a)).ToList();

            foreach (var model in Preparings)
            {
                model.setProcessDate(request.Date);
                model.SetModified();
                await _garmentPreparingRepository.Update(model);
            }
            _storage.Save();

            return(guids.Count());
        }