コード例 #1
0
ファイル: HomeController.cs プロジェクト: pavlove/Blog
        public ActionResult Index(string search = "", int page = 1)
        {
            string keyWord = search;

            PostsListViewModel pLVM = new PostsListViewModel();
            pLVM.Posts = (from p in db.Posts
                          let j = from t in db.Tags
                                  where t.PostId == p.PostId && t.TagValue.Contains(keyWord)
                                  select t.TagValue
                          where p.Content.Contains(keyWord) || p.Title.Contains(keyWord) || j.Count() > 0
                          select p)
                .OrderByDescending(d => d.CreateTime)
                .Skip((page - 1) * pageSize)
                .Take(pageSize);

            pLVM.PagingInfo = new PagingInfo()
            {
                CurrentPage = page,
                ItemsPerPage = pageSize,
                TotalItems = keyWord == "" ? db.Posts.Count() : (from p in db.Posts
                                                                 let j = from t in db.Tags
                                                                         where t.PostId == p.PostId && t.TagValue.Contains(keyWord)
                                                                         select t.TagValue
                                                                 where p.Content.Contains(keyWord) || p.Title.Contains(keyWord) || j.Count() > 0
                                                                 select p).Count()
            };
            pLVM.KeyWords = search;

            if (search != "")
            {
                TempData["message"] = string.Format("Znaleziono " + pLVM.PagingInfo.TotalItems.ToString() + " pozycji!");
            }
            return View(pLVM);
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: pavlove/Blog
 public ActionResult Index(int page = 1)
 {
     PostsListViewModel pLVM = new PostsListViewModel()
     {
         Posts = (from p in db.Posts select p)
         .OrderByDescending(d => d.CreateTime)
         .Skip((page - 1) * pageSize)
         .Take(pageSize),
         KeyWords = "",
         PagingInfo = new PagingInfo()
         {
             CurrentPage = page,
             ItemsPerPage = pageSize,
             TotalItems = (from p in db.Posts select p).Count()
         }
     };
     return View(pLVM);
 }