Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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);
 }