public ValidationData ValidateGetRoomTypes( RoomTypeQueryFilter filter, RoomTypeQuerySort sort, RoomTypeQueryProjection projection, RoomTypeQueryPaging paging, RoomTypeQueryOptions options) { var validationData = new ValidationData(); return(validationData); }
public async Task <IActionResult> Get([FromQuery][QueryObject] RoomTypeQueryFilter filter, [FromQuery] RoomTypeQuerySort sort, [FromQuery] RoomTypeQueryProjection projection, [FromQuery] RoomTypeQueryPaging paging, [FromQuery] RoomTypeQueryOptions options) { var validationData = _service.ValidateGetRoomTypes( filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryRoomTypeDynamic( 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> > > QueryRoomTypeDynamic( RoomTypeQueryProjection projection, IDictionary <string, object> tempData = null, RoomTypeQueryFilter filter = null, RoomTypeQuerySort sort = null, RoomTypeQueryPaging paging = null, RoomTypeQueryOptions options = null) { var query = RoomTypes.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 || !RoomTypeQueryOptions.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 = GetRoomTypeDynamic(single, projection, options); return(new QueryResult <IDictionary <string, object> >() { SingleResult = singleResult }); } var results = GetRoomTypeDynamic(queryResult, projection, options); return(new QueryResult <IDictionary <string, object> >() { Results = results, TotalCount = totalCount }); }