Created
February 6, 2013 11:51
-
-
Save eldewall/4722126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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