public ActionResult <bool> UpdateToy(int id, [FromBody] ToyModel toy) { try { if (!ModelState.IsValid) { foreach (var state in ModelState) { if (state.Key == nameof(toy.Name) && state.Value.Errors.Count > 0) { return(BadRequest(state.Value.Errors)); } } } return(Ok(service.UpdateToy(id, toy))); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <ActionResult> UpdateToy([FromBody] CreateToyViewModel model, int id) { bool isUpdated = await _toyService.UpdateToy(model, id); if (!isUpdated) { return(StatusCode(500)); } else { return(StatusCode(200)); } }