Skip to content

Instantly share code, notes, and snippets.

@eldewall
Created February 6, 2013 11:51
Show Gist options
  • Save eldewall/4722126 to your computer and use it in GitHub Desktop.
Save eldewall/4722126 to your computer and use it in GitHub Desktop.
public class SuggestionController<T> : ApiController, ISuggestionController<T> where T : ISuggestion {
public ISuggestionSubmitter<T> Submitter { get; set; }
public SuggestionController(ISuggestionSubmitter<T> submitter) {
Submitter = submitter;
}
[HttpPost]
public JsonResult Create(T suggestion) {
if (!ModelState.IsValid) {
Response.StatusCode = 422;
return Json(ApiResult(ModelErrors()), JsonRequestBehavior.AllowGet);
}
T result = Submitter.Submit(suggestion, CurrentIdentity);
return Json(result);
}
}
public class ModelSuggestionController<T> : SuggestionController<T> where T : ModelSuggestion {
public ModelSuggestionController()
: base(new ModelSuggestionSubmitter<T>()) {
}
}
// Final Impl
public class CarModelSuggestionController : ModelSuggestionController<CarModelSuggestion> {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment