public ActionResult PatchCommand(int id, JsonPatchDocument <CommandUpdateModel> patchDocument) { // Can we find the command? if (!_dataAccessLayer.LookupCommand(id, out var dataCommand)) { return(NotFound()); } // Use the patchDocument and apply changes var commandToPatch = _mapper.Map <CommandUpdateModel>(dataCommand); patchDocument.ApplyTo(commandToPatch, ModelState); if (!TryValidateModel(commandToPatch)) { return(ValidationProblem(ModelState)); } // Now that the document is applied, store down to the data layer _mapper.Map(commandToPatch, dataCommand); _dataAccessLayer.Update(dataCommand); _dataAccessLayer.Save(); return(NoContent()); }
public bool Update(int id, CommandUpdateModel commandUpdateModel) { if (!_dataAccessLayer.LookupCommand(id, out var foundCommand)) { return(false); } _mapper.Map(commandUpdateModel, foundCommand); _dataAccessLayer.Update(foundCommand); _dataAccessLayer.Save(); return(true); }