Пример #1
0
        public ActionResult UserList()
        {
            UserListModel mdl = new UserListModel();
            mdl.logedInUserName = WebSecurity.CurrentUserName;
            using (var cxt = new Repository.RepoContext())
            {
                cxt.UserProfiles.ToList().ForEach(f1 => {
                    UserListModel.UserListItem item = new UserListModel.UserListItem()
                    {
                        userId = f1.UserId,
                        userName = f1.UserName,
                        firstName = f1.FirstName,
                        lastName = f1.LastName
                    };
                    item.userRoles = new List<UserListModel.UserListItem.UserRole>();
                    Common.Constants.SystemRoles().ForEach(f2 => {
                        item.userRoles.Add(new UserListModel.UserListItem.UserRole()
                        {
                            roleName = f2,
                            roleDisplayName = f2,
                            isMember = Roles.IsUserInRole(f1.UserName, f2)

                        });
                    });
                    mdl.users.Add(item);

                });
            }

            return View(mdl);
        }
Пример #2
0
 public JsonResult SaveUserRoles(UserListModel.UserListItem userToSave)
 {
     foreach (var role in userToSave.userRoles)
     {
         //If the user is marked as isMember and not currenty a member, add them
         if (!Roles.IsUserInRole(userToSave.userName, role.roleName) && role.isMember)
             Roles.AddUserToRole(userToSave.userName, role.roleName);
         else if (Roles.IsUserInRole(userToSave.userName, role.roleName) && !role.isMember) //If the user is marked as not a Member and is currenty a member, remove them
             Roles.RemoveUserFromRole(userToSave.userName, role.roleName);
     }
     return Json(new { success = true });
 }