Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 public ActionResult <Guid> Update(ManufacturerUpdateModel manufacturer)
 {
     return(manufacturerFacade.Update(manufacturer));
 }