public ActionResult <PetType> AddPetType([FromBody] PetType petType)
 {
     try
     {
         return(Ok(_petTypeService.AddPetType(petType)));
     }
     catch (InvalidDataException e)
     {
         return(BadRequest("Something went wrong with your request\n" + e.Message));
     }
     catch (DataBaseException e)
     {
         return(StatusCode(500, e.Message));
     }
 }
Пример #2
0
        public ActionResult <PetType> CreatePetType([FromBody] PetType petType)
        {
            try
            {
                PetType petTypeToAdd = PetTypeService.CreatePetType(petType.Name);
                PetType addedPetType = PetTypeService.AddPetType(petTypeToAdd);

                if (addedPetType == null)
                {
                    return(StatusCode(500, "Error saving pet to Database"));
                }

                return(Created("", addedPetType));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
        }