示例#1
0
 public ActionResult <PetType> Post([FromBody] PetType petType)
 {
     if (string.IsNullOrEmpty(petType.Type))
     {
         return(StatusCode(500, "someting went wrong"));
     }
     return(_petTypeService.CreatePetType(petType));
 }
示例#2
0
        public ActionResult <PetType> Post([FromBody] PetType petType)
        {
            if (string.IsNullOrEmpty(petType.Type))
            {
                return(BadRequest("Type is required for creating a petType"));
            }

            return(_petTypeService.CreatePetType(petType));
        }
示例#3
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));
            }
        }
示例#4
0
        public ActionResult <PetType> Post([FromBody] PetType petType)
        {
            if (string.IsNullOrEmpty(petType.Name))
            {
                return(StatusCode(500, "Name is required for Creating PetType"));
            }


            return(_petTypeService.CreatePetType(petType));
        }
示例#5
0
 public ActionResult <PetType> Post([FromBody] PetType petType)
 {
     try
     {
         return(Created("", _petTypeService.CreatePetType(petType)));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
示例#6
0
 public ActionResult <PetType> Post([FromBody] PetType petType)
 {
     try
     {
         return(StatusCode(201, _petTypesService.CreatePetType(petType)));
     }
     catch (ArgumentException e)
     {
         return(StatusCode(500, e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, ExceptionMessageConstants.NonSpecificUIMessage));
     }
 }
        public ActionResult <PetType> Post([FromBody] PetType petType)
        {
            if (string.IsNullOrEmpty(petType.Type))
            {
                return(BadRequest("Enter IndPut"));
            }

            try
            {
                return(Ok(_petTypeService.CreatePetType(petType)));
            }
            catch (Exception)
            {
                return(StatusCode(500, "Smth Went Wrong"));
            }
        }
        [HttpPost]  // NOT essential. Only needed if we change this methods name from "Post", and then it tells the system this is the POST method. Needed if sending parameters
        public ActionResult <PetType> Post([FromBody] PetType petTypeToPost)
        {
            if (string.IsNullOrEmpty(petTypeToPost.Name))
            {
                return(StatusCode(500, "No name of pet type supplied"));
            }
            List <PetType> allPetTypes = _petTypeService.GetAllPetTypes();

            foreach (var petType in allPetTypes)
            {
                if (petType.Name == petTypeToPost.Name)
                {
                    return(StatusCode(500, "This pet type with name " + petType.Name + " already exists with an id of " + petType.PetTypeId));
                }
            }
            PetType petTypeToCreate = _petTypeService.CreatePetType(petTypeToPost);

            return(StatusCode(201, petTypeToCreate));
        }
示例#9
0
        public ActionResult <PetType> Post([FromBody] PetType petType)
        {
            if (petType.PetTypeId <= 1)
            {
                return(StatusCode(500, "PetId cannot be less than One"));
            }
            if (petType.Color == null)
            {
                return(StatusCode(500, "You must select a color"));
            }

            if (petType.Name == null)
            {
                return(StatusCode(500, "You must write a name"));
            }

            else
            {
                return(_petTypeService.CreatePetType(petType));
            }
        }
示例#10
0
 public ActionResult <PetType> Post([FromBody] PetType petType)
 {
     return(_petTypeService.CreatePetType(petType));
 }
 public ActionResult <PetType> Post([FromBody] PetType value)
 {
     try
     {
         return(string.IsNullOrEmpty(value.name) ? BadRequest("Name is required to create a petType") : StatusCode(201, _petTypeService.CreatePetType(value)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(StatusCode(500, e));
     }
 }
示例#12
0
 public async Task <bool> CreatePetType(PetType petType)
 {
     return(await _petTypeService.CreatePetType(petType));
 }