/// <summary> /// Searches the presence of the given text in communities and contents tables (Name, description and tags fields). /// </summary> /// <param name="searchText">Text to be searched</param> /// <param name="userId">Id of the user who is accessing</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>Communities/Contents which are having the search text</returns> public async Task<IEnumerable<EntityViewModel>> SimpleSearch(string searchText, long userId, PageDetails pageDetails, SearchQueryDetails searchQueryDetails) { // Make sure pageDetails is not null this.CheckNotNull(() => new { pageDetails }); IList<EntityViewModel> searchResults = new List<EntityViewModel>(); // User Id to be used while searching. This will be used to see whether user is having permission or not. long? searchUserId = userId; if (_userRepository.GetUserRole(userId, null) == UserRole.SiteAdmin) { // Set user id as 0 for Site Administrators, so that role check will be ignored for private communities searchUserId = null; } // Gets the total communities/contents satisfying the search condition pageDetails.TotalCount = _searchViewRepository.SearchCount(searchText, searchUserId, searchQueryDetails); // Set the total pages for the search term pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1); // Get the skip count and take count for the given page var skipCount = (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage; var takeCount = pageDetails.ItemsPerPage; var results = await _searchViewRepository.SearchAsync(searchText, searchUserId, skipCount, takeCount, searchQueryDetails); foreach (var entity in results) { EntityViewModel entityViewModel; if (entity.Entity == EntityType.Content.ToString()) { // In case of Content, need to create ContentViewModel instance which is expected by SearchResultView. entityViewModel = new ContentViewModel(); // This is needed to avoid the FxCop warning. var contentViewModel = entityViewModel as ContentViewModel; // Setting the properties which are specific to Contents. contentViewModel.IsLink = entity.ContentType == (int)ContentTypes.Link; contentViewModel.ContentUrl = entity.ContentType == (int)ContentTypes.Link ? entity.ContentUrl : string.Empty; contentViewModel.ContentAzureID = entity.ContentType == (int)ContentTypes.Link ? Guid.Empty : entity.ContentAzureID; } else { entityViewModel = new EntityViewModel(); } Mapper.Map(entity, entityViewModel); searchResults.Add(entityViewModel); } // TODO: Need to send the results based on relevance with following order: Title, Description, Tags and Parent. return searchResults; }
/// <summary> /// Initializes a new instance of the PermissionViewModel class. /// </summary> public PermissionViewModel( Permission currentUserPermission, IList<PermissionDetailsViewModel> permissionItemList, PageDetails paginationDetails, PermissionsTab selectedPermissionsTab) { this.CurrentUserPermission = currentUserPermission; this.PermissionItemList = permissionItemList; this.PaginationDetails = paginationDetails; this.SelectedPermissionsTab = selectedPermissionsTab; }
/// <summary> /// Gets all the comments for the specified Content. /// </summary> /// <param name="filter">Filter which comments to be fetched</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>List of all comments of the Content</returns> public async Task<IEnumerable<CommentDetails>> GetContentComments(CommentFilter filter, PageDetails pageDetails) { this.CheckNotNull(() => new { filter, pageDetails }); Func<ContentComments, object> orderBy = (contentComments) => contentComments.CommentDatetime; Expression<Func<ContentComments, bool>> condition = (contentComments) => contentComments.ContentID == filter.EntityId && contentComments.IsDeleted == false; IEnumerable<ContentComments> comments = _contentCommentsRepository .GetItems(condition, orderBy, filter.OrderType == OrderType.NewestFirst, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); var commentDetails = new List<CommentDetails>(); if (comments != null) { foreach (var item in comments) { var comment = new CommentDetails(); Mapper.Map(item, comment); commentDetails.Add(comment); } } return commentDetails; }
public async Task<JsonResult> GetBrowseContent(HighlightType highlightType, EntityType entityType, int page, int pageSize, CategoryType categoryType, ContentTypes contentType, long? entityId) { var pageDetails = new PageDetails(page); pageDetails.ItemsPerPage = pageSize; var entityHighlightFilter = new EntityHighlightFilter(highlightType, categoryType, entityId, contentType); var highlightEntities = await GetHighlightEntities(entityType, entityHighlightFilter, pageDetails); // It creates the prefix for id of links SetSiteAnalyticsPrefix(highlightType); var result = new JsonResult { Data = new { entities = highlightEntities, pageInfo = pageDetails }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return result; }
private IEnumerable<ContentDetails> GetFeaturedContentDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { Func<FeaturedContentsView, object> orderBy = c => c.SortOrder; var condition = GetFeaturedContentCondition(entityHighlightFilter); // Gets the total items satisfying the var totalItemsForCondition = _featuredContentsViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); // TODO: Passing the condition in a variable doesn't add the WHERE clause in SQL server. Need to work on this later. IEnumerable<FeaturedContentsView> contents = null; // Only for Popular/Top Rated, there is multiple order by which needs to added here. contents = _featuredContentsViewRepository.GetItems(condition, orderBy, false, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var content in contents) { var contentDetail = new ContentDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
/// <summary> /// Gets the invite requests which are already sent for the given community and which are not yet used. /// </summary> /// <param name="userId">User who is reading the invite requests</param> /// <param name="communityId">Community for which invite requests are fetched</param> /// <param name="pageDetails">Page for which invite requests are fetched</param> /// <returns>List of open invite requests for the community</returns> public async Task<IEnumerable<InviteRequestItem>> GetInviteRequests(long userId, long communityId, PageDetails pageDetails) { this.CheckNotNull(() => new { pageDetails }); IList<InviteRequestItem> inviteRequestItemList = new List<InviteRequestItem>(); var userRole = _userRepository.GetUserRole(userId, communityId); if (userRole >= UserRole.Moderator) { // Condition to get all the pending requests irrespective of community. Expression<Func<InviteRequestsView, bool>> condition = (InviteRequestsView invite) => invite.Used == false && invite.CommunityID == communityId; Func<InviteRequestsView, object> orderBy = (InviteRequestsView invite) => invite.InvitedDate; // Gets the total items satisfying the condition pageDetails.TotalCount = _inviteRequestsViewRepository.GetItemsCount(condition); pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1); foreach (var item in _inviteRequestsViewRepository.GetItems(condition, orderBy, true, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage)) { var inviteRequestItem = new InviteRequestItem(); Mapper.Map(item, inviteRequestItem); inviteRequestItemList.Add(inviteRequestItem); } } return inviteRequestItemList; }
/// <summary> /// Gets the user requests for the given community and for the given page. User should have moderator /// or owner/site admin permission on the community to get user request. /// </summary> /// <param name="userId">User who is reading the requests</param> /// <param name="communityId">Community for which requests are fetched</param> /// <param name="pageDetails">Page for which requests are fetched</param> /// <returns>List of user role requests</returns> public async Task<PermissionDetails> GetUserPemissionRequests(long userId, long? communityId, PageDetails pageDetails) { this.CheckNotNull(() => new { pageDetails }); // Condition to get all the pending requests irrespective of community. Expression<Func<PermissionRequest, bool>> condition = (PermissionRequest pr) => pr.Approved == null; Func<PermissionRequest, object> orderBy = (PermissionRequest c) => c.RoleID; if (communityId.HasValue) { // If community is specified, get all the pending requests of the specified community. condition = (PermissionRequest pr) => pr.Approved == null && pr.CommunityID == communityId.Value; } else { // If no community id is specified, get all the community ids to which user is given role of moderator or // higher and get their pending requests. var userCommunityIds = _userRepository.GetUserCommunitiesForRole(userId, UserRole.Moderator, false); condition = (PermissionRequest pr) => pr.Approved == null && userCommunityIds.Contains(pr.CommunityID); } // Gets the total items satisfying the condition pageDetails.TotalCount = _permissionRequestRepository.GetItemsCount(condition); pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1); var permissionDetails = new PermissionDetails(); foreach (var item in _permissionRequestRepository.GetItems(condition, orderBy, true, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage)) { var userRole = _userRepository.GetUserRole(userId, item.CommunityID); // 1. User has to be at least Moderator to know the permission request details of the community. // 2. In case of profile page, user might be moderator for few communities and not for others. So, need to send only the requests // of community to which user is moderator or higher. if (userRole >= UserRole.Moderator) { var permissionItem = new PermissionItem(); Mapper.Map(item, permissionItem); permissionItem.CurrentUserRole = userRole; permissionDetails.PermissionItemList.Add(permissionItem); permissionDetails.CurrentUserPermission = userRole.GetPermission(); } else if (communityId.HasValue) { // If user is not having contributor or higher role, he will get item not found or don't have permission exception page. // This message to be shown only in case of permissions page not for profile page. permissionDetails = null; } } return permissionDetails; }
/// <summary> /// Gets the user permissions for the given community and for the given page. User should have at least /// contributor permission on the community to get user permissions. /// </summary> /// <param name="userId">User who is reading the permissions</param> /// <param name="communityId">Community for which permissions are fetched</param> /// <param name="pageDetails">Page for which permissions are fetched</param> /// <returns>List of permissions/user roles</returns> public async Task<PermissionDetails> GetUserPemissions(long userId, long communityId, PageDetails pageDetails) { this.CheckNotNull(() => new { pageDetails }); Expression<Func<UserCommunities, bool>> condition = c => c.CommunityId == communityId; Func<UserCommunities, object> orderBy = c => c.RoleID; // Gets the total items satisfying the condition pageDetails.TotalCount = _userCommunitiesRepository.GetItemsCount(condition); pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1); // TODO: Passing the condition in a variable doesn't add the WHERE clause in SQL server. Need to work on this later. var items = _userCommunitiesRepository.GetItems(condition, orderBy, true, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); var permissionDetails = new PermissionDetails(); if (items != null && items.Any()) { var userRole = _userRepository.GetUserRole(userId, communityId); // User has to be at least contributor to know the permission details of the community. if (userRole >= UserRole.Contributor) { permissionDetails.CurrentUserPermission = userRole.GetPermission(); foreach (var item in items) { var permissionItem = new PermissionItem(); Mapper.Map(item, permissionItem); permissionItem.CurrentUserRole = userRole; permissionDetails.PermissionItemList.Add(permissionItem); } } else { // If user is not having contributor or higher role, he will get item not found or don't have permission exception page. permissionDetails = null; } } return permissionDetails; }
public IEnumerable<ContentDetails> GetContents(long userId, PageDetails pageDetails, bool onlyPublic) { IList<ContentDetails> contents = new List<ContentDetails>(); Expression<Func<ContentsView, bool>> condition; this.CheckNotNull(() => new { userID = userId, pageDetails }); Func<ContentsView, object> orderBy = c => c.LastUpdatedDatetime; if (onlyPublic) { var accessType = AccessType.Public.ToString(); condition = c => c.CreatedByID == userId && c.AccessType == accessType; } else { condition = c => c.CreatedByID == userId; } foreach (var content in _contentsViewRepository.GetItems( condition, orderBy, true, ((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage), pageDetails.ItemsPerPage)) { var contentDetails = onlyPublic ? new ContentDetails(Permission.Visitor) : new ContentDetails(Permission.Contributor); Mapper.Map(content, contentDetails); contents.Add(contentDetails); } return contents; }
/// <summary> /// Retrieves the contents of the given community. /// </summary> /// <param name="communityId">ID of the community.</param> /// <param name="userId">Id of the user who is accessing</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>An enumerable which contains the contents of the community</returns> public IEnumerable<ContentDetails> GetContents(long communityId, long userId, PageDetails pageDetails) { this.CheckNotNull(() => new { pageDetails }); IList<ContentDetails> contents = new List<ContentDetails>(); var contentIDs = _communityRepository.GetContentIDs(communityId, userId); // Gets the total number of contents of the community pageDetails.TotalCount = contentIDs.Count(); pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1); if (contentIDs != null && contentIDs.Count() > 0) { contentIDs = contentIDs.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage); foreach (var content in _contentRepository.GetItems(contentIDs)) { var userRole = UserRole.Visitor; if (content.CreatedByID == userId) { userRole = UserRole.Owner; } else { userRole = _userRepository.GetUserRole(userId, communityId); if (userRole == UserRole.Moderator) { // In case of user is Moderator for the parent community, he should be considered as moderator inherited so // that he will be having permissions to edit/delete this content. userRole = UserRole.ModeratorInheritted; } else if (userRole == UserRole.Contributor) { // In case of user is Contributor for the parent community, he should be considered as Owner if the content // is created by him. If the content is not created by him, he should be considered as Reader. userRole = UserRole.Reader; } } var contentDetails = new ContentDetails(userRole.GetPermission()); // Some of the values which comes from complex objects need to be set through this method. contentDetails.SetValuesFrom(content); contents.Add(contentDetails); } } return contents; }
/// <summary> /// Initializes a new instance of the InviteRequestViewModel class. /// </summary> public InviteRequestViewModel(IList<InviteRequestDetailsViewModel> inviteRequestList, PageDetails paginationDetails) { this.InviteRequestList = inviteRequestList; this.PaginationDetails = paginationDetails; }
private IEnumerable<CommunityDetails> GetFeaturedCommunityDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { Func<FeaturedCommunitiesView, object> orderBy = c => c.SortOrder; var condition = GetFeaturedCommunitiesCondition(entityHighlightFilter); // Gets the total items satisfying the var totalItemsForCondition = _featuredCommunitiesViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); IEnumerable<FeaturedCommunitiesView> communities = null; communities = _featuredCommunitiesViewRepository.GetItems(condition, orderBy, false, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); var communityDetails = new List<CommunityDetails>(); if (communities != null) { foreach (var community in communities) { var communityDetail = new CommunityDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(community, communityDetail); communityDetails.Add(communityDetail); } } return communityDetails; }
/// <summary> /// Gets the page details instance. /// </summary> /// <param name="userId">User Id for whom page is rendered</param> /// <param name="entityType">Entity Type (Community/Content)</param> /// <param name="currentPage">Selected page to be rendered</param> /// <returns>Page details instance</returns> private PageDetails GetPageDetails(long userId, EntityType entityType, int currentPage) { var pageDetails = new PageDetails(currentPage); pageDetails.ItemsPerPage = Constants.EntitiesPerUser; var totalItemsForCondition = 0; switch (entityType) { case EntityType.Community: totalItemsForCondition = ProfileService.GetCommunitiesCount(userId, userId != CurrentUserId); break; case EntityType.Content: totalItemsForCondition = ProfileService.GetContentsCount(userId, userId != CurrentUserId); break; default: break; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); pageDetails.CurrentPage = currentPage > pageDetails.TotalPages ? pageDetails.TotalPages : currentPage; pageDetails.TotalCount = totalItemsForCondition; return pageDetails; }
/// <summary> /// It returns the entity list /// </summary> /// <param name="userId">User Id for whom page is rendered</param> /// <param name="entityType">Entity type (Community/Content)</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>List of entity objects</returns> private async Task<List<EntityViewModel>> GetEntities(long userId, EntityType entityType, PageDetails pageDetails) { // TODO: Need to create a model for passing parameters to this controller var highlightEntities = new List<EntityViewModel>(); if (entityType == EntityType.Community) { var communities = ProfileService.GetCommunities(userId, pageDetails, userId != CurrentUserId); foreach (var community in communities) { var communityViewModel = new CommunityViewModel(); Mapper.Map(community, communityViewModel); highlightEntities.Add(communityViewModel); } } else if (entityType == EntityType.Content) { var contents = ProfileService.GetContents(userId, pageDetails, userId != CurrentUserId); foreach (var content in contents) { var contentViewModel = new ContentViewModel(); contentViewModel.SetValuesFrom(content); highlightEntities.Add(contentViewModel); } } return highlightEntities; }
private async Task<Stream> GetTopCommunity(EntityHighlightFilter entityHighlightFilter) { var entityService = DependencyResolver.Current.GetService(typeof(IEntityService)) as IEntityService; var pageDetails = new PageDetails(1); pageDetails.ItemsPerPage = 20; var communities = await entityService.GetCommunities(entityHighlightFilter, pageDetails); var payloadDetails = PayloadDetailsExtensions.InitializePayload(); payloadDetails.SetValuesFrom(communities); RewritePayloadUrls(payloadDetails, false); return GetOutputStream(payloadDetails); }
/// <summary> /// It returns the entity list /// </summary> /// <param name="entityType">Entity type (Community/Content)</param> /// <param name="entityHighlightFilter">Entity Highlight filter for the entities (Featured/Latest/Popular/Related)</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>entity object</returns> private async Task<List<EntityViewModel>> GetHighlightEntities(EntityType entityType, EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { // TODO: Need to create a model for passing parameters to this controller var highlightEntities = new List<EntityViewModel>(); // Set the user who is getting the highlight entities. entityHighlightFilter.UserID = CurrentUserId; // Total pages will be set by the service. if (pageDetails.ItemsPerPage == 0) { pageDetails.ItemsPerPage = Constants.HighlightEntitiesPerPage; } if (entityType == EntityType.Community) { var communities = await _entityService.GetCommunities(entityHighlightFilter, pageDetails); foreach (var community in communities) { var communityViewModel = new CommunityViewModel(); Mapper.Map(community, communityViewModel); highlightEntities.Add(communityViewModel); } } else if (entityType == EntityType.Content) { var contents = await _entityService.GetContents(entityHighlightFilter, pageDetails); foreach (var content in contents) { var contentViewModel = new ContentViewModel(); contentViewModel.SetValuesFrom(content); highlightEntities.Add(contentViewModel); } } return highlightEntities; }
/// <summary> /// Initializes a new instance of the UploadAssetViewModel class. /// </summary> public UploadAssetViewModel(IList<BlobDetails> assets, PageDetails paginationDetails) { this.Assets = assets; this.PaginationDetails = paginationDetails; }
/// <summary> /// Gets the content from the Layerscape database for the given highlight type and category type. /// Highlight can be none which gets all the contents. /// </summary> /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>List of all contents</returns> public async Task<IEnumerable<ContentDetails>> GetContents(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { this.CheckNotNull(() => new { entityHighlightFilter, pageDetails }); if (entityHighlightFilter.HighlightType == HighlightType.Featured) { return GetFeaturedContentDetails(entityHighlightFilter, pageDetails); } if (entityHighlightFilter.HighlightType == HighlightType.Related) { return GetRelatedContentDetails(entityHighlightFilter, pageDetails); } return GetContentDetails(entityHighlightFilter, pageDetails); }
/// <summary> /// Gets the user permission details for the given community /// </summary> /// <param name="communityId">Community for which permission details to be fetched</param> /// <param name="permissionsTab">Permission tab (Users/Requests) for which data to be fetched</param> /// <param name="currentPage">Current page to be rendered</param> /// <returns>ViewModel with permission details</returns> private async Task<PermissionViewModel> GetUserPermissionDetails(long? communityId, PermissionsTab permissionsTab, int currentPage) { var pageDetails = new PageDetails(currentPage) {ItemsPerPage = Constants.PermissionsPerPage}; PermissionDetails permissionDetails = null; if (permissionsTab == PermissionsTab.Users) { permissionDetails = await ProfileService.GetUserPemissions(CurrentUserId, communityId.Value, pageDetails); } else if (permissionsTab == PermissionsTab.Requests) { permissionDetails = await ProfileService.GetUserPemissionRequests(CurrentUserId, communityId, pageDetails); } else { permissionDetails = await ProfileService.GetUserPemissionRequests(CurrentUserId, null, pageDetails); } if (permissionDetails != null) { // Check if there is only one owner for the current community. var singleOwner = permissionDetails.PermissionItemList.Count(p => p.Role == UserRole.Owner) == 1; var permissionList = new List<PermissionDetailsViewModel>(); foreach (var permissionItem in permissionDetails.PermissionItemList) { var model = new PermissionDetailsViewModel() { Id = permissionItem.UserID, Name = permissionItem.Name, CommunityId = permissionItem.CommunityID, CommunityName = permissionItem.CommunityName, Comment = permissionItem.Comment, Date = permissionItem.Date, Role = permissionItem.Role, IsInherited = permissionItem.IsInherited, CurrentUserRole = permissionItem.CurrentUserRole }; model.Requested = model.Date.GetFormattedDifference(DateTime.UtcNow); model.CanShowEditLink = model.CanShowDeleteLink = true; if (model.Role == UserRole.Owner && (singleOwner || model.CurrentUserRole < UserRole.Owner)) { // 1. No edit/delete options should be shown if there is only one owner. // 2. Only owners and site administrators can edit/delete owners permissions. model.CanShowEditLink = model.CanShowDeleteLink = false; } else if (model.Id == CurrentUserId) { // No edit/delete options should be shown in users permission page for the logged in user model.CanShowEditLink = model.CanShowDeleteLink = false; } else if (permissionItem.IsInherited) { // If the role of user permission is is inherited, then user should not be allowed to delete. model.CanShowDeleteLink = false; // If the role of user permission is Owner and is inherited, then user should not be allowed to edit also. if (model.Role == UserRole.Owner) { model.CanShowEditLink = false; } } permissionList.Add(model); } var permissionViewModel = new PermissionViewModel( permissionDetails.CurrentUserPermission, permissionList, pageDetails, permissionsTab); return permissionViewModel; } else return null; }
/// <summary> /// Retrieves the sub communities of a given community. This only retrieves the immediate children. /// </summary> /// <param name="communityId">ID of the community.</param> /// <param name="userId">Id of the user who is accessing</param> /// <param name="pageDetails">Details about the pagination</param> /// <param name="onlyItemCount">To get only item count, not the entities. When community details page is loaded first time, /// no need to get the communities, only count is enough.</param> /// <returns>Collection of sub communities</returns> public IEnumerable<CommunityDetails> GetSubCommunities(long communityId, long userId, PageDetails pageDetails, bool onlyItemCount) { this.CheckNotNull(() => new { pageDetails }); IList<CommunityDetails> subCommunities = new List<CommunityDetails>(); var subCommunityIDs = _communityRepository.GetSubCommunityIDs(communityId, userId); // Gets the total number of direct sub communities of the community pageDetails.TotalCount = subCommunityIDs.Count(); pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1); // When community details page is loaded first time, no need to get the communities, only count is enough. if (!onlyItemCount && subCommunityIDs != null && subCommunityIDs.Count() > 0) { subCommunityIDs = subCommunityIDs.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage); foreach (var community in _communityRepository.GetItems(subCommunityIDs)) { var userRole = _userRepository.GetUserRole(userId, community.CommunityID); var communityDetails = new CommunityDetails(userRole.GetPermission()); // Some of the values which comes from complex objects need to be set through this method. communityDetails.SetValuesFrom(community); subCommunities.Add(communityDetails); } } return subCommunities; }
/// <summary> /// Gets all the comments for the specified Community. /// </summary> /// <param name="filter">Filter which comments to be fetched</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>List of all comments of the Community</returns> public async Task<IEnumerable<CommentDetails>> GetCommunityComments(CommentFilter filter, PageDetails pageDetails) { this.CheckNotNull(() => new { filter, pageDetails }); Func<CommunityComments, object> orderBy = (communityComments) => communityComments.CommentedDatetime; Expression<Func<CommunityComments, bool>> condition = (communityComments) => communityComments.CommunityID == filter.EntityId && communityComments.IsDeleted == false; // Gets the total items satisfying the var totalItemsForCondition = _communityCommentRepository.GetItemsCount(condition); pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); IEnumerable<CommunityComments> comments = _communityCommentRepository .GetItems(condition, orderBy, filter.OrderType == OrderType.NewestFirst, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); var commentDetails = new List<CommentDetails>(); if (comments != null) { foreach (var item in comments) { var comment = new CommentDetails(); Mapper.Map(item, comment); commentDetails.Add(comment); } } return commentDetails; }
private IEnumerable<ContentDetails> GetContentDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { var orderBy = GetContentOrderByClause(entityHighlightFilter); var condition = GetContentConditionClause(entityHighlightFilter); // Gets the total items satisfying the var totalItemsForCondition = _contentsViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); // TODO: Passing the condition in a variable doesn't add the WHERE clause in SQL server. Need to work on this later. IEnumerable<ContentsView> contents = null; // Only for Popular/Top Rated, there is multiple order by which needs to added here. if (entityHighlightFilter.HighlightType == HighlightType.Popular) { // TODO: This is a temporary fix, since multiple order by cannot be passed. // Need to do this in a better way, instead of getting all the items. contents = _contentsViewRepository.GetItems(condition, null, true); contents = contents .OrderByDescending((ContentsView c) => c.AverageRating) .ThenByDescending<ContentsView, int?>((ContentsView c) => c.RatedPeople) .Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage) .Take(pageDetails.ItemsPerPage) .ToList(); } else { contents = _contentsViewRepository.GetItems(condition, orderBy, true, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage); } var contentDetails = new List<ContentDetails>(); if (contents != null) { foreach (var content in contents) { var contentDetail = new ContentDetails(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(content, contentDetail); contentDetails.Add(contentDetail); } } return contentDetails; }
/// <summary> /// Gets the entities for the given community. /// </summary> /// <param name="entityId">Entity Id (Community/Content)</param> /// <param name="entityType">Entity type (Community/Content)</param> /// <param name="pageDetails">Details about the pagination</param> /// <param name="onlyItemCount">To get only item count, not the entities. When community details page is loaded first time, /// no need to get the communities, only count is enough.</param> /// <returns>Collection of entities</returns> private List<EntityViewModel> GetCommunityEntities(long entityId, EntityType entityType, PageDetails pageDetails, bool onlyItemCount) { var entities = new List<EntityViewModel>(); // Default value is 20 if the value is not specified or wrong in the configuration file. // Total pages will be set by the service. pageDetails.ItemsPerPage = Constants.HighlightEntitiesPerPage; // Do not hit the database if the entity is not valid. This will happen for private communities. if (entityId > 0) { if (entityType == EntityType.Community || entityType == EntityType.Folder) { var subCommunities = _entityService.GetSubCommunities(entityId, CurrentUserId, pageDetails, onlyItemCount); foreach (var item in subCommunities) { var subCommunityViewModel = new CommunityViewModel(); Mapper.Map(item, subCommunityViewModel); entities.Add(subCommunityViewModel); } } else { var contents = _entityService.GetContents(entityId, CurrentUserId, pageDetails); foreach (var item in contents) { var contentViewModel = new ContentViewModel(); contentViewModel.SetValuesFrom(item); entities.Add(contentViewModel); } } } return entities; }
/// <summary> /// Gets the Related Community details for the given community. /// </summary> /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param> /// <param name="pageDetails">Details about the pagination</param> /// <returns>Collection of related communities</returns> private IEnumerable<CommunityDetails> GetRelatedCommunityDetails(EntityHighlightFilter entityHighlightFilter, PageDetails pageDetails) { var userId = entityHighlightFilter.EntityId.HasValue ? entityHighlightFilter.EntityId.Value : 0; var relatedCommunityIds = _communityTagsRepository.GetRelatedCommunityIDs(userId, entityHighlightFilter.UserID); var condition = GetRelatedCommunitiesCondition(relatedCommunityIds); // Gets the total items satisfying the var totalItemsForCondition = _communitiesViewRepository.GetItemsCount(condition); // If TotalCount is already specified in pageDetails, need to consider that. Ignore even if there are more items in the DB. if (pageDetails.TotalCount > 0 && totalItemsForCondition > pageDetails.TotalCount) { totalItemsForCondition = pageDetails.TotalCount; } pageDetails.TotalPages = (totalItemsForCondition / pageDetails.ItemsPerPage) + ((totalItemsForCondition % pageDetails.ItemsPerPage == 0) ? 0 : 1); IEnumerable<CommunitiesView> communities = null; relatedCommunityIds = relatedCommunityIds.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage); condition = GetRelatedCommunitiesCondition(relatedCommunityIds); communities = _communitiesViewRepository.GetItems(condition, null, false); var communityDetails = new List<CommunityDetails>(); if (communities != null) { foreach (var communityId in relatedCommunityIds) { var communityDetail = new CommunityDetails(); var community = communities.Where(c => c.CommunityID == communityId).FirstOrDefault(); // Some of the values which comes from complex objects need to be set through this method. Mapper.Map(community, communityDetail); communityDetails.Add(communityDetail); } } return communityDetails; }
/// <summary> /// This returns the results for Search Result View /// </summary> /// <param name="searchText">search Text</param> /// <param name="selectedTab">selected Tab Text</param> /// <returns>EntityViewModel collection</returns> private async Task<JsonResult> GetSearchResults(string searchText, string selectedTab, int currentPage, SearchViewModel searchQuery, SearchSortBy sortBy = SearchSortBy.Rating) { ViewData["SearchText"] = searchText = (string.IsNullOrWhiteSpace(searchText) || searchText.ToLower(CultureInfo.CurrentCulture).Equals(Resources.DefaultSearchText.ToLower(CultureInfo.CurrentCulture))) ? string.Empty : searchText; ViewData["SearchMessage"] = string.Empty; IEnumerable<EntityViewModel> results = null; var pageDetails = new PageDetails(currentPage); if (!string.IsNullOrWhiteSpace(searchText)) { pageDetails.ItemsPerPage = searchQuery.ResultsPerPage; var searchQueryDetails = new SearchQueryDetails(); if (searchQuery.ContentTypeFilter != null) { foreach (var contentFilterValue in searchQuery.ContentTypeFilter.Split(',')) { searchQueryDetails.ContentTypeFilter.Add(Convert.ToInt32(contentFilterValue, CultureInfo.CurrentCulture)); } } if (searchQuery.CategoryFilter != null) { foreach (var categoryFilterValue in searchQuery.CategoryFilter.Split(',')) { searchQueryDetails.CategoryFilter.Add(Convert.ToInt32(categoryFilterValue, CultureInfo.CurrentCulture)); } } searchQueryDetails.SortBy = searchQuery.SortBy.ToEnum<string, SearchSortBy>(sortBy); results = await _searchService.SimpleSearch(searchText.Replace("'", "''"), CurrentUserId, pageDetails, searchQueryDetails); // If the total count of items are less than the selected per page items, select previous per page items //ViewData["CurrentPage"] = currentPage; //ViewData["TotalPage"] = pageDetails.TotalPages; //ViewData["TotalCount"] = pageDetails.TotalCount; } return Json(new{ searchResults=results, pageInfo = pageDetails }); }
/// <summary> /// Gets the Invite Request details for the given community /// </summary> /// <param name="communityId">Community for which Invite Request details to be fetched</param> /// <param name="currentPage">Current page to be rendered</param> /// <returns>ViewModel with invite request details</returns> private async Task<InviteRequestViewModel> GetInviteRequests(long communityId, int currentPage) { var pageDetails = new PageDetails(currentPage); pageDetails.ItemsPerPage = Constants.PermissionsPerPage; var inviteRequestItemList = await ProfileService.GetInviteRequests(CurrentUserId, communityId, pageDetails); this.CheckNotNull(() => new { inviteRequestItemList }); var inviteRequestList = new List<InviteRequestDetailsViewModel>(); for (var i = 0; i < inviteRequestItemList.Count(); i++) { var model = new InviteRequestDetailsViewModel() { InviteRequestID = inviteRequestItemList.ElementAt(i).InviteRequestID, CommunityID = inviteRequestItemList.ElementAt(i).CommunityID, EmailId = inviteRequestItemList.ElementAt(i).EmailIdList[0], Role = (UserRole)inviteRequestItemList.ElementAt(i).RoleID, InvitedDate = inviteRequestItemList.ElementAt(i).InvitedDate }; inviteRequestList.Add(model); } var inviteRequestViewModel = new InviteRequestViewModel(inviteRequestList, pageDetails); return inviteRequestViewModel; }
public IEnumerable<CommunityDetails> GetCommunities(long userId, PageDetails pageDetails, bool onlyPublic) { this.CheckNotNull(() => new { userID = userId, pageDetails }); IList<CommunityDetails> userCommunities = new List<CommunityDetails>(); Func<CommunitiesView, object> orderBy = c => c.LastUpdatedDatetime; // Get all the community ids to which user is given role of contributor or higher. var userCommunityIds = _userRepository.GetUserCommunitiesForRole(userId, UserRole.Contributor, onlyPublic); // Get only the communities for the current page. userCommunityIds = userCommunityIds.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage); Expression<Func<CommunitiesView, bool>> condition = c => userCommunityIds.Contains(c.CommunityID); foreach (var community in _communitiesViewRepository.GetItems(condition, orderBy, true)) { CommunityDetails communityDetails; if (onlyPublic) { // In case of only public, user is looking at somebody else profile and so just send the user role as Visitor. communityDetails = new CommunityDetails(Permission.Visitor); } else { var userRole = _userRepository.GetUserRole(userId, community.CommunityID); communityDetails = new CommunityDetails(userRole.GetPermission()); } Mapper.Map(community, communityDetails); userCommunities.Add(communityDetails); } return userCommunities; }