Esempio n. 1
0
        protected List <ArticleJson> ArticleListInfo(List <Article> list, string usernumber = "")
        {
            //文章编号集合
            var array        = list.Select(x => x.Number).ToArray();
            var articletypes = AppHelper.GetArticleType();
            var parts        = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic).And("ArticleNumber").In(array).OrderAsc("SortID").ExecuteTypedList <ArticlePart>();

            List <string> userids = new List <string>();

            list.ForEach(x =>
            {
                userids.Add(x.CreateUserNumber);
            });

            var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Signature", "Number", "IsPay").From <User>().Where("Number").In(userids.ToArray()).ExecuteTypedList <User>();

            //判断是否关注、判断是否点赞、判断是否收藏
            var fans  = new List <Fan>();
            var zans  = new List <ArticleZan>();
            var keeps = new List <Keep>();

            if (!string.IsNullOrWhiteSpace(usernumber))
            {
                fans  = db.Find <Fan>(x => x.CreateUserNumber == usernumber).ToList();
                zans  = db.Find <ArticleZan>(x => x.CreateUserNumber == usernumber).ToList();
                keeps = db.Find <Keep>(x => x.CreateUserNumber == usernumber).ToList();
            }

            var tags = GetTag();

            List <ArticleJson> newlist = new List <ArticleJson>();

            list.ForEach(x =>
            {
                var user = users.FirstOrDefault(y => y.Number == x.CreateUserNumber);
                if (user != null)
                {
                    ArticleJson model   = new ArticleJson();
                    var articletype     = articletypes.FirstOrDefault(y => y.ID == x.TypeID);
                    model.UserID        = user.ID;
                    model.NickName      = user.NickName;
                    model.Avatar        = user.Avatar;
                    model.Signature     = user.Signature;
                    model.UserCover     = user.Cover;
                    model.IsPay         = user.IsPay;
                    model.ArticleID     = x.ID;
                    model.ArticleNumber = x.Number;
                    model.Title         = x.Title;
                    model.Views         = x.Views;
                    model.Goods         = x.Goods;

                    //标签
                    model.TagList = new List <Tag>();
                    if (!string.IsNullOrWhiteSpace(x.Tag))
                    {
                        var tag = x.Tag.Split(',').ToList();
                        tag.ForEach(y =>
                        {
                            var id   = Tools.SafeInt(y);
                            var item = tags.FirstOrDefault(z => z.ID == id);
                            if (item != null)
                            {
                                model.TagList.Add(item);
                            }
                        });
                    }
                    model.IsFollow     = fans.Count(y => y.ToUserNumber == x.CreateUserNumber);
                    model.IsZan        = zans.Count(y => y.ArticleNumber == x.Number);
                    model.IsKeep       = keeps.Count(y => y.ArticleNumber == x.Number);
                    model.UserNumber   = x.CreateUserNumber;
                    model.Cover        = x.Cover;
                    model.CreateDate   = x.CreateDate.ToString("yyyy-MM-dd hh:mm");
                    model.TypeName     = articletype == null ? "" : articletype.Name;
                    model.ArticlePart  = parts.Where(y => y.ArticleNumber == x.Number).OrderBy(y => y.ID).Take(4).ToList();
                    model.ArticlePower = x.ArticlePower;
                    model.Recommend    = x.Recommend;
                    model.Province     = x.Province;
                    model.City         = x.City;
                    model.Submission   = x.Submission;
                    newlist.Add(model);
                }
            });

            return(newlist);
        }