コード例 #1
0
        public ActionResult <PetModel> UpdatePet(int petId, [FromBody] PetModel petModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    foreach (var pair in ModelState)
                    {
                        if (pair.Key == nameof(petModel.Description) && pair.Value.Errors.Count > 0)
                        {
                            return(BadRequest(pair.Value.Errors));
                        }
                    }
                }
                return(_petService.UpdatePet(petId, petModel));
            }

            catch (NotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Something happend: {ex.Message}"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> UpdatePet(PetDTO pet)
        {
            await _petServices.UpdatePet(pet);

            return(NoContent());
        }