public IHttpActionResult RoleList(roleparm parm) { try { int recordcount = 0; RoleService rs = new RoleService(); var list = rs.List(parm, out recordcount); return(Json(new { code = 1, msg = "ok", list = list, recordcount = recordcount })); } catch (Exception e) { return(Json(new { code = 0, msg = e.Message })); } }
public IEnumerable <sys_role> List(roleparm parm, out int recordcount) { recordcount = 0; using (LocalDB db = new LocalDB()) { StringBuilder sql = new StringBuilder(); DynamicParameters p = new DynamicParameters(); sql.Append("select * from sys_role where 1=1 \n"); if (!string.IsNullOrEmpty(parm.key)) { sql.Append(" and title like @key "); p.Add("key", "%" + parm.key + "%"); } if (!string.IsNullOrEmpty(parm.code)) { sql.Append(" and code like @code "); p.Add("code", "%" + parm.code + "%"); } var list = db.Current_Conn.Query <sys_role>(sql.ToString(), p).OrderByDescending(t => t.id).ToPagedList(parm.pageindex, parm.pagesize); recordcount = list.TotalItemCount; return(list); } }