public ActionResult Index(int pageIndex = 1, int pageSize = 9) { var model = new NewsDao().ListAll(); int totalRecord = model.Count(); //Lấy 1 khoảng trong list sản phẩm từ pageIndex đến pageSize để phân trang model = model.Skip((pageIndex - 1) * pageSize) .Take(pageSize); //Đếm lấy số record thực tế ở đoạn record hiện tại int totalRowCurent = model.Count(); //Các biến để phân trang ViewBag.totalRecord = totalRecord; ViewBag.pageIndex = pageIndex; int recordStartPosition = ((pageIndex - 1) * pageSize) + 1; int recordEndPosition = ((recordStartPosition - 1 + pageSize) < totalRecord) ? (recordStartPosition - 1 + pageSize) : recordStartPosition - 1 + totalRowCurent; ViewBag.recordStartPosition = recordStartPosition; ViewBag.recordEndPosition = recordEndPosition; int maxPage = 5; int totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); if (totalRecord % pageSize > 0 && totalRecord > pageSize) { totalPage += 1; } ViewBag.First = 1; ViewBag.Last = totalPage; ViewBag.Next = pageIndex + 1; ViewBag.Prev = pageIndex - 1; ViewBag.TotalPage = totalPage; ViewBag.MaxPage = maxPage; return(View(model)); }
public JsonResult LoadLoai() { var lstLoai = new NewsDao().GetCategories(); return(Json(new { data = lstLoai, total = lstLoai.Count() }, JsonRequestBehavior.AllowGet)); }
public JsonResult LoadData(int type, string keyword, bool status, int pageIndex, int pageSize) { string str = NonUnicode.RemoveUnicode(keyword).ToLower(); var model = new NewsDao().ListAll(); switch (type) { case 0: model = model.Where( x => NonUnicode.RemoveUnicode(x.Name).ToLower().Contains(str) || NonUnicode.RemoveUnicode(x.NewsCategoryName).ToLower().Contains(str) || NonUnicode.RemoveUnicode(x.Tag).ToLower().Contains(str) ); break; case 1: model = model.Where(x => NonUnicode.RemoveUnicode(x.Name).ToLower().Contains(str)); break; case 2: model = model.Where(x => NonUnicode.RemoveUnicode(x.NewsCategoryName).ToLower().Contains(str)); break; case 3: model = model.Where(x => NonUnicode.RemoveUnicode(x.Tag).ToLower().Contains(str)); break; } if (status) { model = model.Where(x => x.Status == true); } else { model = model.Where(x => x.Status == false); } int totalRow = model.Count(); model = model.OrderByDescending(x => x.ID) .Skip((pageIndex - 1) * pageSize) .Take(pageSize); int totalRowCurent = model.Count(); return(Json(new { data = model, total = totalRow, totalCurent = totalRowCurent, status = true }, JsonRequestBehavior.AllowGet)); }
public JsonResult LoadData(string model, int page = 1, int pageSize = 2) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var filterDTO = serializer.Deserialize <FilterDTO>(model); var newsDTOs = new NewsDao().FilterNews(filterDTO).Skip((page - 1) * pageSize).Take(pageSize).ToList(); int totalRow = newsDTOs.Count(); return(Json(new { data = newsDTOs, total = totalRow }, JsonRequestBehavior.AllowGet)); }
public int NewsCount(bool withDeleted = true) => _news.Count(withDeleted);