Esempio n. 1
0
        public ActionResult ManageRoles(List <string> userIds, string roleName)
        {
            //Use our RoleHelper to actually assign the role to the person or persons selected
            //This action is intended to operate on the selected Users.
            //If no Users were selected then there is nothing to do
            if (userIds != null)
            {
                //This loop removes all the selected Users from the Role they occupy
                //If they don't currently occupy a Role then I juess we are wasting time
                //trying to remove them from no role
                foreach (var userId in userIds)
                {
                    //First I need to determine what Role if any the user is in
                    var userRole = roleHelper.ListUserRoles(userId).FirstOrDefault();

                    if (!string.IsNullOrEmpty(userRole))
                    {
                        //Second I have to remove each of the selected users from their current Role

                        roleHelper.RemoveUserFromRole(userId, userRole);
                    }

                    //Then I will add each selected user to the selected Role


                    if (!string.IsNullOrEmpty(roleName))
                    {
                        roleHelper.AddUserToRole(userId, roleName);
                    }
                }
            }

            return(RedirectToAction("ManageRoles"));
        }
        public async Task <ActionResult> TransferPower(string memberId)
        {
            var userId = User.Identity.GetUserId();

            //Remove our role as Head of Household  Head
            //Add the role of Member to former Head
            rolesHelper.RemoveUserFromRole(userId, "Head");
            rolesHelper.AddUserToRole(userId, "Member");

            //Drop role from Member
            //Add role of Head to former Member
            rolesHelper.RemoveUserFromRole(memberId, "Member");
            rolesHelper.AddUserToRole(memberId, "Head");

            await HttpContext.RefreshAuthentication(db.Users.Find(userId));

            //Reauthorize current user
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        public ActionResult ManageUserRole(string id, string roleName)
        {
            foreach (var role in roleHelper.ListUserRoles(id))
            {
                roleHelper.RemoveUserFromRole(id, role);
            }

            if (!string.IsNullOrEmpty(roleName))
            {
                roleHelper.AddUserToRole(id, roleName);
            }

            TempData["Message"] = "The user's role has been updated.";
            return(RedirectToAction("Index"));
        }
        public ActionResult ManageRoles(List <string> userIds, string roleName)
        {
            if (userIds == null)
            {
                return(RedirectToAction("ManageRoles"));
            }

            foreach (var userId in userIds)
            {
                foreach (var role in roleHelper.ListUserRoles(userId).ToList())
                {
                    roleHelper.RemoveUserFromRole(userId, role);
                }

                if (!string.IsNullOrEmpty(roleName))
                {
                    roleHelper.AddUserToRole(userId, roleName);
                }
            }
            return(RedirectToAction("ManageRoles"));
        }
        public ActionResult ManageRoles(List <string> userIds, string roleName)
        {
            //This action is intended to operate on the selected Users.
            //If no Users were selected then there is nothing to do
            if (userIds != null)
            {
                foreach (var userId in userIds)
                {
                    //var currentRole = roleHelper.ListUserRoles(userId).FirstOrDefault();
                    //roleHelper.RemoveUserFromRole(userId, currentRole);

                    roleHelper.RemoveUserFromRole(userId, roleHelper.ListUserRoles(userId).FirstOrDefault());

                    if (!string.IsNullOrEmpty(roleName))
                    {
                        roleHelper.AddUserToRole(userId, roleName);
                    }
                }
            }

            return(RedirectToAction("ManageRoles"));
        }
Esempio n. 6
0
        public ActionResult ManageRoles(List <string> userIds, string roleName)
        {
            if (userIds == null || roleName == null)
            {
                return(RedirectToAction("ManageRoles"));
            }

            if (userIds != null)
            {
                foreach (var userId in userIds)
                {
                    var userRole = rolesHelper.ListUserRoles(userId).FirstOrDefault();

                    if (userRole != null)
                    {
                        var currentRole = rolesHelper.ListUserRoles(userId).FirstOrDefault();
                        rolesHelper.RemoveUserFromRole(userId, currentRole);
                    }
                    rolesHelper.AddUserToRole(userId, roleName);
                }
            }
            return(RedirectToAction("ManageRoles"));
        }