Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public void Put(int id, [FromBody] UpdateFarmDto dto)
 {
     _farmService.Update(id, dto);
 }