public ActionResult CashBackDetail() { var allCashback = CashbackService.GetCashbackView(); ViewBag.allCashback = allCashback; var allLinkSite = Linked_SiteService.GetAllLinked_Site(); ViewBag.allLinkSite = allLinkSite; return(View()); }
public ActionResult AjaxHandler(JQueryDataTableParamModel param) { var allCashback = CashbackService.GetCashbackView(); IEnumerable <CashbackModel> filteredCashback; //Check whether the Cashback should be filtered by keyword if (!string.IsNullOrEmpty(param.sSearch)) { //Used if particulare columns are filtered var nameFilter = Convert.ToString(Request["sSearch_1"]); var addressFilter = Convert.ToString(Request["sSearch_2"]); var townFilter = Convert.ToString(Request["sSearch_3"]); //Optionally check whether the columns are searchable at all var isNameSearchable = Convert.ToBoolean(Request["bSearchable_1"]); var isAddressSearchable = Convert.ToBoolean(Request["bSearchable_2"]); var isTownSearchable = Convert.ToBoolean(Request["bSearchable_3"]); filteredCashback = CashbackService.GetCashbackView() .Where(c => isNameSearchable && (c.SiteName.ToLower().Contains(param.sSearch.ToLower()) || c.CategoriesName.ToLower().Contains(param.sSearch.ToLower()) || c.Value.Equals(param.sSearch.ToLower()))); } else { filteredCashback = allCashback; } var isNameSortable = Convert.ToBoolean(Request["bSortable_1"]); var isAddressSortable = Convert.ToBoolean(Request["bSortable_2"]); var isTownSortable = Convert.ToBoolean(Request["bSortable_3"]); var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]); Func <CashbackModel, string> orderingFunction = (c => sortColumnIndex == 1 && isNameSortable ? c.Id.ToString() : sortColumnIndex == 2 && isAddressSortable ? c.SiteName.ToString() : sortColumnIndex == 4 && isAddressSortable ? c.CategoriesName.ToString() : sortColumnIndex == 5 && isAddressSortable ? c.Value.ToString() : sortColumnIndex == 6 && isTownSortable ? c.CreateDate.ToString() : sortColumnIndex == 7 && isTownSortable ? c.Flag.ToString() : ""); var sortDirection = Request["sSortDir_0"]; // asc or desc if (sortDirection == "asc") { filteredCashback = filteredCashback.OrderBy(orderingFunction); } else { filteredCashback = filteredCashback.OrderByDescending(orderingFunction); } var displayedCashback = filteredCashback.Skip(param.iDisplayStart).Take(param.iDisplayLength); var result = from c in displayedCashback select new[] { Convert.ToString(c.Id), c.SiteName, c.CategoriesName, Convert.ToString(c.Value), Convert.ToString(c.CreateDate), Convert.ToString(c.Flag) }; return(Json(new { sEcho = param.sEcho, iTotalRecords = allCashback.Count(), iTotalDisplayRecords = filteredCashback.Count(), aaData = result }, JsonRequestBehavior.AllowGet)); }