示例#1
0
        public IActionResult Index(int id = 0, int page = 1)
        {
            ArticleCategory model = ArticleCategory.FindById(id);

            if (model == null)
            {
                return(AlertAndGoBack("系统找不到本记录"));
            }
            //如果跳转到地址
            if (!string.IsNullOrEmpty(model.LinkURL))
            {
                if (Utils.IsInt(model.LinkURL))//如果是数字,则跳转到详情
                {
                    //return Redirect($"/Article/Detail/{model.LinkURL}");
                    string linkUrl = ViewsHelper.EchoArticleURL(int.Parse(model.LinkURL));
                    return(Redirect(linkUrl));
                }
                else
                {
                    return(Redirect(model.LinkURL));
                }
            }
            if (page < 1)
            {
                page = 1;
            }

            if (model.IsList == 1)
            {
                IList <Article> list = new List <Article>();
                int             numPerPage, currentPage, startRowIndex;
                numPerPage = model.PageSize;
                if (page > 0)
                {
                    currentPage = page;
                }
                else
                {
                    currentPage = 1;
                }

                startRowIndex = (currentPage - 1) * numPerPage;

                var ex = Article._.IsHide != 1 & Article._.IsDel != 1;

                //如果显示下级栏目文章
                if (model.IsShowSubDetail == 1)
                {
                    //获取下级所有栏目
                    List <int> allsubkids = new List <int>();
                    allsubkids.Add(model.Id);

                    IList <ArticleCategory> allkind = ArticleCategory.FindAllSubKinds(model.Id);
                    if (allkind != null && allkind.Count > 0)
                    {
                        foreach (var s in allkind)
                        {
                            allsubkids.Add(s.Id);
                        }
                    }
                    ex &= Article._.KId.In(allsubkids);
                }
                else
                {
                    ex &= Article._.KId == model.Id;
                }
                long totalCount = Article.FindCount(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage);
                int  pageCount  = (int)totalCount / numPerPage;//总页数
                if (totalCount % numPerPage > 0)
                {
                    pageCount += 1;
                }
                list         = Article.FindAll(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage);
                ViewBag.list = list;//列表
                //分页信息
                ViewBag.totalCount = totalCount;
                ViewBag.pageCount  = pageCount;
                ViewBag.page       = page;
                ViewBag.pagesize   = numPerPage;
            }

            ViewBag.cfg = cfg;
            string templatesname = "Index.cshtml";//模板名称

            if (!string.IsNullOrEmpty(model.TemplateFile))
            {
                templatesname = model.TemplateFile;
                //return Content(templatesname);
            }
            return(View("~/Views/Article/" + templatesname, model)); //固定死就是这个
        }