예제 #1
0
        public IActionResult CreateShelter([FromBody] ShelterDto shelterToAdd)
        {
            if (shelterToAdd == null)
            {
                return(BadRequest(ModelState));
            }

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

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            if (!shelterRepo.CreateShelter(shelter))
            {
                ModelState.AddModelError("", $"Error with {shelter.Name}");
                return(StatusCode(500, ModelState));
            }
            return(CreatedAtRoute("GetShelter", new { version = HttpContext.GetRequestedApiVersion().ToString(), shelterId = shelter.Id }, shelter));
        }
예제 #2
0
 private bool ShelterExists(int id)
 {
     return(_repository.ShelterExists(id));
 }