protected DriverResult LatestActiveUsers(ProjectPart part, dynamic shapeHelper, int count) { IUser owner = part.As <CommonPart>().Owner; var contentManager = this.services.ContentManager; var query = contentManager.HqlQuery().ForVersion(VersionOptions.Published); dynamic state = new JObject(); state.Project_Id = part.Record.Id.ToString(CultureInfo.InvariantCulture); query = this.projectionWithDynamicSort.ApplyFilter(query, AttachToProjectFilter.CategoryName, AttachToProjectFilter.IdFilterType, state); var latestActiveUserIds = this.activityStreamService.LatestUsersInActivityStreamFilteredByGivenQuery(query, count).ToList(); if (latestActiveUserIds.Count < count && !latestActiveUserIds.Any(c => c == owner.Id)) { latestActiveUserIds.Add(owner.Id); } var users = contentManager.GetMany <IUser>(latestActiveUserIds, VersionOptions.Published, QueryHints.Empty); List <UserViewModel> model = new List <UserViewModel>(); foreach (var user in users) { var userModel = ProjectHelper.Convert <UserViewModel>(user); model.Add(userModel); } return(ContentShape("Parts_LatestActiveUsers", () => shapeHelper.Parts_LatestActiveUsers( Model: model))); }
public ActionResult Invite(int userId) { if (!this.services.Authorizer.Authorize(Orchard.Users.Permissions.ManageUsers, T("Not authorized to list users")) || !this.services.Authorizer.Authorize(Orchard.CRM.Core.Permissions.AdvancedOperatorPermission, T("Not authorized to list users"))) { return(new HttpUnauthorizedResult()); } var user = this.services.ContentManager.Get <IUser>(userId); if (user == null) { return(new HttpNotFoundResult(T("There is no user with the given Id").Text)); } if (!this.contentOwnershipService.IsCustomer(userId) && !this.contentOwnershipService.IsOperator(userId)) { return(new HttpUnauthorizedResult(T("The given user doesn't have customer permission").Text)); } var projects = this.projectService.GetProjects(null); var temp = this.projectService.GetUsersProjects(new[] { userId }); List <ProjectPart> userProjects = new List <ProjectPart>(); if (temp.ContainsKey(userId)) { userProjects.AddRange(temp[userId]); } projects = projects.Where(c => !userProjects.Any(d => d.Record.Id == c.Id)).ToList(); InviteUserToProjectViewModel model = new InviteUserToProjectViewModel(); model.User = ProjectHelper.Convert <UserViewModel>(user); model.User.UserProjects.AddRange(userProjects.Select(c => new SelectListItem { Value = c.Record.Id.ToString(CultureInfo.InvariantCulture), Text = c.Record.Title })); model.Projects.AddRange(projects.Select(c => new SelectListItem { Value = c.Id.ToString(CultureInfo.InvariantCulture), Text = c.As <ProjectPart>().Record.Title })); return(this.View(model)); }
public ActionResult Display(int userId) { // check user is operator or customer if (!this.contentOwnershipService.IsCurrentUserOperator() && !this.contentOwnershipService.IsCurrentUserCustomer()) { return(HttpNotFound()); } var user = this.services.ContentManager.Get <IUser>(userId); if (user == null) { return(HttpNotFound()); } UserDetailViewModel model = ProjectHelper.Convert <UserDetailViewModel>(user); // retrieving paging parameters var queryString = this.services.WorkContext.HttpContext.Request.QueryString; var pageKey = "page"; var page = 0; int pageSize = 10; // don't try to page if not necessary if (queryString.AllKeys.Contains(pageKey)) { int.TryParse(queryString[pageKey], out page); } var userProjects = this.projectService.GetUsersProjects(new[] { userId }); if (userProjects.ContainsKey(userId)) { model.UserProjects.AddRange(userProjects[userId].Select(c => new SelectListItem { Value = c.Record.Id.ToString(CultureInfo.InvariantCulture), Text = c.Record.Title })); } var count = this.activityStreamService.ActivityStreamOfGivenUserVisibleByCurrentUserCount(userId); var items = this.activityStreamService.ActivityStreamOfGivenUserVisibleByCurrentUser(userId, page > 0 ? page - 1 : 0, pageSize).ToList(); model.ActivityStream = this.activityStreamService.CreateModel(items, count, page, pageSize); return(View(model)); }
public ActionResult Customers(UserIndexOptionsViewModel options) { if (!this.contentOwnershipService.IsCurrentUserOperator()) { return(new HttpUnauthorizedResult()); } var pager = this.helperService.ReterivePagerFromQueryString(); options = options ?? new UserIndexOptionsViewModel(); int count = this.basicDataService.GetCustomersCount(options.Search); var customers = this.basicDataService.GetCustomers(options.Search, pager.Page, pager.PageSize, options.Order, options.OrderByDescending); var pagerShape = Shape.Pager(pager).PagerId("page"); pagerShape.TotalItemCount(count); UserListViewModel model = new UserListViewModel { Pager = pagerShape, Search = options.Search, OrderBy = options.Order, OrderByDescending = options.OrderByDescending }; model.Users.AddRange(customers.Select(c => ProjectHelper.Convert <UserViewModel>(c))); var userProjects = this.projectService.GetUsersProjects(customers.Select(c => c.Id)); foreach (var user in model.Users) { if (userProjects.ContainsKey(user.UserId)) { user.UserProjects.AddRange(userProjects[user.UserId].Select(c => new SelectListItem { Value = c.Record.Id.ToString(CultureInfo.InvariantCulture), Text = c.Record.Title })); } } return(View(model)); }
public ActionResult Operators(UserIndexOptionsViewModel options) { if (!this.contentOwnershipService.IsCurrentUserOperator()) { return(new HttpUnauthorizedResult()); } options = options ?? new UserIndexOptionsViewModel(); var operators = this.basicDataService.GetOperators(); string searchPhrase = string.IsNullOrEmpty(options.Search)? string.Empty: options.Search.ToLower(); if (!String.IsNullOrWhiteSpace(options.Search)) { operators = operators.Where(u => u.UserName.ToLower().Contains(searchPhrase) || u.Email.ToLower().Contains(searchPhrase) || (CRMHelper.GetFullNameOfUser(u) != null && CRMHelper.GetFullNameOfUser(u).ToLower().Contains(searchPhrase))) .ToList(); } switch (options.Order) { case UsersOrderViewModel.Username: operators = operators.OrderBy(u => u.UserName); break; case UsersOrderViewModel.Email: operators = operators.OrderBy(u => u.Email); break; } var pager = this.helperService.ReterivePagerFromQueryString(); var pagerShape = Shape.Pager(pager).PagerId("page"); pagerShape.TotalItemCount(operators.Count()); UserListViewModel model = new UserListViewModel { Pager = pagerShape, Search = searchPhrase, OrderBy = options.Order, OrderByDescending = options.OrderByDescending }; operators = operators.Skip(Math.Min(0, pager.Page - 1) * pager.PageSize).Take(pager.PageSize); model.Users.AddRange(operators.Select(c => ProjectHelper.Convert <UserViewModel>(c))); var userProjects = this.projectService.GetUsersProjects(operators.Select(c => c.Id)); foreach (var user in model.Users) { if (userProjects.ContainsKey(user.UserId)) { user.UserProjects.AddRange(userProjects[user.UserId].Select(c => new SelectListItem { Value = c.Record.Id.ToString(CultureInfo.InvariantCulture), Text = c.Record.Title })); } } return(View(model)); }