public async Task <IActionResult> Get([FromQuery] EntityCategoryQueryFilter filter, [FromQuery] EntityCategoryQuerySort sort, [FromQuery] EntityCategoryQueryProjection projection, [FromQuery] EntityCategoryQueryPaging paging, [FromQuery] EntityCategoryQueryOptions options) { var validationResult = _service.ValidateGetEntityCategories( User, filter, sort, projection, paging, options); if (!validationResult.Valid) { return(BadRequest(validationResult.Result)); } var result = await _service.QueryEntityCategoryDynamic( projection, options, filter, sort, paging); if (options.single_only) { if (result == null) { return(NotFound(new AppResultBuilder().NotFound())); } return(Ok(new AppResultBuilder().Success(result.SingleResult))); } return(Ok(new AppResultBuilder().Success(result))); }
public ValidationResult ValidateGetEntityCategories( ClaimsPrincipal principal, EntityCategoryQueryFilter filter, EntityCategoryQuerySort sort, EntityCategoryQueryProjection projection, EntityCategoryQueryPaging paging, EntityCategoryQueryOptions options) { return(ValidationResult.Pass()); }
public async Task <QueryResult <EntityCategoryQueryRow> > QueryEntityCategory( EntityCategoryQueryFilter filter = null, EntityCategoryQuerySort sort = null, EntityCategoryQueryProjection projection = null, EntityCategoryQueryPaging paging = null, EntityCategoryQueryOptions options = null) { var conn = context.Database.GetDbConnection(); var openConn = conn.OpenAsync(); var query = EntityCategoryQuery.CreateDynamicSql(); #region General if (filter != null) { query = query.SqlFilter(filter); } if (projection != null) { query = query.SqlJoin(projection, filter); } DynamicSql countQuery = null; int?totalCount = null; Task <int> countTask = null; if (options != null && options.count_total) { countQuery = query.SqlCount("*"); } if (projection != null) { query = query.SqlProjectFields(projection); } #endregion await openConn; if (options != null && !options.single_only) { #region List query if (sort != null) { query = query.SqlSort(sort); } if (paging != null && (!options.load_all || !EntityCategoryQueryOptions.IsLoadAllAllowed)) { query = query.SqlSelectPage(paging.page, paging.limit); } #endregion #region Count query if (options.count_total) { countTask = conn.ExecuteScalarAsync <int>( sql: countQuery.PreparedForm, param: countQuery.DynamicParameters); } #endregion } if (projection != null) { query = query.SqlExtras(projection, filter); } var multipleResult = await conn.QueryMultipleAsync( sql : query.PreparedForm, param : query.DynamicParameters); using (multipleResult) { var queryResult = multipleResult.Read( types: query.GetTypesArr(), map: (objs) => ProcessMultiResults(query, objs), splitOn: string.Join(',', query.GetSplitOns())); if (projection != null) { var extraKeys = projection.GetFieldsArr() .Where(f => EntityCategoryQueryProjection.Extras.ContainsKey(f)); IEnumerable <CateOfResQueryRow> resources = null; foreach (var key in extraKeys) { switch (key) { case EntityCategoryQueryProjection.RESOURCES: resources = GetCategoriesQueryResult(multipleResult); break; } } ProcessExtras(queryResult, resources); } if (options != null && options.single_only) { var single = queryResult.FirstOrDefault(); if (single == null) { return(null); } return(new QueryResult <EntityCategoryQueryRow> { SingleResult = single }); } if (options != null && options.count_total) { totalCount = await countTask; } return(new QueryResult <EntityCategoryQueryRow> { Results = queryResult, TotalCount = totalCount }); } }