public void should_success_instantiate() { Guid id = Guid.NewGuid(); GarmentAvalComponentItem componentItem = new GarmentAvalComponentItem(new GarmentAvalComponentItemReadModel(id)); Assert.NotNull(componentItem); }
public GarmentAvalComponentItemDto(GarmentAvalComponentItem garmentAvalComponentItem) { Id = garmentAvalComponentItem.Identity; AvalComponentId = garmentAvalComponentItem.AvalComponentId; CuttingInDetailId = garmentAvalComponentItem.CuttingInDetailId; SewingOutItemId = garmentAvalComponentItem.SewingOutItemId; SewingOutDetailId = garmentAvalComponentItem.SewingOutDetailId; Product = new Product(garmentAvalComponentItem.ProductId.Value, garmentAvalComponentItem.ProductCode, garmentAvalComponentItem.ProductName); DesignColor = garmentAvalComponentItem.DesignColor; Color = garmentAvalComponentItem.Color; Quantity = garmentAvalComponentItem.Quantity; RemainingQuantity = garmentAvalComponentItem.RemainingQuantity; Size = garmentAvalComponentItem.SizeId.Value > 0 ? new SizeValueObject(garmentAvalComponentItem.SizeId.Value, garmentAvalComponentItem.SizeName) : null; Price = garmentAvalComponentItem.Price; }
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); }