Exemple #1
0
        public IActionResult Put(int id, [FromBody] AnimalModel updatedAnimal)
        {
            var animal = _animalService.Update(updatedAnimal.ToDomainModel());

            if (animal == null)
            {
                return(NotFound());
            }
            return(Ok(animal.ToApiModel()));
        }
Exemple #2
0
 public IActionResult Post([FromBody] AnimalModel newAnimal)
 {
     try
     {
         _animalService.Add(newAnimal.ToDomainModel());
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("AddAnimal", ex.GetBaseException().Message);
         return(BadRequest(ModelState));
     }
     return(CreatedAtAction("Get", new { Id = newAnimal.Id }, newAnimal));
 }