public IActionResult Post([FromBody] MyModelViewModel viewModel) { try { if (viewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MyModel item = Mapper.Map <MyModel>(viewModel); _exampleRepository.Add(item); int save = _exampleRepository.Save(); if (save > 0) { return(CreatedAtRoute("GetSingle", new { controller = "MyModel", id = item.Id }, item)); } return(BadRequest()); } catch (Exception exception) { //Do something with the exception return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public UpdateExampleResponse Process(UpdateExampleRequest request) { try { var example = _repository.Get(request.Id); example.UpdateProperty1(request.Property1); if (example.IsValid()) { _repository.Save(example); return(new UpdateExampleResponse(true)); } else { return(new UpdateExampleResponse(false, example.Errors)); } } catch (Exception ex) { var validations = new Validations(); validations.AddError(ErrorCode.Unexpected, "Unable to update example model."); return(new UpdateExampleResponse(false, validations)); } }