public async Task <QueryResult <IDictionary <string, object> > > QueryAppConfigDynamic(
            AppConfigQueryProjection projection,
            AppConfigQueryOptions options,
            AppConfigQueryFilter filter = null,
            AppConfigQuerySort sort     = null,
            AppConfigQueryPaging paging = null)
        {
            var query = AppConfigs;

            #region General
            if (filter != null)
            {
                query = query.Filter(filter);
            }
            query = query.Project(projection);
            int?totalCount = null;
            if (options.count_total)
            {
                totalCount = query.Count();
            }
            #endregion
            if (!options.single_only)
            {
                #region List query
                if (sort != null)
                {
                    query = query.Sort(sort);
                }
                if (paging != null && (!options.load_all || !AppConfigQueryOptions.IsLoadAllAllowed))
                {
                    query = query.SelectPage(paging.page, paging.limit);
                }
                #endregion
            }

            if (options.single_only)
            {
                var single = query.SingleOrDefault();
                if (single == null)
                {
                    return(null);
                }
                var singleResult = GetAppConfigDynamic(single, projection, options);
                return(new QueryResult <IDictionary <string, object> >()
                {
                    Single = singleResult
                });
            }
            var entities = query.ToList();
            var list     = GetAppConfigDynamic(entities, projection, options);
            var result   = new QueryResult <IDictionary <string, object> >();
            result.List = list;
            if (options.count_total)
            {
                result.Count = totalCount;
            }
            return(result);
        }
 public ValidationData ValidateGetAppConfigs(
     ClaimsPrincipal principal,
     AppConfigQueryFilter filter,
     AppConfigQuerySort sort,
     AppConfigQueryProjection projection,
     AppConfigQueryPaging paging,
     AppConfigQueryOptions options)
 {
     return(new ValidationData());
 }
Example #3
0
 public static IQueryable <AppConfig> Sort(this IQueryable <AppConfig> query,
                                           AppConfigQuerySort model)
 {
     foreach (var s in model._sortsArr)
     {
         var asc       = s[0] == 'a';
         var fieldName = s.Remove(0, 1);
         switch (fieldName)
         {
         case AppConfigQuerySort.NAME:
         {
             query = asc ? query.OrderBy(o => o.Name) :
                     query.OrderByDescending(o => o.Name);
         }
         break;
         }
     }
     return(query);
 }
Example #4
0
        public async Task <IActionResult> Get([FromQuery][QueryObject] AppConfigQueryFilter filter,
                                              [FromQuery] AppConfigQuerySort sort,
                                              [FromQuery] AppConfigQueryProjection projection,
                                              [FromQuery] AppConfigQueryPaging paging,
                                              [FromQuery] AppConfigQueryOptions options)
        {
            var validationData = _service.ValidateGetAppConfigs(
                User, filter, sort, projection, paging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var result = await _service.QueryAppConfigDynamic(
                projection, options, filter, sort, paging);

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(result)));
        }