Пример #1
0
        //List<SelectListItem>
        private void FetchUserRoles(CopiosisEntities db, ViewUsersModel model)
        {
            List<UserModel> adminUsers = new List<UserModel>();
            List<int> adminIds = new List<int>();
            List<UserModel> nonAdminUsers = new List<UserModel>();

            var items = db.webpages_Roles.ToList();
            if (items != null)
            {
                foreach (var item in items)
                {
                    if (item.RoleName == "ADMIN")
                    {
                        foreach (var user in item.users)
                        {
                            UserModel temp = new UserModel();
                            temp.firstName = user.firstName;
                            temp.lastName = user.lastName;
                            temp.status = user.status;
                            temp.userId = user.userID;
                            temp.userName = user.username;
                            if (temp.userId != WebSecurity.CurrentUserId)
                            {
                                adminIds.Add(temp.userId);
                                adminUsers.Add(temp);
                            }
                        }
                    }
                    else if (item.RoleName == "USER")
                    {
                        foreach (var user in item.users)
                        {
                            if (!adminIds.Contains(user.userID))
                            {
                                UserModel temp = new UserModel();
                                temp.firstName = user.firstName;
                                temp.lastName = user.lastName;
                                temp.status = user.status;
                                temp.userId = user.userID;
                                temp.userName = user.username;
                                nonAdminUsers.Add(temp);
                            }
                        }
                    }
                } // end Foreach
            } // if (items != null)

            model.adminUsers = adminUsers;
            model.nonadminUsers = nonAdminUsers;
        }
Пример #2
0
        public ActionResult ViewUsers()
        {
            ViewUsersModel model = new ViewUsersModel();

            using (var db = new CopiosisEntities())
            {
                FetchUserRoles(db, model);
            }

            return View(model);
        }