コード例 #1
0
        public ActionResult UserManagement([DefaultValue(1)] int page)
        {
            var allUsers = _userRepository.GetAllUsers().Where(u => u.UserID != 1).ToList();
            var filteredList = allUsers.Skip((page - 1) * _itemsPerPage).Take(_itemsPerPage).ToList();

            filteredList.ForEach(author =>
            {
                author.PostsCount = _postRepository.GetPostsByUserID(author.UserID, 1).Count(p => !p.IsPrivate);
            });

            var usersModel = new AdminAuthorsViewModel
            {
                Authors = filteredList,
                PagingInfo = new PagingInformation
                {
                    CurrentPage = page,
                    ItemsPerPage = _itemsPerPage,
                    TotalItems = allUsers.Count
                },
                AuthorsCount = allUsers.Count,
                OneTimeCode = GetToken(),
                Title = SettingsRepository.BlogName
            };
            return View(usersModel);
        }
コード例 #2
0
        public ActionResult UserManagement([DefaultValue(1)] int page)
        {
            if (!User.IsInRole("SuperAdmin") && !User.IsInRole("Admin"))
            {
                return RedirectToAction("Index", "Home", new { Area = "" });
            }

            var allUsers = _userRepository.GetAllUsers().Where(u => u.UserID != 1).ToList();
            var filteredList = allUsers.Skip((page - 1) * _itemsPerPage).Take(_itemsPerPage).ToList();

            filteredList.ForEach(author =>
            {
                author.PostsCount = _postRepository.GetPostsByUserID(author.UserID, 1).Count(p => !p.IsPrivate);
                var roleForUser = _roleRepository.GetRoleForUser(author.UserID);
                author.RoleId = (short) (roleForUser == -1 ? 2 : roleForUser);
            });

            var usersModel = new AdminAuthorsViewModel
            {
                Authors = filteredList,
                PagingInfo = new PagingInformation
                {
                    CurrentPage = page,
                    ItemsPerPage = _itemsPerPage,
                    TotalItems = allUsers.Count
                },
                AuthorsCount = allUsers.Count,
                OneTimeCode = GetToken(),
                Title = SettingsRepository.BlogName
            };
            return View(usersModel);
        }