public bool LookupCommand(int id, out CommandReadModel model) { var returnValue = _dataAccessLayer.LookupCommand(id, out var databaseModel); if (!returnValue) { model = null; return(false); } model = _mapper.Map <CommandReadModel>(databaseModel); return(true); }
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()); }