Beispiel #1
0
        public ActionResult DeleteUser(AjaxManageUsersViewModel model)
        {
            List <ApplicationUser> users = new List <ApplicationUser>();

            if (model.UserId != null)  // Only one user to delete
            {
                users.Add(UserManager.FindById(model.UserId));
            }
            else  // Multiple users to delete
            {
                users = model.UserIdsList.ConvertAll(new Converter <string, ApplicationUser>(userId => UserManager.FindById(userId)));
            }

            foreach (var user in users)
            {
                if (user != null)
                {
                    Unregister(user);
                }
            }

            return(Json(new { }, contentType: "application/json"));
        }
Beispiel #2
0
        public ActionResult ChangeUserRole(AjaxManageUsersViewModel model)
        {
            var    user    = UserManager.FindById(model.UserId);
            bool   status  = false;
            String message = null;

            if (user == null)
            {
                message = "Modifications annulée: l'utilisateur n'existe pas";
            }

            // Remove from all roles just in case.
            UserManager.RemoveFromRoles(user.Id, UserManager.GetRoles(user.Id).ToArray());

            if (model.NewRole != null)
            {
                UserManager.AddToRole(user.Id, model.NewRole);
                status  = true;
                message = "Modifications reusie";
            }

            return(Json(new { status = status, message = message }, contentType: "application/json"));
        }