Skip to content

Instantly share code, notes, and snippets.

@cbcwebdev
Created April 19, 2012 18:23
Show Gist options
  • Save cbcwebdev/2422815 to your computer and use it in GitHub Desktop.
Save cbcwebdev/2422815 to your computer and use it in GitHub Desktop.
public class UsersController : ApplicationController // base class exposes profiler, etc.
{
[Authorize(Roles = Roles.Administrator)]
[Authorize(Roles = Roles.Owner)]
public ActionResult Register()
{
return View();
}
[HttpPost]
[Authorize(Roles = Roles.Administrator)]
[IHandleRequestsFor(Roles.Administrator)]
public ActionResult Register(UserRegistrationViewModel viewModel)
{
if(ModelState.IsValid)
{
var command = Mapper.Map<RegisterUserCommand>(viewModel);
Bus.Send(command);
return ViewForRole("Register_Complete"); // returns Register_Complete_Administrator
}
return View(viewModel);
}
[HttpPost]
[Authorize(Roles = Roles.Owner)]
[IHandleRequestsFor(Roles.Owner)]
public ActionResult Register(UserRegistrationViewModel viewModel)
{
if(ModelState.IsValid)
{
viewModel.Account = // get account identifier for current user
viewModel.Role = Roles.Employee; // well defined business scenario
var command = Mapper.Map<RegisterUserCommand>(viewModel);
Bus.Send(command);
return ViewForRole("Register_Complete"); // returns Register_Complete_Owner
}
return View(viewModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment