示例#1
0
        public IActionResult UpdateShelter(int shelterId, [FromBody] ShelterDto shelterToUpdate)
        {
            if (shelterToUpdate == null || shelterId != shelterToUpdate.Id)
            {
                return(BadRequest(ModelState));
            }

            if (shelterRepo.ShelterExists(shelterToUpdate.Name))
            {
                ModelState.AddModelError("", "Shelter already exist");
                return(StatusCode(404, ModelState));
            }

            var shelter = mapper.Map <Shelter>(shelterToUpdate);

            if (!shelterRepo.UpdateShelter(shelter))
            {
                ModelState.AddModelError("", $"Error with {shelter.Name}");
                return(StatusCode(500, ModelState));
            }
            return(NoContent());
        }