예제 #1
0
        public async Task <IActionResult> GetPaged([FromBody] GoblinIdentityGetPagedUserModel model, CancellationToken cancellationToken = default)
        {
            var userPagedModel = await _userService.GetPagedAsync(model, cancellationToken);

            var userPagedWithMetadataResponseModel = Url.GetGoblinApiPagedMetaResponseModel(model, userPagedModel);

            return(Ok(userPagedWithMetadataResponseModel));
        }
예제 #2
0
        public static async Task <GoblinApiPagedMetaResponseModel <GoblinIdentityGetPagedUserModel, GoblinIdentityUserModel> > GetPagedAsync(GoblinIdentityGetPagedUserModel model, CancellationToken cancellationToken = default)
        {
            try
            {
                var endpoint = GetRequest(null).AppendPathSegment(GoblinIdentityEndpoints.GetPagedUser);

                var userPagedMetaResponse = await endpoint
                                            .PostJsonAsync(model, cancellationToken : cancellationToken)
                                            .ReceiveJson <GoblinApiPagedMetaResponseModel <GoblinIdentityGetPagedUserModel, GoblinIdentityUserModel> >()
                                            .ConfigureAwait(true);

                return(userPagedMetaResponse);
            }
            catch (FlurlHttpException ex)
            {
                await FlurlHttpExceptionHelper.HandleErrorAsync(ex).ConfigureAwait(true);

                return(null);
            }
        }
예제 #3
0
        public Task <GoblinApiPagedResponseModel <GoblinIdentityUserModel> > GetPagedAsync(
            GoblinIdentityGetPagedUserModel model, CancellationToken cancellationToken = default)
        {
            var query = _userRepo.Get();

            // Filters

            if (model.Email != null)
            {
                query = query.Where(x => x.Email.Contains(model.Email));
            }

            if (model.FullName != null)
            {
                query = query.Where(x => x.FullName.Contains(model.FullName));
            }

            if (model.UserName != null)
            {
                query = query.Where(x => x.UserName.Contains(model.UserName));
            }

            // Excludes

            var excludeIds = model.ExcludeIds.ToList <long>(long.TryParse);

            if (excludeIds.Any())
            {
                query = query.Where(x => !excludeIds.Contains(x.Id));
            }

            var includeIds = model.IncludeIds.ToList <long>(long.TryParse);

            // Includes

            if (includeIds.Any())
            {
                var includeIdsQuery = _userRepo.Get(x => includeIds.Contains(x.Id));

                query = query.Union(includeIdsQuery);
            }

            // Build Model Query

            var modelQuery = query.QueryTo <GoblinIdentityUserModel>();

            // Order

            var sortByDirection = model.IsSortAscending ? "ASC" : "DESC";

            var orderByDynamicStatement = $"{model.SortBy} {sortByDirection}";

            modelQuery = !string.IsNullOrWhiteSpace(model.SortBy)
                ? modelQuery.OrderBy(orderByDynamicStatement)
                : modelQuery.OrderByDescending(x => x.LastUpdatedTime);

            // Get Result

            var total = query.LongCount();

            var items =
                modelQuery
                .Skip(model.Skip)
                .Take(model.Take)
                .ToList();

            var pagedResponse = new GoblinApiPagedResponseModel <GoblinIdentityUserModel>
            {
                Total = total,
                Items = items
            };

            return(Task.FromResult(pagedResponse));
        }