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 ActionResult AllRole(string role) { List <AllRole> list = new List <AllRole>(); try { Dictionary <string, string> role_Color = StatusContext.GetColorForRole(); if (string.IsNullOrEmpty(role)) { role = "Fullpower"; //return null; } foreach (var i in this.db.RoleAccounts) { if (i.Role.ToLower().Equals(role.ToLower())) { ViewBag.RoleIDAccEdit = i.ID; ViewBag.RoleAccEdit = role; ViewBag.RoleColorClass = role_Color[i.Role]; } AllRole alr = new AllRole() { ID = i.ID, Role = i.Role, ColorClass = role_Color[i.Role] }; list.Add(alr); } } catch { return(this.PartialView(null)); } return(this.PartialView(list)); }
public JsonResult GetListAccountShort() { try { 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]"]; // search theo role string searchRoleValue = HttpContext.Request["columns[5][search][value]"]; string sortDirection = Request["order[0][dir]"]; AccountPaging apg = new AccountPaging(); apg.data = new List <AccountShort>(); start = (start - 1) * length; List <Account> listAccount = db.Accounts.ToList <Account>(); apg.recordsTotal = listAccount.Count; //filter // search theo Role if (!string.IsNullOrEmpty(searchRoleValue)) { listAccount = listAccount.Where(x => x.RoleAccount.Role.ToLower().Equals(searchRoleValue.ToLower()) ).ToList <Account>(); } // search total if (!string.IsNullOrEmpty(searchValue)) { listAccount = listAccount.Where(x => x.Username.ToLower().Contains(searchValue.ToLower()) || x.Email.ToLower().Contains(searchValue.ToLower()) || x.Fullname.ToLower().Contains(searchValue.ToLower()) || x.Phone.ToLower().Contains(searchValue.ToLower()) || x.RoleAccount.Role.ToLower().Contains(searchValue.ToLower()) ).ToList <Account>(); } //sorting if (sortColumnName.Equals("Role")) { sortColumnName = "RoleID"; } listAccount = listAccount.OrderBy(sortColumnName + " " + sortDirection).ToList <Account>(); //} apg.recordsFiltered = listAccount.Count; //paging listAccount = listAccount.Skip(start).Take(length).ToList <Account>(); Dictionary <string, string> Role_Color = StatusContext.GetColorForRole(); int count = StatusContext.Color.Count; for (int i = 0; i < listAccount.Count; i++) { AccountShort acs = new AccountShort { ID = listAccount[i].ID, Username = listAccount[i].Username, Fullname = listAccount[i].Fullname, Phone = listAccount[i].Phone, Email = listAccount[i].Email, Role = listAccount[i].RoleAccount.Role, RoleColorClass = Role_Color[listAccount[i].RoleAccount.Role], Avatar = listAccount[i].Avatar, Actions = "" }; apg.data.Add(acs); } apg.draw = int.Parse(Request["draw"]); return(Json(apg)); } catch { return(null); } }