Ejemplo n.º 1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                    UsersInRole ur = new UsersInRole();
                    UserProfile user = db.UserProfile.Where(x => x.UserName == model.UserName).ToList<UserProfile>()[0];

                    ur.UserId = user.UserId;
                    ur.RoleId = model.SelectedRoleId;

                    db.UsersInRoles.Add(ur);
                    db.SaveChanges();
                    //WebSecurity.Login(model.UserName, model.Password);
                    //return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            List<Role> roles = db.Role.ToList();
            model.Roles = roles;
            return View(model);
        }
Ejemplo n.º 2
0
 public ActionResult Register()
 {
     List<Role> roles = db.Role.ToList();
     RegisterModel VM = new RegisterModel();
     VM.Roles = roles;
     return View(VM);
 }