Exemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery] AppUserQueryFilter filter,
                                              [FromQuery] AppUserQuerySort sort,
                                              [FromQuery] AppUserQueryProjection projection,
                                              [FromQuery] AppUserQueryPaging paging,
                                              [FromQuery] AppUserQueryOptions options)
        {
            var validationResult = _service.ValidateGetAppUsers(
                User, filter, sort, projection, paging, options);

            if (!validationResult.Valid)
            {
                return(BadRequest(validationResult.Result));
            }
            var result = await _service.QueryAppUserDynamic(
                projection, options, filter, sort, paging, UserId);

            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)));
        }
Exemplo n.º 2
0
        public async Task <QueryResult <IDictionary <string, object> > > QueryAppUserDynamic(
            AppUserQueryProjection projection,
            AppUserQueryOptions options,
            AppUserQueryFilter filter = null,
            AppUserQuerySort sort     = null,
            AppUserQueryPaging paging = null)
        {
            var query = Users;

            #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 || !AppUserQueryOptions.IsLoadAllAllowed))
                {
                    query = query.SelectPage(paging.page, paging.limit);
                }
                #endregion
            }

            if (options.single_only)
            {
                var single = query.SingleOrDefault();
                if (single == null)
                {
                    return(null);
                }
                var singleResult = GetAppUserDynamic(single, projection, options);
                return(new QueryResult <IDictionary <string, object> >()
                {
                    Single = singleResult
                });
            }
            var entities = query.ToList();
            var list     = GetAppUserDynamic(entities, projection, options);
            var result   = new QueryResult <IDictionary <string, object> >();
            result.List = list;
            if (options.count_total)
            {
                result.Count = totalCount;
            }
            return(result);
        }
Exemplo n.º 3
0
 public ValidationData ValidateGetAppUsers(
     ClaimsPrincipal principal,
     AppUserQueryFilter filter,
     AppUserQuerySort sort,
     AppUserQueryProjection projection,
     AppUserQueryPaging paging,
     AppUserQueryOptions options)
 {
     return(new ValidationData());
 }
Exemplo n.º 4
0
 public ValidationResult ValidateGetAppUsers(
     ClaimsPrincipal principal,
     AppUserQueryFilter filter,
     AppUserQuerySort sort,
     AppUserQueryProjection projection,
     AppUserQueryPaging paging,
     AppUserQueryOptions options)
 {
     return(ValidationResult.Pass());
 }
        public async Task <IActionResult> Get([FromQuery][QueryObject] AppUserQueryFilter filter,
                                              [FromQuery] AppUserQuerySort sort,
                                              [FromQuery] AppUserQueryProjection projection,
                                              [FromQuery] AppUserQueryPaging paging,
                                              [FromQuery] AppUserQueryOptions options)
        {
            var validationData = _service.ValidateGetAppUsers(
                User, filter, sort, projection, paging, options);

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

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(result)));
        }
Exemplo n.º 6
0
        public async Task <QueryResult <AppUserQueryRow> > QueryAppUser(
            AppUserQueryFilter filter         = null,
            AppUserQuerySort sort             = null,
            AppUserQueryProjection projection = null,
            AppUserQueryPaging paging         = null,
            AppUserQueryOptions options       = null)
        {
            var conn     = context.Database.GetDbConnection();
            var openConn = conn.OpenAsync();
            var query    = AppUserQuery.CreateDynamicSql();

            #region General
            if (filter != null)
            {
                query = query.SqlFilter(filter);
            }
            if (projection != null)
            {
                query = query.SqlJoin(projection);
            }
            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 || !AppUserQueryOptions.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);
            }
            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 => AppUserQueryProjection.Extras.ContainsKey(f));
                    IEnumerable <AppUserRoleQueryRow> userRoles = null;
                    foreach (var key in extraKeys)
                    {
                        switch (key)
                        {
                        case AppUserQueryProjection.ROLES:
                            userRoles = GetAppUserRoleQueryResult(multipleResult);
                            break;
                        }
                    }
                    ProcessExtras(queryResult, userRoles);
                }
                if (options != null && options.single_only)
                {
                    var single = queryResult.FirstOrDefault();
                    if (single == null)
                    {
                        return(null);
                    }
                    return(new QueryResult <AppUserQueryRow>
                    {
                        SingleResult = single
                    });
                }
                if (options != null && options.count_total)
                {
                    totalCount = await countTask;
                }
                return(new QueryResult <AppUserQueryRow>
                {
                    Results = queryResult,
                    TotalCount = totalCount
                });
            }
        }