コード例 #1
0
        public ActionResult New()
        {
            Model_For_New_Account user = new Model_For_New_Account();

            user.AllRoles = GetAllRolesForNew();
            return(View(user));
        }
コード例 #2
0
        public ActionResult New(Model_For_New_Account u, string newRole)
        {
            ApplicationUser user = new ApplicationUser();

            u.AllRoles = GetAllRolesForNew();
            try
            {
                ApplicationDbContext context = new ApplicationDbContext();
                var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

                // se adauga utilizatorul administrator
                user.Email    = u.user_to_register.Email;
                user.UserName = u.user_to_register.Email;
                user.AllRoles = GetAllRoles();

                // return JavaScript("window.open('"+ newRole+"')");

                if (u.user_to_register.Password == u.user_to_register.ConfirmPassword)
                {
                    //user.Email = pass;
                    var adminCreated = UserManager.Create(user, u.user_to_register.Password);
                    if (adminCreated.Succeeded)
                    {
                        UserManager.AddToRole(user.Id, newRole);
                    }
                }
                else
                {
                    return(View(u));
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                Response.Write(e.Message);
                return(View(u));
            }
        }