コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: EntityController.cs プロジェクト: faorg/wwt-website
        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;

        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets condition for Top Rated communities.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Condition for Top Rated communities.</returns>
        private static Expression<Func<CommunitiesView, bool>> GetTopRatedCommunitiesCondition(EntityHighlightFilter entityHighlightFilter)
        {
            Expression<Func<CommunitiesView, bool>> condition;

            var accessType = AccessType.Public.ToString();

            // In case of TopRated highlight, condition to be decided based on Rating and category as well.
            if (entityHighlightFilter.CategoryType == CategoryType.All)
            {
                condition = (CommunitiesView c) => c.AverageRating > 0
                    && c.RatedPeople >= Constants.MinRatedPeopleCount
                    && c.CommunityTypeID == (int)CommunityTypes.Community
                    && c.AccessType == accessType;
            }
            else
            {
                var categoryType = entityHighlightFilter.CategoryType.ToString();
                condition = (CommunitiesView c) => c.AverageRating > 0
                    && c.RatedPeople >= Constants.MinRatedPeopleCount
                    && c.CategoryName == categoryType
                    && c.CommunityTypeID == (int)CommunityTypes.Community
                    && c.AccessType == accessType;
            }

            return condition;
        }
コード例 #5
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets order by clause for contents.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Order by clause for contents.</returns>
        private static Func<ContentsView, object> GetContentOrderByClause(EntityHighlightFilter entityHighlightFilter)
        {
            Func<ContentsView, object> orderBy = null;

            // Set the order by expression for the given highlight type.
            switch (entityHighlightFilter.HighlightType)
            {
                case HighlightType.Latest:
                    orderBy = (ContentsView c) => c.LastUpdatedDatetime;
                    break;
                case HighlightType.MostDownloaded:
                    orderBy = (ContentsView c) => c.DownloadCount;
                    break;
            }

            return orderBy;
        }
コード例 #6
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets condition clause for contents.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Condition clause for contents.</returns>
        private static Expression<Func<ContentsView, bool>> GetContentConditionClause(EntityHighlightFilter entityHighlightFilter)
        {
            Expression<Func<ContentsView, bool>> condition = null;

            // Set the order by expression for the given highlight type.
            switch (entityHighlightFilter.HighlightType)
            {
                case HighlightType.Popular:
                    condition = GetTopRatedContentsCondition(entityHighlightFilter);
                    break;
                case HighlightType.MostDownloaded:
                    condition = GetTopDownloadedContentsCondition(entityHighlightFilter);
                    break;
            }

            var accessType = AccessType.Public.ToString();

            // Only when category type is other then "All" and also the condition is not already set (which will happen when this method is called 
            // with highlight type as Featured and category type as not "All"), condition to be set here.
            if (entityHighlightFilter.CategoryType != CategoryType.All && condition == null)
            {
                condition = (ContentsView c) => c.CategoryID == (int)entityHighlightFilter.CategoryType && 
                    c.AccessType == accessType &&
                    entityHighlightFilter.ContentType != ContentTypes.All ? c.TypeID == (int)entityHighlightFilter.ContentType : c.TypeID > -1;
            }
            if (condition == null && entityHighlightFilter.ContentType != ContentTypes.All)
            {
                condition = (ContentsView c) => c.AccessType == accessType && c.TypeID == (int)entityHighlightFilter.ContentType;
            }
            // Still if condition is not set, add a condition to get only public contents.
            return condition ?? ((ContentsView c) => c.AccessType == accessType);
            
        }
コード例 #7
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets order by clause for communities.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Order by clause for communities.</returns>
        private static Func<CommunitiesView, object> GetCommunityOrderByClause(EntityHighlightFilter entityHighlightFilter)
        {
            Func<CommunitiesView, object> orderBy = null;

            // Set the order by expression for the given highlight type.
            switch (entityHighlightFilter.HighlightType)
            {
                case HighlightType.Latest:
                    orderBy = c => c.LastUpdatedDatetime;
                    break;
            }

            return orderBy;
        }
コード例 #8
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <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;
        }
コード例 #9
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        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;
        }
コード例 #10
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        private IEnumerable<ContentDetails> GetAllContents(EntityHighlightFilter entityHighlightFilter)
        {
            Func<ContentsView, object> orderBy = c => c.LastUpdatedDatetime;

            var accessType = AccessType.Public.ToString();
            Expression<Func<ContentsView, bool>> condition = c => c.AccessType == accessType;
            if (entityHighlightFilter.CategoryType != CategoryType.All)
            {
                condition = c => c.CategoryID == (int)entityHighlightFilter.CategoryType && c.AccessType == accessType;
            }

            var contents =  _contentsViewRepository.GetItems(condition, orderBy, true);

            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;
        }
コード例 #11
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        private IEnumerable<ContentDetails> GetAllFeaturedContents(EntityHighlightFilter entityHighlightFilter)
        {
            Func<FeaturedContentsView, object> orderBy = c => c.SortOrder;
            Expression<Func<FeaturedContentsView, bool>> condition = c => c.FeaturedCategoryID == (int)entityHighlightFilter.CategoryType;

            var contents =  _featuredContentsViewRepository.GetItems(condition, orderBy, false);

            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;
        }
コード例 #12
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        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;
        }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets condition for Featured content.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Condition for Featured contents.</returns>
        private static Expression<Func<FeaturedContentsView, bool>> GetFeaturedContentCondition(EntityHighlightFilter entityHighlightFilter)
        {
            Expression<Func<FeaturedContentsView, bool>> condition;

            var accessType = AccessType.Public.ToString();

            // In case of Featured highlight, condition to be decided based on highlight and category as well.
            condition = c =>
                c.FeaturedCategoryID == (int)entityHighlightFilter.CategoryType
                && c.AccessType == accessType;

            return condition;
        }
コード例 #16
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets condition for Top Downloaded Contents.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Condition for Top Downloaded Content.</returns>
        private static Expression<Func<ContentsView, bool>> GetTopDownloadedContentsCondition(EntityHighlightFilter entityHighlightFilter)
        {
            Expression<Func<ContentsView, bool>> condition;

            var accessType = AccessType.Public.ToString();

            // In case of Top Rated highlight, condition to be decided based on rating and category as well.
            if (entityHighlightFilter.CategoryType == CategoryType.All)
            {
                if (entityHighlightFilter.ContentType != ContentTypes.All)
                {
                    condition = c => c.AccessType == accessType &&
                                                    c.DownloadCount > 0 &&
                                                    c.TypeID == (int) entityHighlightFilter.ContentType;
                }
                else
                {
                    condition = c => c.AccessType == accessType &&
                                                    c.DownloadCount > 0;
                }
            }
            else
            {
                if (entityHighlightFilter.ContentType != ContentTypes.All)
                {
                    condition = c => c.CategoryID == (int)entityHighlightFilter.CategoryType && 
                                                    c.AccessType == accessType &&
                                                    c.DownloadCount > 0 &&
                                                    c.TypeID == (int) entityHighlightFilter.ContentType;
                }
                else
                {
                    condition = (ContentsView c) => c.CategoryID == (int) entityHighlightFilter.CategoryType &&
                                                    c.AccessType == accessType && c.DownloadCount > 0;
                }
            }

            return condition;
        }
コード例 #17
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <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);
            
        }
コード例 #18
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        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;
        }
コード例 #19
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <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>
        /// <returns>List of all contents</returns>
        public async Task<IEnumerable<ContentDetails>> GetContents(EntityHighlightFilter entityHighlightFilter)
        {
            this.CheckNotNull(() => new { entityHighlightFilter });

            if (entityHighlightFilter.HighlightType == HighlightType.Featured)
            {
                return  GetAllFeaturedContents(entityHighlightFilter);
            }
            else
            {
                return  GetAllContents(entityHighlightFilter);
            }
        }
コード例 #20
0
ファイル: EntityService.cs プロジェクト: faorg/wwt-website
        /// <summary>
        /// Gets condition clause for communities.
        /// </summary>
        /// <param name="entityHighlightFilter">Filters needed while retrieving collection of entities</param>
        /// <returns>Condition clause for communities.</returns>
        private static Expression<Func<CommunitiesView, bool>> GetCommunityConditionClause(EntityHighlightFilter entityHighlightFilter)
        {
            Expression<Func<CommunitiesView, bool>> condition = null;

            // Set the order by expression for the given highlight type.
            switch (entityHighlightFilter.HighlightType)
            {
                case HighlightType.Popular:
                    condition = GetTopRatedCommunitiesCondition(entityHighlightFilter);
                    break;
            }

            var accessType = AccessType.Public.ToString();

            // Only when category type is other then "All" and also the condition is not already set (which will happen when this method is called 
            // with highlight type as Featured and category type as not "All"), condition to be set here.
            if (entityHighlightFilter.CategoryType != CategoryType.All && condition == null)
            {
                var categoryType = entityHighlightFilter.CategoryType.ToString();
                condition = c => c.CategoryName == categoryType
                                                        && c.CommunityTypeID == (int)CommunityTypes.Community
                                                        && c.AccessType == accessType;
            }

            // Still if condition is not set, add a condition to get only public communities.
            if (condition == null)
            {
                condition = c => c.CommunityTypeID == (int)CommunityTypes.Community && c.AccessType == accessType;
            }

            return condition;
        }
コード例 #21
0
ファイル: EntityController.cs プロジェクト: faorg/wwt-website
        /// <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;
        }