Guest User

Untitled

a guest
Mar 4th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. public ActionResult Register(UserFormModel form)
  2.         {
  3.             if (ModelState.IsValid)
  4.             {
  5.                 var command = new UserRegisterCommand
  6.                 {
  7.                     FirstName = form.FirstName,
  8.                     LastName = form.LastName,
  9.                     Email=form.Email,
  10.                     Password = form.Password,
  11.                     Activated = true,
  12.                     RoleId = (Int32)UserRoles.User
  13.                 };
  14.                 IEnumerable<ValidationResult> errors = commandBus.Validate(command);              
  15.                 ModelState.AddModelErrors(errors);            
  16.                 if (ModelState.IsValid)
  17.                 {
  18.                     var result = commandBus.Submit(command);
  19.                     if (result.Success)
  20.                     {
  21.                         User user = userRepository.Get(u => u.Email == form.Email);
  22.                         formAuthentication.SetAuthCookie(this.HttpContext,
  23.                                                           UserAuthenticationTicketBuilder.CreateAuthenticationTicket(
  24.                                                               user));
  25.                         return RedirectToAction("Index", "Home");
  26.                     }
  27.                 }
  28.             }
  29.             // If fail
  30.             return View(form);
  31.         }
Add Comment
Please, Sign In to add comment