public ActionResult Index(int page = 1, int itemsperpage = 10, bool showInactive = false, string srchParam = "") { if (TempData["msg"] != null) { ViewBag.msg = TempData["msg"].ToString(); TempData["msg"] = null; } try { ViewBag.srchParam = srchParam; ViewBag.showInactive = showInactive; int currentPageIndex = page - 1 < 0 ? 0 : page - 1; int take = itemsperpage; int skip = currentPageIndex * take; var query = new QueryShift{ Skip = skip, Take = take, Name = srchParam, ShowInactive = showInactive }; var ls = _shiftRepository.Query(query); var total = ls.Count; var data = ls.Data.ToList(); return View(data.ToPagedList(currentPageIndex, take, total)); ; } catch (Exception ex) { TempData["msg"] = "Error loading page\nDetails:" + ex.Message; } return View(); }
protected override void Load(bool isFirstLoad = false) { Application.Current.Dispatcher.BeginInvoke( new Action( delegate { //if (isFirstLoad) using (var c = NestedContainer) { var query = new QueryShift(); query.Take = ItemsPerPage; query.Skip = ItemsPerPage * (CurrentPage - 1); query.ShowInactive = ShowInactive; if (!string.IsNullOrWhiteSpace(SearchText)) query.Name = SearchText; var rawList = Using<IShiftRepository>(c).Query(query); _pagedCommodityProducerService = new PagenatedList<Shift>(rawList.Data.OfType<Shift>().AsQueryable(), CurrentPage, ItemsPerPage, rawList.Count, true); ListOfShifts.Clear(); int rownumber = 0; _pagedCommodityProducerService.ToList().ForEach(n => ListOfShifts.Add(new VmShift { Id = n.Id, Code = n.Code, Name = n.Name, StartTime=n.StartTime, EndTime=n.EndTime, Status = n._Status, Action = n._Status == EntityStatus.Active ? "Deactivate" : "Activate", RowNumber = ++rownumber })); UpdatePagenationControl(); } })); }
public ActionResult Index(int page = 1, int itemsperpage = 10, bool showInactive = false, string srchParam = "", string srch = "") { try { string command = srch; bool showinactive = false; if (showInactive != null) showinactive = (bool)showInactive; ViewBag.showInactive = showinactive; if (TempData["msg"] != null) { ViewBag.msg = TempData["msg"].ToString(); TempData["msg"] = null; } if (srch == "Search") { ViewBag.showInactive = showInactive; int currentPageIndex = page - 1 < 0 ? 0 : page - 1; int take = itemsperpage; int skip = currentPageIndex * take; var query = new QueryShift { Skip = skip, Take = take, Name = srchParam, ShowInactive = showInactive }; var result = _shiftRepository.Query(query); var item = result.Data.Cast<Shift>().ToList(); int total = result.Count; var data = item.ToPagedList(currentPageIndex, take, total); return View(data); } return RedirectToAction("Index", new { showInactive = showInactive, srch = "Search", srchParam = "" }); } catch (Exception ex) { ViewBag.msg = ex.Message; return View(); } }