public static GridModel GetGridModel(PagerArgs args, string DefaultSortKey) { var gm = new GridModel { Pager = new GridPager { Pages = new List <GridPage>() } }; if (string.IsNullOrWhiteSpace(args.CurrentPage)) { gm.Pager.CurrentPage = 1; } else { gm.Pager.CurrentPage = args.CurrentPage.IntParse(); } if (string.IsNullOrWhiteSpace(args.PageSize)) { gm.Pager.PageSize = 12; } else { gm.Pager.PageSize = args.PageSize.IntParse(); } if (string.IsNullOrWhiteSpace(args.PagerCount)) { gm.Pager.PagerCount = 5; } else { gm.Pager.PagerCount = args.PagerCount.IntParse(); } if (string.IsNullOrWhiteSpace(args.SortKey)) { gm.SortKey = DefaultSortKey; } else { gm.SortKey = args.SortKey; } if (string.IsNullOrWhiteSpace(args.SortDirection)) { gm.SortDirection = "DESC"; } else { gm.SortDirection = args.SortDirection; } return(gm); }
public static PagerData ApplyArgs <T>(this PagerArgs Args, IQueryable <T> candidates) { Args.RecordCount = candidates.Count(); candidates = candidates.Skip(Args.PageIndex * Args.PageSize).Take(Args.PageSize); PagerData data = new PagerData(); data.PagerArgs = Args; try { data.Data = candidates.ToList(); } catch (Exception e) { throw new Exception(e.Message); } return(data); }
public PagerArgs GetPagerArgs() { var x = new PagerArgs(Convert.ToInt32(this.RecordCount), Convert.ToInt32(this.CurrentPage), this.PageSize); return(x); }