public JsonResult GetAllRole() { try { /*db.Configuration.ProxyCreationEnabled = false;*/ int length = int.Parse(HttpContext.Request["length"]); int start = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(int.Parse(Request["start"]) / length))) + 1; string searchValue = HttpContext.Request["search[value]"]; string sortColumnName = HttpContext.Request["columns[" + Request["order[0][column]"] + "][name]"]; string sortDirection = Request["order[0][dir]"]; /*int length = 10; * int start = 1; * string searchValue = ""; * string sortColumnName = "ID"; * string sortDirection = "asc";*/ RolePaging apg = new RolePaging(); apg.data = new List <RoleModel>(); start = (start - 1) * length; List <RoleAccount> listRole = this.db.RoleAccounts.ToList <RoleAccount>(); Dictionary <string, string> role_Color = StatusContext.GetColorForRole(); apg.recordsTotal = listRole.Count; //filter if (!string.IsNullOrEmpty(searchValue)) { listRole = listRole.Where(x => x.Role.ToLower().Contains(searchValue.ToLower())).ToList <RoleAccount>(); } //sorting if (sortColumnName.Equals("Role")) { //sort UTF 8 sortColumnName = "ID"; } listRole = listRole.OrderBy(sortColumnName + " " + sortDirection).ToList <RoleAccount>(); apg.recordsFiltered = listRole.Count; //paging listRole = listRole.Skip(start).Take(length).ToList <RoleAccount>(); foreach (var i in listRole) { apg.data.Add(new RoleModel(i, role_Color[i.Role])); } apg.draw = int.Parse(this.Request["draw"]); return(this.Json(apg)); /*return Json(apg, JsonRequestBehavior.AllowGet);*/ } catch { return(null); } }
public JsonResult GetAllRole() { try { /*db.Configuration.ProxyCreationEnabled = false;*/ int length = int.Parse(Request.Query["length"]); int start = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(int.Parse(Request.Query["start"]) / length))) + 1; string searchValue = Request.Query["search[value]"]; string sortColumnName = Request.Query["columns[" + Request.Query["order[0][column]"] + "][name]"]; string sortDirection = Request.Query["order[0][dir]"]; /*int length = 10; * int start = 1; * string searchValue = ""; * string sortColumnName = "ID"; * string sortDirection = "asc";*/ RolePaging apg = new RolePaging(); apg.data = new List <RoleModel>(); start = (start - 1) * length; List <Role> listRole = _context.Roles.ToList <Role>(); apg.recordsTotal = listRole.Count; //filter if (!string.IsNullOrEmpty(searchValue)) { listRole = listRole.Where(x => x.RoleName.ToLower().Contains(searchValue.ToLower())).ToList <Role>(); } //sorting /*if (sortDirection == "asc") * { * listRole = listRole.OrderBy(x => x.GetType().GetProperty(sortColumnName).GetValue(x)).ToList<Role>(); * } * else * { * listRole = listRole.OrderByDescending(x => x.GetType().GetProperty(sortColumnName).GetValue(x)).ToList<Role>(); * }*/ apg.recordsFiltered = listRole.Count; //paging listRole = listRole.Skip(start).Take(length).ToList <Role>(); foreach (var i in listRole) { RoleModel rm = new RoleModel { RoleName = i.RoleName, Description = i.Description, Actions = "" }; apg.data.Add(rm); } apg.draw = int.Parse(Request.Query["draw"]); return(Json(apg)); /*return Json(apg, JsonRequestBehavior.AllowGet);*/ } catch (Exception ex) { return(null); } }