public ViewResult Users(int? page, int? pageSize, string filter) { AdminUsersModel m = new AdminUsersModel(); int pageIdx = (page ?? 1) - 1; m.Filter = filter; m.AdminsCount = AppService.Admins.Count(); m.AuthorsCount = AppService.Workspaces.SelectMany(a => a.Authors).Count() + AppService.Workspaces.SelectMany(c => c.Collections).SelectMany(a => a.Authors).Count(); m.ContribsCount = AppService.Workspaces.SelectMany(a => a.Contributors).Count() + AppService.Workspaces.SelectMany(c => c.Collections).SelectMany(a => a.Contributors).Count(); //get total TODO: fix inefficient when filter int total; m.Users = UserRepository.GetUsers(pageIdx, pageSize ?? DEFAULT_PAGE_SIZE, out total) .ToPagedList(pageIdx, pageSize ?? DEFAULT_PAGE_SIZE, total); m.AllCount = total; // if filter, then filter if (filter == "admins") { var users = AppService.Admins.Select(a => UserRepository.GetUser(a)); m.Users = users.ToPagedList(pageIdx, pageSize ?? DEFAULT_PAGE_SIZE, users.Count()); } else if (filter == "authors") { var users = AppService.Workspaces.SelectMany(a => a.Authors).Concat( AppService.Workspaces.SelectMany(c => c.Collections).SelectMany(a => a.Authors)).Select(a => UserRepository.GetUser(a)); m.Users = users.ToPagedList(pageIdx, pageSize ?? DEFAULT_PAGE_SIZE, users.Count()); } else if (filter == "contribs") { var users = AppService.Workspaces.SelectMany(a => a.Contributors).Concat( AppService.Workspaces.SelectMany(c => c.Collections).SelectMany(a => a.Contributors)).Select(a => UserRepository.GetUser(a)); m.Users = users.ToPagedList(pageIdx, pageSize ?? DEFAULT_PAGE_SIZE, users.Count()); } else if (filter == "users") { //TODO: find a way to efficiently filter to only user } return View("AdminUsers", "Admin", m); }
public PartialViewResult People(string workspace, string collection) { var m = new AdminUsersModel(); m.Title = "Authors and Contributors"; m.AddLinks.Add("Add Author", Url.Action("SelectAuthor", "Admin", new { workspace = Scope.Workspace, collection = Scope.Collection })); m.AddLinks.Add("Add Contributor", Url.Action("SelectContributor", "Admin", new { workspace = Scope.Workspace, collection = Scope.Collection })); m.CanRemove = true; m.GetRemoveHref = (u) => Url.Action("RemovePerson", "Admin", new { workspace = Scope.Workspace, collection = Scope.Collection, userId = u.Ids.First() }); m.CanEdit = true; m.Service = AppService; int total; //TODO: paging var w = AppService.GetWorkspace(Scope.Workspace); if (Scope.IsCollection) { m.Users = UserRepository.GetUsers(0, int.MaxValue, out total) .Where(u => u.Ids.Intersect(w.GetCollection(Scope.Collection).Authors.Union(w.GetCollection(Scope.Collection).Contributors)).Count() == 1).ToPagedList(0, int.MaxValue, total); } else { m.Users = UserRepository.GetUsers(0, int.MaxValue, out total) .Where(u => u.Ids.Intersect(w.Authors.Union(w.Contributors)).Count() == 1).ToPagedList(0, int.MaxValue, total); } return PartialView("AdminUsersWidget", m); }
public PartialViewResult Administrators() { var m = new AdminUsersModel(); m.Title = "Administrators"; m.AddLinks.Add("Add", Url.Action("SelectAdministrator")); m.CanRemove = true; m.GetRemoveHref = (u) => Url.Action("RemoveAdministrator", "Admin", new { userId = u.Ids.First() }); m.CanEdit = true; int total; //TODO: paging m.Users = UserRepository.GetUsers(0, int.MaxValue, out total) .Where(u => u.Ids.Intersect(AppService.Admins).Count() == 1).ToPagedList(0, int.MaxValue, total); return PartialView("AdminUsersWidget", m); }