public ValidationData ValidateGetDepartments( DepartmentQueryFilter filter, DepartmentQuerySort sort, DepartmentQueryProjection projection, DepartmentQueryPaging paging, DepartmentQueryOptions options) { var validationData = new ValidationData(); return(validationData); }
public async Task <IActionResult> Get([FromQuery][QueryObject] DepartmentQueryFilter filter, [FromQuery] DepartmentQuerySort sort, [FromQuery] Business.Models.DepartmentQueryProjection projection, [FromQuery] DepartmentQueryPaging paging, [FromQuery] DepartmentQueryOptions options) { var validationData = _service.ValidateGetDepartments( filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryDepartmentDynamic( projection, validationData.TempData, filter, sort, paging, options); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(data: result))); }
public async Task <QueryResult <IDictionary <string, object> > > QueryDepartmentDynamic( DepartmentQueryProjection projection, IDictionary <string, object> tempData = null, DepartmentQueryFilter filter = null, DepartmentQuerySort sort = null, DepartmentQueryPaging paging = null, DepartmentQueryOptions options = null) { var query = Departments.AsNoTracking(); if (filter != null) { query = query.Filter(filter, tempData); } int?totalCount = null; Task <int> countTask = null; var countQuery = query; query = query.Project(projection); if (options != null && !options.single_only) { #region List query if (sort != null) { query = query.Sort(sort); } if (paging != null && (!options.load_all || !DepartmentQueryOptions.IsLoadAllAllowed)) { query = query.SelectPage(paging.page, paging.limit); } #endregion #region Count query if (options.count_total) { countTask = countQuery.CountAsync(); } #endregion } if (options != null && options.count_total) { totalCount = await countTask; } var queryResult = await query.ToListAsync(); if (options != null && options.single_only) { var single = queryResult.FirstOrDefault(); if (single == null) { return(null); } var singleResult = GetDepartmentDynamic(single, projection, options); return(new QueryResult <IDictionary <string, object> >() { SingleResult = singleResult }); } var results = GetDepartmentDynamic(queryResult, projection, options); return(new QueryResult <IDictionary <string, object> >() { Results = results, TotalCount = totalCount }); }