public void Update(int id, UpdateFarmDto dto) { var farm = _farmRepository.FindById(id); if (farm == null) { throw new Exception("Farm was not found"); } if (dto.Name != null) { farm.Name = dto.Name; } if (dto.AddressId != farm.Address.Id) { var address = _addressRepository.FindById(dto.AddressId); if (address != null) { farm.Address = address; } } if (dto.ImageId != farm.Image.Id) { var image = _appImageRepository.FindById(dto.ImageId); if (image != null) { farm.Image = image; } } _farmRepository.Update(farm); }