public async Task <IEnumerable <SysUsersResponeModel> > GetModelsAsync(SysUsersRequestModel queryParameter, IEnumerable <string> fields = null) { using (var conn = DbContext.CreateConnection()) { var strWhere = GetQuery(queryParameter); var strFieldNames = DbContext.GetFieldsToString <SysUsersModel>("b1", fields); var dataQuery = $"SELECT b1_result.*{joinFiles} FROM (SELECT {strFieldNames} FROM {tableName} b1 WHERE 1=1 {strWhere}) b1_result {joinTable} ORDER BY b1_result.user_id ASC";//内查询,可以做连接查询 直接join return(await conn.QueryAsync <SysUsersResponeModel>(dataQuery, queryParameter)); } }
public async Task <IEnumerable <SysUsersModel> > GetCurrentModelsAsync(SysUsersRequestModel queryParameter, IEnumerable <string> fields = null) { using (var conn = DbContext.CreateConnection()) { var strWhere = GetQuery(queryParameter); var strFieldNames = DbContext.GetFieldsToString <SysUsersModel>("b1", fields); var dataQuery = $"SELECT {strFieldNames} FROM {tableName} b1 WHERE 1=1 {strWhere} ORDER BY b1.user_id ASC"; return(await conn.QueryAsync <SysUsersModel>(dataQuery, queryParameter)); } }
private string GetQuery(SysUsersRequestModel queryParameter, string table = null) { switch (table) { default: { var sb = new StringBuilder(); //如果需要模糊查询请处理参数值添加% sb.Append(DbContext.GetSqlQueryString <SysUsersModel>(queryParameter)); return(sb.ToString()); } } }
public async Task <IActionResult> Post([FromBody] SysUsersRequestModel parameter) { var apiResult = new ApiResultModel(ErrorCodeType.Success); var model = new SysUsersModel(); parameter.CloneTo(model); if (await sysUsersService.CreateAsync(model)) { return(Created($"{route}/{parameter.user_id}", apiResult)); } apiResult.Code = ErrorCodeType.PostError; return(BadRequest(apiResult)); }
public async Task <IEnumerable <SysUsersResponeModel> > GetModelsAsync(PagingModel pagingModel, SysUsersRequestModel queryParameter, IEnumerable <string> fields = null) { var strWhere = GetQuery(queryParameter); var strFieldNames = DbContext.GetFieldsToString <SysUsersModel>("b1", fields); var querySql = "SELECT {0} " + $"FROM (SELECT {strFieldNames} FROM {tableName} b1 WHERE 1=1 {strWhere} ORDER BY user_id ASC) b1_result {joinTable}";//内查询,可以做连接查询 直接join var countQuery = string.Format(querySql, "COUNT(1)"); var pagingSql = $" LIMIT {pagingModel.StartIndex()},{pagingModel.PageSize}";//分页 var dataQuery = string.Format(querySql, $"b1_result.*{joinFiles}") + pagingSql; using (var conn = DbContext.CreateConnection()) { pagingModel.TotalCount = await conn.ExecuteScalarAsync <long>(countQuery, queryParameter); return(await conn.QueryAsync <SysUsersResponeModel>(dataQuery, queryParameter)); } }
public async Task <IEnumerable <SysUsersResponeModel> > GetModelsAsync(PagingModel pagingModel, SysUsersRequestModel queryParameter, IEnumerable <string> fields = null) { return(await sysUsersRepository.GetModelsAsync(pagingModel, queryParameter, fields)); }
public async Task <IEnumerable <SysUsersModel> > GetCurrentModelsAsync(SysUsersRequestModel queryParameter, IEnumerable <string> fields = null) { return(await sysUsersRepository.GetCurrentModelsAsync(queryParameter, fields)); }
public async Task <IActionResult> Get([FromQuery] int oprator, [FromQuery] PagingModel paging, [FromQuery] SysUsersRequestModel queryParameter) { var apiResult = new ApiResultModel(ErrorCodeType.Success); switch (paging.Oprator) { case 1: { //获取不分页数据集合 apiResult.Result = await sysUsersService.GetModelsAsync(queryParameter); return(Ok(apiResult)); } case 10: { var userid = UserHttpInfo.GetValueByToken(TokenInfoType.UserId); var data = await sysUsersService.GetModelAsync(userid); data.user_pwd = string.Empty; apiResult.Result = data; return(Ok(apiResult)); } default: { var data = await sysUsersService.GetModelsAsync(paging, queryParameter); apiResult.Result = new { paging, data }; return(Ok(apiResult)); } } }