private async Task <object> ResolveConnectionAsync(IMediator mediator, IResolveConnectionContext <object> context)
        {
            var first = context.First;
            var skip  = Convert.ToInt32(context.After ?? 0.ToString());

            var query = context.GetCartQuery <SearchCartQuery>();

            query.Skip          = skip;
            query.Take          = first ?? context.PageSize ?? 10;
            query.Sort          = context.GetArgument <string>("sort");
            query.Filter        = context.GetArgument <string>("filter");
            query.IncludeFields = context.SubFields.Values.GetAllNodesPaths().ToArray();

            context.CopyArgumentsToUserContext();

            var authorizationResult = await _authorizationService.AuthorizeAsync(context.GetCurrentPrincipal(), query, new CanAccessCartAuthorizationRequirement());

            if (!authorizationResult.Succeeded)
            {
                throw new ExecutionError($"Access denied");
            }

            var response = await mediator.Send(query);

            foreach (var cartAggregate in response.Results)
            {
                context.SetExpandedObjectGraph(cartAggregate);
            }
            return(new PagedConnection <CartAggregate>(response.Results, skip, Convert.ToInt32(context.After ?? 0.ToString()), response.TotalCount));
        }
Пример #2
0
        private async Task <object> ResolvePaymentsConnectionAsync(IMediator mediator, IResolveConnectionContext <object> context)
        {
            var query = context.ExtractQuery <SearchPaymentsQuery>();

            var authorizationResult = await _authorizationService.AuthorizeAsync(context.GetCurrentPrincipal(), query, new CanAccessOrderAuthorizationRequirement());

            if (!authorizationResult.Succeeded)
            {
                throw new AuthorizationError($"Access denied");
            }

            context.UserContext.Add(nameof(Currency.CultureName).ToCamelCase(), query.CultureName);

            var response = await mediator.Send(query);

            foreach (var payment in response.Results)
            {
                context.SetExpandedObjectGraph(payment);
            }

            var allCurrencies = await _currencyService.GetAllCurrenciesAsync();

            //Store all currencies in the user context for future resolve in the schema types
            context.SetCurrencies(allCurrencies, query.CultureName);

            return(new PagedConnection <PaymentIn>(response.Results, query.Skip, query.Take, response.TotalCount));
        }
Пример #3
0
        private async Task <object> ResolveOrdersConnectionAsync(IMediator mediator, IResolveConnectionContext <object> context)
        {
            var first = context.First;
            var skip  = Convert.ToInt32(context.After ?? 0.ToString());

            var request = new SearchOrderQuery
            {
                Skip        = skip,
                Take        = first ?? context.PageSize ?? 10,
                Filter      = context.GetArgument <string>("filter"),
                Sort        = context.GetArgument <string>("sort"),
                CultureName = context.GetArgument <string>(nameof(Currency.CultureName).ToCamelCase()),
                CustomerId  = context.GetArgumentOrValue <string>("userId")
            };

            context.CopyArgumentsToUserContext();
            var allCurrencies = await _currencyService.GetAllCurrenciesAsync();

            //Store all currencies in the user context for future resolve in the schema types
            context.SetCurrencies(allCurrencies, request.CultureName);


            var authorizationResult = await _authorizationService.AuthorizeAsync(context.GetCurrentPrincipal(), request, new CanAccessOrderAuthorizationRequirement());

            if (!authorizationResult.Succeeded)
            {
                throw new ExecutionError($"Access denied");
            }

            var response = await mediator.Send(request);

            foreach (var customerOrderAggregate in response.Results)
            {
                context.SetExpandedObjectGraph(customerOrderAggregate);
            }

            return(new PagedConnection <CustomerOrderAggregate>(response.Results, skip, Convert.ToInt32(context.After ?? 0.ToString()), response.TotalCount));
        }