Web/Controllers/HomeController.cs

(完整代码) 2KB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using Doc.Model;
using Doc.Utility;

namespace Web.Controllers
{
    public class HomeController : Controller
    {
        Doc.DAL.DocContext db = new Doc.DAL.DocContext();
        // GET: Home
        public ActionResult Index(string keyword,int? projectid,int? page)
        {

            //获取项目列表
            var projectList = db.Project.OrderByDescending(m => m.id).ToList();
            ViewBag.projectList = projectList;

            Doc.Utility.PagingHtml pagehtml = new PagingHtml();
         
            Expression<Func<Doc.Model.ApiMethod, bool>> expression = PredicateExtensions.True<Doc.Model.ApiMethod>();
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                expression = expression.And(m => m.Name.Contains(keyword) || m.RequestUrl.Contains(keyword));
                ViewBag.keyword = keyword;
                pagehtml.pageWhere.Append("&keyword=" + keyword);

            }
            if (projectid != null)
            {
                expression = expression.And(m => m.ProjectId==projectid);
                ViewBag.projectid = projectid;
                pagehtml.pageWhere.Append("&projectid=" + projectid);
            }
            int total = 0;
            List<SortCondition<Doc.Model.ApiMethod>> sortlist = new List<SortCondition<ApiMethod>>
            {
                new SortCondition<ApiMethod>(m => m.id, ListSortDirection.Descending)
            };
            var list = new Doc.Service.ApiMethod().Page(page.ToInt32(),20,out total,expression, sortlist);

           
            pagehtml.Count = total;
            pagehtml.pageNum = 11;
            pagehtml.pageSize =20;
            pagehtml.pageIndex = page.ToInt32()==0?1 : page.ToInt32();
            ViewBag.pagehtml = pagehtml.CreatePageList();
            return View(list.ToList());
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。