public ActionResult ManageUsers(int pageNum) { var searchOptions = new List<SelectListItem> { new SelectListItem {Text = "User Name", Value = "UserName"}, new SelectListItem {Text = "Email",Value = "Email"} }; var currUserName = null != HttpContext ? HttpContext.User.Identity.Name : string.Empty; var allUsers = _memberShipProvider.GetAllUsers().Where(m=>!m.UserName.Equals(currUserName,StringComparison.OrdinalIgnoreCase)); var userCount = allUsers.Count(); var manageUsersView = new ManageUsersView { SearchOptionList = new SelectList(searchOptions, "Value", "Text", "UserName"), SearchInput = string.Empty, UsersOnline = _memberShipProvider.GetNumberOfUsersOnline(), RegisteredUsers = userCount }; int usersPerPage = DessertHouseConfigurationSection.Current.Users.PageSize; var users = allUsers.Skip((pageNum-1)*usersPerPage).Take(usersPerPage).ToList(); manageUsersView.UserList = new Pagination<MembershipUserWrapper>(users, pageNum, usersPerPage,userCount); ViewBag.PageTitle = "Account Management"; return View(manageUsersView); }
public ActionResult ManageUsers(string searchInput, string searchType, int pageNum) { var searchOptions = new List<SelectListItem> { new SelectListItem {Text = "User Name", Value = "UserName"}, new SelectListItem {Text = "Email",Value = "Email"} }; var manageUsersView = new ManageUsersView { SearchOptionList = new SelectList(searchOptions, "Value", "Text", searchType ?? "UserName"), SearchInput = searchInput ?? string.Empty, UsersOnline = _memberShipProvider.GetNumberOfUsersOnline(), RegisteredUsers = _memberShipProvider.GetAllUsers().Count() }; int usersPerPage = DessertHouseConfigurationSection.Current.Users.PageSize; List<MembershipUserWrapper> userList; if (searchType == "Email") userList = _memberShipProvider.GetUsersByEmail(searchInput). Where(m=>m.Email.Equals(searchInput,StringComparison.OrdinalIgnoreCase)).ToList(); //had to filter out email again here as the Membership Provider has a bug in it else { var user = _memberShipProvider.GetUserByUserName(searchInput); userList = null == user ? new List<MembershipUserWrapper>() : new List<MembershipUserWrapper> { user }; } if (!userList.Any()) ViewBag.InformationalMessage = "No user found with the specified inputs"; manageUsersView.UserList = new Pagination<MembershipUserWrapper>(userList.Skip((pageNum - 1) * usersPerPage).Take(usersPerPage), pageNum, usersPerPage, userList.Count); ViewBag.PageTitle = "Account Management"; return View(manageUsersView); }