Skip to content

Instantly share code, notes, and snippets.

@hazzik
Created November 9, 2012 11:10
Show Gist options
  • Save hazzik/4045190 to your computer and use it in GitHub Desktop.
Save hazzik/4045190 to your computer and use it in GitHub Desktop.
FormController.cs
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();
}
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