Ejemplo n.º 1
0
        public static IQueryable <Order> WithOptions(
            this IQueryable <Order> query,
            OrderRetrievalOptions options)
        {
            if (options.IncludeRegistration)
            {
                query = query.Include(o => o.Registration);
            }

            if (options.IncludeUser)
            {
                query = query
                        .Include(o => o.User)
                        .Include(o => o.Registration)
                        .ThenInclude(r => r.User);
            }

            if (options.IncludeEvent)
            {
                query = query.Include(o => o.Registration)
                        .ThenInclude(r => r.EventInfo);
            }

            if (options.IncludeOrderLines)
            {
                query = query.Include(o => o.OrderLines)
                        .ThenInclude(l => l.Product);

                query = query.Include(o => o.OrderLines)
                        .ThenInclude(l => l.ProductVariant);
            }

            return(query);
        }
Ejemplo n.º 2
0
        public async Task <Order> GetOrderByIdAsync(int id,
                                                    OrderRetrievalOptions options,
                                                    CancellationToken cancellationToken)
        {
            var order = await _context.Orders
                        .WithOptions(options ?? new OrderRetrievalOptions())
                        .FirstOrDefaultAsync(o => o.OrderId == id, cancellationToken) ?? throw
                            new NotFoundException($"Order {id} not found");

            await _orderAccessControlService.CheckOrderReadAccessAsync(order, cancellationToken);

            return(order);
        }
Ejemplo n.º 3
0
        public async Task <Paging <Order> > ListOrdersAsync(
            OrderListRequest request,
            OrderRetrievalOptions options,
            CancellationToken cancellationToken)
        {
            var filter = request.Filter ?? new OrderListFilter();

            var query = _context.Orders
                        .AsNoTracking()
                        .WithOptions(options ?? new OrderRetrievalOptions())
                        .WithOrder(request.Order, request.Descending)
                        .WithFilter(filter);

            if (filter.AccessibleOnly)
            {
                query = await _orderAccessControlService
                        .AddAccessFilterAsync(query, cancellationToken);
            }

            return(await Paging <Registration> .CreateAsync(query, request, cancellationToken));
        }