Ejemplo n.º 1
0
        /// <summary>
        /// 获取前几条
        /// </summary>
        /// <param name="memTopEnum"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List <MemTopDetailView> GetTopMembers(MemTopEnum?memTopEnum, int count)
        {
            var filter = base.GetFilterEnabled();
            var order  = base.Order();

            if (memTopEnum.HasValue && memTopEnum.Value == MemTopEnum.ResourseCount)
            {
                order = w => w.OrderByDescending(b => b.Articles.Count);
            }

            return(_Respository.GetFeilds(t => new MemTopDetailView
            {
                UserId = t.Id,
                RealName = t.RealName,
                ArticleCount = t.Articles.Count(w => w.ArticleCategory != null),
                TopicCount = t.Articles.Count(w => w.ArticleTopic != null),
                FansCount = 0,
                HeadIcon = t.HeadIcon,
                NickName = t.NickName
            }, filter, order, "Articles,ArticleCategory").ToList());
        }
Ejemplo n.º 2
0
        public PagedList <ArticleDetailView> GetBooks(ArticleSearchView searchView, int pageIndex, int pageSize)
        {
            var expression        = GetFilterEnabled();
            var includeProperties = "ArticleCategory";
            //if (!searchView.SpecialTopicId.IsEmpty())
            //{
            //    includeProperties = "";
            //    expression = base.GetFilterEnabled();
            //    expression = expression.And(t => t.SpecialTopicId == searchView.SpecialTopicId);
            //}
            var orderpr = base.Order();

            orderpr = o => o.OrderBy(t => t.CreatorTime);

            if (!string.IsNullOrEmpty(searchView.Keyword))
            {
                expression = expression.And(t => t.Title.Contains(searchView.Keyword) ||
                                            (!t.Description.IsEmpty() && t.Description.Contains(searchView.Keyword)) ||
                                            (!t.Keyword.IsEmpty() && t.Keyword.Contains(searchView.Keyword)));
            }

            if (!searchView.Title.IsEmpty())
            {
                expression = expression.And(t => t.Title.Contains(searchView.Title));
            }

            if (!string.IsNullOrEmpty(searchView.MemberId))
            {
                expression = expression.And(t => t.MemberId == searchView.MemberId);
            }
            if (!searchView.CategoryId.IsEmpty())
            {
                expression = expression.And(t => t.CategoryId == searchView.CategoryId);
            }

            if (searchView.StartDate.HasValue)
            {
                expression = expression.And(t => t.CreatorTime >= searchView.StartDate);
            }
            if (searchView.EndDate.HasValue)
            {
                expression = expression.And(t => t.CreatorTime <= searchView.EndDate);
            }
            if (!searchView.ResourceType.IsEmpty())
            {
                //资源类型多样化查询处理
                if (searchView.ResourceType == "pdf" || searchView.ResourceType == "doc" || searchView.ResourceType == "docx" ||
                    searchView.ResourceType == "ppt" || searchView.ResourceType == "pptx")
                {
                    expression = expression.And(t => t.ResourceType == searchView.ResourceType);
                }
                else if (searchView.ResourceType == "jpg")
                {
                    expression = expression.And(t => ConfigManager.UploadAllowImgExtension.Contains(t.ResourceType));
                }
                else if (searchView.ResourceType == "mp4")
                {
                    expression = expression.And(t => ConfigManager.UploadAllowVideoExtension.Contains(t.ResourceType));
                }
                else if (searchView.ResourceType == "mp3")
                {
                    expression = expression.And(t => ConfigManager.UploadAllowVoiceExtension.Contains(t.ResourceType));
                }
                else if (searchView.ResourceType == "swf")
                {
                    expression = expression.And(t => ConfigManager.UploadAllowFlashExtension.Contains(t.ResourceType));
                }
            }
            if (searchView.StartScore.HasValue)
            {
                expression = expression.And(t => t.RequireAmount > searchView.StartScore);
            }
            if (searchView.EndScore.HasValue)
            {
                expression = expression.And(t => t.RequireAmount <= searchView.EndScore);
            }
            if (searchView.StartPage.HasValue)
            {
                expression = expression.And(t => t.PageCount >= searchView.StartPage);
            }
            if (searchView.EndPage.HasValue)
            {
                expression = expression.And(t => t.PageCount <= searchView.EndPage);
            }
            //审核状态
            if (searchView.BookStatus.HasValue)
            {
                expression = expression.And(t => t.BookStatus == searchView.BookStatus);
            }
            if (!searchView.SearchStatus.IsEmpty())
            {
                if (searchView.SearchStatus == "0")
                {
                    orderpr = o => o.OrderByDescending(b => b.CreatorTime);
                }
                if (searchView.SearchStatus == "1")
                {
                    orderpr = o => o.OrderByDescending(b => b.DownloadCount);
                }
                if (searchView.SearchStatus == "2")
                {
                    orderpr = o => o.OrderByDescending(b => b.ReadCount);
                }
            }
            //分类
            if (!searchView.ParentCategoryId.IsEmpty())
            {
                if (searchView.CategoryId.IsEmpty())
                {
                    expression = expression.And(t => t.ArticleCategory.ParentId == searchView.ParentCategoryId);
                }
            }
            if (!searchView.CategoryId.IsEmpty())
            {
                expression = expression.And(t => t.CategoryId == searchView.CategoryId);
            }

            //expression = expression.And(t => t.CategoryId == 2);
            var data = _Respository.GetPagedList(
                u => new ArticleDetailView
            {
                Id            = u.Id,
                Title         = u.Title,
                CoverUrl      = u.CoverUrl,
                ShortTitle    = u.ShortTitle,
                Description   = u.Description,
                Attachment    = u.Attachment,
                CategoryId    = u.CategoryId,
                Category      = (u.ArticleCategory == null ? null : u.ArticleCategory.Title),
                ReadCount     = u.ReadCount,
                DownloadCount = u.DownloadCount,
                ResourceUrl   = u.ResourceUrl,
                CreatorTime   = u.CreatorTime,
                ResourceSize  = u.ResourceSize,
                RequireAmount = u.RequireAmount,
                BookStatus    = u.BookStatus,
                AuditMessage  = u.AuditMessage,
                ResourceType  = u.ResourceType,
                MemberId      = u.MemberId
            }
                , expression, pageIndex, pageSize, orderpr, includeProperties);


            if (data.Any() && searchView.HasMember.HasValue && searchView.HasMember == true)
            {
                var meberIds = data.Select(u => u.MemberId).Distinct().ToArray();
                if (meberIds.Any())
                {
                    var memList = _IMemberRespository.GetFeilds(u => new { u.Id, u.UserName }, w => w.EnabledMark == true && meberIds.Contains(w.Id)).ToDictionary(k => k.Id, v => v.UserName);
                    data.ForEach(article => {
                        article.Member = "系统管理员";
                        if (!article.MemberId.IsEmpty())
                        {
                            article.Member = memList.TryGetValue(article.MemberId);
                        }
                    });
                }
            }
            return(data);
        }