Example #1
0
        public ActionResult FunNewsDetail(int id)
        {
            var nn = GetNewsDetails(id);

            ViewData.Model = nn;
            //-----相关推荐
            ViewData["recTopSixFunNews"] = NewsBll.GetRelatedFunNews(id, 6, "0");
            #region  一篇、下一篇
            //-上一篇、下一篇
            //用pre和next变量分别存放上一篇文章和下一篇文章的id号
            int pre = 0, next = 0, i = 0, j;
            //计算总记录数
            int   num   = NewsBll.LoadEntities(n => true).Count();
            int[] a     = new int[num];
            var   query = NewsBll.LoadEntities(n => true).Select(n => n.Id).ToArray();
            //将所有的文章id号全部放入一个数组中
            foreach (var item in query)
            {
                a[i] = Convert.ToInt32(item);
                i++;
            }
            //循环,获取上一篇和下一篇文章的ID号,分别放入变量pre和next中
            for (j = 0; j < num; j++)
            {
                if (a[j] == id)
                {
                    if (j != 0)
                    {
                        pre = a[j - 1];         //上一篇id
                    }
                    if (j != num - 1)
                    {
                        next = a[j + 1];               //下一篇文章id
                    }
                }
            }
            //获取上一篇文章的标题
            if (pre == 0)
            {
                ViewBag.preTitle = "没有了";
                ViewBag.pre      = id;
            }
            else
            {
                string edtitTitle = NewsBll.LoadEntities(n => n.Id == pre).Single().EditTitle;
                //拿了原标题
                if (edtitTitle != null)
                {
                    ViewBag.preTitle = edtitTitle;
                }
                else
                {
                    ViewBag.preTitle = NewsBll.LoadEntities(n => n.Id == pre).Single().Title;
                }
                ViewBag.pre = pre;
            }
            //获取下一篇文章的标题
            if (next == 0)
            {
                ViewBag.nextTitle = "没有了";
                ViewBag.next      = id;
            }
            else
            {
                string edtitTitle = NewsBll.LoadEntities(n => n.Id == next).Single().EditTitle;
                //拿了原标题
                if (edtitTitle != null)
                {
                    ViewBag.nextTitle = edtitTitle;
                }
                else
                {
                    ViewBag.nextTitle = NewsBll.LoadEntities(n => n.Id == next).Single().Title;
                }
                ViewBag.next = next;
            }
            #endregion
            return(View());
        }