Created
November 9, 2012 11:10
-
-
Save hazzik/4045190 to your computer and use it in GitHub Desktop.
FormController.cs
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
protected ActionResult Handle<TForm, TResult>(TForm form, | |
Func<TResult, ActionResult> successResultGetter, | |
Func<ActionResult> failResultGetter) where TForm : IForm | |
{ | |
if (ModelState.IsValid) | |
{ | |
try | |
{ | |
var result = FormHandlerFactory.Create<TForm, TResult>().Handle(form); | |
return successResultGetter(result); | |
} | |
catch (Exception e) | |
{ | |
ModelState.AddModelError("", e.Message); | |
} | |
} | |
TempData[ModelStateKey] = ModelState; | |
TempData[ValueProviderKey] = ValueProvider; | |
return failResultGetter(); | |
} |
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 interface IFormHandler<in TForm, out TResult> where TForm : IForm | |
{ | |
TResult Handle(TForm form); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment