Created
June 19, 2012 20:30
-
-
Save koistya/2956368 to your computer and use it in GitHub Desktop.
Membership service usage sample inside ASP.NET MVC 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 AccountController : Controller | |
{ | |
private readonly IMembershipService membershipService; | |
// service initialization is handled by IoC container | |
public AccountController(IMembershipService membershipService) | |
{ | |
this.membershipService = membershipService; | |
} | |
// .. some other stuff .. | |
[HttpPost] | |
public ActionResult Register(RegisterModel model) | |
{ | |
if (this.ModelSteate.IsValid) | |
{ | |
// then passes it to the service method and checks for errors | |
// which returns ServiceResponse<User> with the status of operation and registered user entity | |
var response = this.membershipService.CreateUser(model); | |
if (response.Success) | |
{ | |
FormsAuthentication.SetAuthCookie(response.Value.UserName, createPersistentCookie: false); | |
return RedirectToAction("Index", "Home"); | |
} | |
response.Errors.CopyTo(this.ModelState); | |
} | |
return View(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment