Skip to content

Instantly share code, notes, and snippets.

@schotime
Created April 16, 2012 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schotime/2395851 to your computer and use it in GitHub Desktop.
Save schotime/2395851 to your computer and use it in GitHub Desktop.
Delegating Controller
public class HomeController : DelegatingControllers.DelegatingController
{
public ActionResult Edit(UserEditQueryModel model)
{
var vm = Invoker.Execute<UserEditQueryModel, UserEditViewModel>(model);
return View(vm);
}
public ActionResult Edit(UserEditInputModel model)
{
if (!ModelState.IsValid)
{
return Edit(new UserEditQueryModel());
}
Invoker.Execute(model);
//There is an overload which allows data to be returned if you have to conditionally redirect somewhere else.
return RedirectToAction("Edit");
}
}
public class UserEditViewModel
{
public string Id { get; set; }
public string Data { get; set; }
public IList<string> RefData { get; set; }
}
public class UserEditInputModel
{
public string Id { get; set; }
public string Data { get; set; }
}
public class UserEditQueryModel
{
public string Id { get; set; }
}
public class UserEditQueryHandler : IHandler<UserEditQueryModel, UserEditViewModel>
{
public UserEditViewModel Handle(UserEditQueryModel inputModel)
{
return new UserEditViewModel();
}
}
public class UserEditSaveHandler : IHandler<UserEditInputModel>
{
public void Handle(UserEditInputModel command)
{
var user = Session.Find<User>(command.Id) ?? new User();
user.Data = command.Data;
Session.Save(user);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment