public PagingResult <Role, RoleDTO> Search(SearchCriterias criterias, string name, bool tracking = false) { var skip = criterias.iDisplayStart; if (skip == null) { skip = (criterias.pageNumber.Value >= criterias.iDisplayLength) ? criterias.pageNumber.Value : criterias.pageNumber.Value * criterias.iDisplayLength; } var query = base.Query(); var total = query.Select(r => r.Id).LongCount(); if (!string.IsNullOrWhiteSpace(name)) { query = query.Where(r => r.Name.Contains(name)); } foreach (var sort in criterias.sortings) { query = query.OrderBy(string.Concat(sort.sort, " ", sort.dir)); } var totalDisplay = query.LongCount(); query = query.Include(r => r.Modules).Skip(skip.Value).Take(criterias.iDisplayLength); if (!tracking) { query = query.AsNoTracking(); } var pageCount = (int)Math.Ceiling(totalDisplay / (double)criterias.iDisplayLength); return(new PagingResult <Role, RoleDTO> { Total = total, PageNumber = criterias.pageNumber ?? 0, TotalDisplay = totalDisplay, PageCount = pageCount, PageOfResults = query }); }
public JsonResult Roles(SearchCriterias criterias, string name) { var manager = this.GetManagerFor <IRoleManager>(); var result = manager.Search(criterias, name); var resultDTOs = result.PageOfResults.Select(t => new RoleDTO(new Query[] { new Query { Name = "Modules" } }, t)); return(Json(new PagingResult <Role, RoleDTO> { Total = result.Total, TotalDisplay = result.TotalDisplay, PageNumber = result.PageNumber, PageCount = result.PageCount, PageOfDTOs = resultDTOs })); }
public async Task <JsonResult> List(SearchCriterias criterias, string name) { var result = await this.PostAsync <PagingResult <Role, RoleDTO> >(this.GetAPIAddress("/api/console/Role/Roles"), new { criterias = criterias, name = name }); return(Json(new { aaData = result.PageOfDTOs.Select(r => new { Id = r.Id, Name = r.Name, Modules = r.Modules.Select(m => new { Name = m.Name }) }), iTotalDisplayRecords = result.TotalDisplay, iTotalRecords = result.Total, //sEcho= "3" })); }
public List <BOL.roles> Select(BOL.roles obj, SearchCriterias criteria) { if (obj != null) { DataSet ds = new DataSet(); conn = new MySqlConnection(ConnectionString); conn.Open(); trans = conn.BeginTransaction(); if (criteria.GetHashCode() == SearchCriterias.multiple.GetHashCode()) { ds = bll_roles.Select(obj, conn, trans); } if (criteria.GetHashCode() == SearchCriterias.all.GetHashCode()) { ds = bll_roles.SelectAll(obj, conn, trans); } trans.Commit(); conn.Close(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { List <BOL.roles> roles = new List <BOL.roles>(); foreach (DataRow dr in ds.Tables[0].Rows) { BOL.roles c = new BOL.roles(); if (dr["Roleid"] != DBNull.Value && Convert.ToInt32(dr["Roleid"]) > 0) { c.Roleid = Convert.ToInt32(Convert.ToString(dr["Roleid"])); } if (dr["Rolename"] != DBNull.Value && !string.IsNullOrEmpty(Convert.ToString(dr["Rolename"]))) { c.Rolename = Convert.ToString(dr["Rolename"]); } if (dr["Description"] != DBNull.Value && !string.IsNullOrEmpty(Convert.ToString(dr["Description"]))) { c.Description = Convert.ToString(dr["Description"]); } if (dr["Createdby"] != DBNull.Value && Convert.ToInt32(dr["Createdby"]) > 0) { c.Createdby = Convert.ToInt32(Convert.ToString(dr["Createdby"])); } if (dr["Createdon"] != DBNull.Value && !string.IsNullOrEmpty(Convert.ToString(dr["Createdon"]))) { c.Createdon = Convert.ToDateTime(Convert.ToString(dr["Createdon"])); } if (dr["Isdeleted"] != DBNull.Value && !string.IsNullOrEmpty(Convert.ToString(dr["Isdeleted"]))) { c.Isdeleted = Convert.ToString(dr["Isdeleted"]); } if (dr["Modifiedby"] != DBNull.Value && Convert.ToInt32(dr["Modifiedby"]) > 0) { c.Modifiedby = Convert.ToInt32(Convert.ToString(dr["Modifiedby"])); } if (dr["Modifiedon"] != DBNull.Value && !string.IsNullOrEmpty(Convert.ToString(dr["Modifiedon"]))) { c.Modifiedon = Convert.ToDateTime(Convert.ToString(dr["Modifiedon"])); } roles.Add(c); } return(roles); } return(null); } return(null); }