public Guid?Update(ManufacturerUpdateModel manufacturerUpdateModel) { var manufacturerEntityExisting = manufacturerRepository.GetById(manufacturerUpdateModel.Id); manufacturerEntityExisting.Product = productRepository.GetByManufacturerId(manufacturerUpdateModel.Id); UpdateManufacturer(manufacturerUpdateModel, manufacturerEntityExisting); var manufacturerEntityUpdated = mapper.Map <ManufacturerEntity>(manufacturerUpdateModel); return(manufacturerRepository.Update(manufacturerEntityUpdated)); }
private void UpdateManufacturer(ManufacturerUpdateModel manufacturerUpdateModel, ManufacturerEntity manufacturerEntity) { var productToRemove = manufacturerEntity.Product.Where(product => !manufacturerUpdateModel.Product.Any(products => products.Id == product.Id)); foreach (var product in productToRemove) { product.ManufacturerId = Guid.Empty; product.Manufacturer = null; productRepository.Update(product); } var productToAdd = manufacturerUpdateModel.Product.Where( product => !manufacturerEntity.Product.Any(products => products.Id == product.Id)); foreach (var product in productToAdd) { var goodEntity = productRepository.GetById(product.Id); goodEntity.ManufacturerId = manufacturerUpdateModel.Id; productRepository.Update(goodEntity); } }
public ActionResult <Guid> Update(ManufacturerUpdateModel manufacturer) { return(manufacturerFacade.Update(manufacturer)); }