public JsonResult GetAdminRoles() { string LoginUser = (string)Session["LoginSAPID"]; try { string userkey = ConfigurationManager.AppSettings["userkey"]; string uid = ConfigurationManager.AppSettings["uid"]; Employer.Employer employer = new Employer.Employer(); DataTable dt = employer.FetchAllRoles(); dt.TableName = "FetchRoles"; var roles = (from DataRow dr in dt.Rows where dr["isexternal"].ToString().Trim() != "Y" select new Models.UserRoles() { ID = dr["ID"].ToString(), Name = dr["Name"].ToString(), Code = dr["Code"].ToString() }).ToList(); return(Json(new { data = roles }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogError logerror = new LogError(); logerror.ErrorLog("", LoginUser, "", "Admin/GetRoles", "Admin", "GetRoles", "FetchAllRoles Error", ex.Message.ToString(), 0); return(Json(new { data = "Error has occured" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetAllRoles([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel) { string userkey = ConfigurationManager.AppSettings["userkey"]; string uid = ConfigurationManager.AppSettings["uid"]; string LoginUser = (string)Session["LoginSAPID"]; try { Employer.Employer employer = new Employer.Employer(); DataTable dt = employer.FetchAllRoles(); dt.TableName = "Roles"; List <UserRoles> roles = new List <UserRoles>(); int startRec = requestModel.Start; int pageSize = requestModel.Length; List <UserRoles> roleCount = (from DataRow dr in dt.Rows select new UserRoles() { ID = dr["ID"].ToString() }).ToList(); roles = (from DataRow dr in dt.Rows select new UserRoles() { ID = dr["ID"].ToString(), Name = dr["NAME"].ToString(), Code = dr["CODE"].ToString(), }).Skip(startRec).Take(pageSize).ToList(); var totalCount = roleCount.Count(); var filteredCount = roleCount.Count(); var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; foreach (var column in sortedColumns) { orderByString += orderByString != String.Empty ? "," : ""; orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc"); } var data = roles.Select(emList => new { ID = emList.ID, Name = emList.Name, Code = emList.Code }).ToList(); return(Json(new DataTablesResponse(requestModel.Draw, data, totalCount, totalCount), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogError logerror = new LogError(); logerror.ErrorLog("", LoginUser, "", "AdminViewsController/GetAllRoles", "AdminViewsController", "GetAllRoles", "FetchAllRoles Error", ex.Message.ToString(), 0); throw new Exception(ex.Message.ToString()); } }