public JsonResult GetKeyData(PagingOptions options, Int32 range) { //paging parameter var start = options.Start; var length = options.Length; //sorting parameter var sortColumn = options.ColumnName; var sortColumnDir = options.Direction ? "descending" : "ascending"; //filter parameter var searchValue = options.SearchName; int pageSize = length; int skip = start; int recordsTotal = 0; var allKeyword = new List <Keyword>(); DateTime enddate = DateTime.Today.AddDays(-3); DateTime startdate = enddate; GetStartDate(range, ref startdate); switch (range) { case 0: allKeyword = dashboardData.GetKeywordData(SessionData.UserID); break; default: allKeyword = dashboardData.GetCustKeywordData(SessionData.UserID, startdate, enddate); break; } //Database query var v = from a in allKeyword select a; if (!string.IsNullOrEmpty(searchValue)) { v = v.Where(a => a.KeywordName.ToLower().Contains(searchValue.ToLower()) ); } //sort if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir))) { if (options.IsIgnoreZero) { v = SkipZeroKeywords(sortColumn, v); } //for make sort simpler we will add Syste.Linq.Dynamic reference v = v.OrderBy(sortColumn + " " + sortColumnDir); } recordsTotal = v.Count(); allKeyword = v.Skip(skip).Take(pageSize).ToList(); return(Json(new { recordsTotal = recordsTotal, data = allKeyword })); }