public async Task <List <GarmentComodityPrice> > Handle(PlaceGarmentComodityPriceCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();
            List <GarmentComodityPrice> List = new List <GarmentComodityPrice>();

            foreach (var item in request.Items)
            {
                GarmentComodityPrice garmentComodityPrice = new GarmentComodityPrice(
                    Guid.NewGuid(),
                    true,
                    request.Date,
                    new UnitDepartmentId(request.Unit.Id),
                    request.Unit.Code,
                    request.Unit.Name,
                    new GarmentComodityId(item.Comodity.Id),
                    item.Comodity.Code,
                    item.Comodity.Name,
                    item.Price
                    );
                List.Add(garmentComodityPrice);
                await _garmentComodityPriceRepository.Update(garmentComodityPrice);
            }

            _storage.Save();

            return(List);
        }
コード例 #2
0
        public async Task <List <GarmentComodityPrice> > Handle(UpdateGarmentComodityPriceCommand request, CancellationToken cancellationToken)
        {
            List <GarmentComodityPrice> List = new List <GarmentComodityPrice>();

            foreach (var item in request.Items)
            {
                var como = _garmentComodityPriceRepository.Query.Where(o => o.Identity == item.Id).Select(o => new GarmentComodityPrice(o)).Single();

                if (como.Price != item.NewPrice)
                {
                    como.setValid(false);

                    GarmentComodityPrice garmentComodityPrice = new GarmentComodityPrice(
                        Guid.NewGuid(),
                        true,
                        request.Date,
                        new UnitDepartmentId(request.Unit.Id),
                        request.Unit.Code,
                        request.Unit.Name,
                        new GarmentComodityId(item.Comodity.Id),
                        item.Comodity.Code,
                        item.Comodity.Name,
                        item.NewPrice
                        );

                    await _garmentComodityPriceRepository.Update(garmentComodityPrice);
                }

                como.Modify();
                await _garmentComodityPriceRepository.Update(como);

                _storage.Save();
                List.Add(como);
            }
            return(List);
        }