コード例 #1
0
        public bool HasPopularArticlesBySubtopic(Item subtopic)
        {
            List <Guid> articleIds = GetSubtopicArticleIds(subtopic);

            try
            {
                using (var mc = new MemberActivityContext())
                {
                    string activityType = String.Concat(Constants.UserActivity_Values.SubtopicItemViewed, subtopic.ID.ToGuid().ToString());

                    var query = from ma in mc.MemberActivity
                                where ma.Value == activityType &&
                                articleIds.Contains(ma.Key.Value)
                                select ma.Key;

                    return(query.Count() > 0);
                }
            }
            catch (Exception ex)
            {
                // TODO: log
            }

            return(false);
        }
コード例 #2
0
        public List <Guid> GetMostPopularArticleIdsBySubtopic(Item subtopic, int page, int pageSize, out bool hasMoreResults)
        {
            List <Guid> results = new List <Guid>();

            hasMoreResults = false;

            // Grab guids for articles under this subtopic to restrict article search
            List <Guid> articleIds = GetSubtopicArticleIds(subtopic);

            try
            {
                using (var mc = new MemberActivityContext())
                {
                    string activityType = String.Concat(Constants.UserActivity_Values.SubtopicItemViewed, subtopic.ID.ToGuid().ToString());

                    var query = from ma in mc.MemberActivity
                                where ma.Value == activityType &&
                                articleIds.Contains(ma.Key.Value)
                                group ma by ma.Key into groupView
                                select new
                    {
                        TotalViews = groupView.Count(),
                        ContentId  = groupView.Key
                    };

                    // Limit results that have at least one view
                    int totalArticles = query.Count();

                    int offset = (page - 1) * pageSize;

                    results = query.OrderByDescending(x => x.TotalViews)
                              .Select(x => x.ContentId.Value)
                              .Skip(offset)
                              .Take(pageSize)
                              .ToList();

                    hasMoreResults = results.Count() + offset < totalArticles;
                }
            }
            catch (Exception ex)
            {
                // TODO: log
            }

            return(results);
        }
コード例 #3
0
        public List<Guid> GetMostPopularArticleIdsBySubtopic(Item subtopic, int page, int pageSize, out bool hasMoreResults)
        {
            List<Guid> results = new List<Guid>();
            hasMoreResults = false;

            // Grab guids for articles under this subtopic to restrict article search
            List<Guid> articleIds = GetSubtopicArticleIds(subtopic);

            try
            {
                using (var mc = new MemberActivityContext())
                {
                    string activityType = String.Concat(Constants.UserActivity_Values.SubtopicItemViewed, subtopic.ID.ToGuid().ToString());

                    var query = from ma in mc.MemberActivity
                                where ma.Value == activityType
                                    && articleIds.Contains(ma.Key.Value)
                                group ma by ma.Key into groupView
                                select new
                                {
                                    TotalViews = groupView.Count(),
                                    ContentId = groupView.Key
                                };

                    // Limit results that have at least one view
                    int totalArticles = query.Count();

                    int offset = (page - 1) * pageSize;

                    results = query.OrderByDescending(x => x.TotalViews)
                                    .Select(x => x.ContentId.Value)
                                    .Skip(offset)
                                    .Take(pageSize)
                                    .ToList();

                    hasMoreResults = results.Count() + offset < totalArticles;
                }
            }
            catch (Exception ex)
            {
                // TODO: log
            }

            return results;
        }
コード例 #4
0
        public bool HasPopularArticlesBySubtopic(Item subtopic)
        {
            List<Guid> articleIds = GetSubtopicArticleIds(subtopic);

            try
            {
                using (var mc = new MemberActivityContext())
                {
                    string activityType = String.Concat(Constants.UserActivity_Values.SubtopicItemViewed, subtopic.ID.ToGuid().ToString());

                    var query = from ma in mc.MemberActivity
                                where ma.Value == activityType
                                    && articleIds.Contains(ma.Key.Value)
                                select ma.Key;

                    return query.Count() > 0;
                }
            }
            catch (Exception ex)
            {
                // TODO: log
            }

            return false;
        }