public async Task <ActionResult> Details(int?id) { if (id.HasValue) { try { var customer = await _customerRepo.Get(id.Value); if (customer == null) { return(HttpNotFound()); } model.inputModel = customer; } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return(View(model)); } return(HttpNotFound()); }
public IActionResult GetData(JqueryDatatableParam param) { var Customers = repo.Get().data; if (!string.IsNullOrEmpty(param.sSearch)) { Customers = Customers.Where( x => x.CustomerName.ToLower().Contains(param.sSearch.ToLower()) || x.CustomerNumber.ToLower().Contains(param.sSearch.ToLower()) || x.CustomerAddress.ToLower().Contains(param.sSearch.ToLower()) || x.Phone.ToLower().Contains(param.sSearch.ToLower()) || x.Resident.ResidentName.ToLower().Contains(param.sSearch.ToLower()) ).ToList(); } var sortColumnIndex = Convert.ToInt32(HttpContext.Request.Query["iSortCol_0"]); var sortDirection = HttpContext.Request.Query["sSortDir_0"]; Func <CustomerViewModel, string> orderingFunction = e => sortColumnIndex == 5 ? e.Resident.ResidentName: sortColumnIndex == 4 ? e.Phone : sortColumnIndex == 3 ? e.CustomerAddress : sortColumnIndex == 2 ? e.CustomerNumber : sortColumnIndex == 1 ? e.CustomerName : e.CustomerID.ToString(); Customers = sortDirection == "asc" ? Customers.OrderBy(orderingFunction).ToList() : Customers.OrderByDescending(orderingFunction).ToList(); var displayResult = Customers.Skip(param.iDisplayStart) .Take(param.iDisplayLength).ToList(); var totalRecords = Customers.Count(); return(Json(new { param.sEcho, iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords, Data = displayResult })); }