Esempio n. 1
0
        public object GetArticleListWidthSub(int kid, int pagesize = 10, int page = 1, string key = "", string random = "", string timeStamp = "", string signature = "")
        {
            var where = Article._.IsHide != 1;
            if (kid > 0)
            {
                //获取下属
                List <int> kids = new List <int>();
                kids.Add(kid);
                IList <ArticleCategory> subkinds = ArticleCategory.FindByParentID(kid);
                if (subkinds != null && subkinds.Count > 0)
                {
                    foreach (var item in subkinds)
                    {
                        kids.Add(item.Id);
                    }
                }
                where &= Article._.KId.In(kids);
            }
            if (!string.IsNullOrEmpty(key))
            {
                where &= Article._.Title.Contains(key);
            }
            if (page <= 0)
            {
                page = 1;
            }
            //计算分页
            int numPerPage, currentPage, startRowIndex;

            numPerPage    = pagesize;
            currentPage   = page;
            startRowIndex = (currentPage - 1) * numPerPage;

            IList <Article> list       = Article.FindAll(where, Article._.Sequence.Asc(), null, startRowIndex, numPerPage);
            long            totalCount = Article.FindCount(where, Article._.Sequence.Asc(), null, startRowIndex, numPerPage);
            List <object>   relist     = new List <object>();

            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    relist.Add(new
                    {
                        id          = item.Id,
                        title       = item.Title,
                        subTitle    = item.SubTitle,
                        pic         = item.Pic,
                        description = item.Description,
                        addTime     = item.AddTime.ToString("yyyy-MM-dd HH:mm"),
                        origin      = item.Origin
                    });
                }
            }
            dynamic re = new { total = totalCount, page = page, list = relist };

            reJson.code    = 0;
            reJson.message = "获取成功";
            reJson.detail  = re;
            return(reJson);
        }
Esempio n. 2
0
        public IActionResult GetArticleList(string keyword, int page = 1, int limit = 20)
        {
            int numPerPage, currentPage, startRowIndex;

            numPerPage    = limit;
            currentPage   = page;
            startRowIndex = (currentPage - 1) * numPerPage;
            Expression ex = Article._.Id > 0;

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                if (Utils.IsInt(keyword))
                {
                    ex &= (Article._.Id == int.Parse(keyword) | Article._.Title.Contains(keyword));
                }
                else
                {
                    ex &= Article._.Title.Contains(keyword);
                }
            }
            string kid       = Request.Query["kid"];
            string isshowsub = Request.Query["isshowsub"];

            if (Utils.IsInt(kid) && int.Parse(kid) > 0)
            {
                //获取栏目
                if (isshowsub == "1")
                {
                    List <int> kids = new List <int>();
                    kids.Add(int.Parse(kid));
                    IList <ArticleCategory> subkinds = ArticleCategory.FindByParentID(int.Parse(kid));
                    if (subkinds != null && subkinds.Count > 0)
                    {
                        foreach (var item in subkinds)
                        {
                            kids.Add(item.Id);
                        }
                        ex &= Article._.KId.In(kids);
                    }
                }
                else
                {
                    ex &= Article._.KId == int.Parse(kid);
                }
            }

            IList <Article> list       = Article.FindAll(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage);
            long            totalCount = Article.FindCount(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage);

            return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(new { total = totalCount, rows = list }), "text/plain"));
            //return Json(new { total = totalCount, rows = list }, JsonRequestBehavior.AllowGet);
        }
        public IActionResult GetArticleList(string keyword, int page = 1, int limit = 20)
        {
            int numPerPage, currentPage, startRowIndex;

            numPerPage    = limit;
            currentPage   = page;
            startRowIndex = (currentPage - 1) * numPerPage;
            Expression ex = new Expression();;

            Admin      my     = Admin.GetMyInfo();
            List <int> aclist = new List <int>();

            if (my.Roles.IsSuperAdmin != 1)
            {
                aclist = Newtonsoft.Json.JsonConvert.DeserializeObject <List <int> >(string.IsNullOrEmpty(my.Roles.AuthorizedArticleCagegory)?"[]": my.Roles.AuthorizedArticleCagegory);
                if (aclist == null)
                {
                    aclist = new List <int>();
                }
                if (aclist.Count > 0)
                {
                    ex &= Article._.KId.In(aclist);
                }

                //仅显示有权限内容
                if (my.Roles.OnlyEditMyselfArticle == 1)
                {
                    ex &= Article._.AuthorId == my.Id;
                }
            }

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                if (Utils.IsInt(keyword))
                {
                    ex &= (Article._.Id == int.Parse(keyword) | Article._.Title.Contains(keyword));
                }
                else
                {
                    ex &= Article._.Title.Contains(keyword);
                }
            }
            string kid       = Request.Query["kid"];
            string isshowsub = Request.Query["isshowsub"];

            if (Utils.IsInt(kid) && int.Parse(kid) > 0)
            {
                //获取栏目
                if (isshowsub == "1")
                {
                    List <int> kids = new List <int>();
                    kids.Add(int.Parse(kid));
                    IList <ArticleCategory> subkinds = ArticleCategory.FindByParentID(int.Parse(kid));
                    if (subkinds != null && subkinds.Count > 0)
                    {
                        foreach (var item in subkinds)
                        {
                            kids.Add(item.Id);
                        }
                        ex &= Article._.KId.In(kids);
                    }
                }
                else
                {
                    ex &= Article._.KId == int.Parse(kid);
                }
            }

            IList <Article> list       = Article.FindAll(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage);
            long            totalCount = Article.FindCount(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage);

            //return Content(Newtonsoft.Json.JsonConvert.SerializeObject(new { total = totalCount, rows = list }), "text/plain");
            return(Json(new { total = totalCount, rows = list }));
        }