Created
April 16, 2012 01:19
-
-
Save schotime/2395851 to your computer and use it in GitHub Desktop.
Delegating Controller
This file contains 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 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