コード例 #1
0
        public async Task <EventInfo> GetEventInfoByIdAsync(int id, EventInfoRetrievalOptions options = null)
        {
            var query = _context.EventInfos
                        .AsNoTracking()
                        .Where(e => e.EventInfoId == id)
                        .UseOptions(options ?? new EventInfoRetrievalOptions());

            return(await query.SingleAsync());
        }
コード例 #2
0
 public async Task <EventInfo> GetEventInfoByIdAsync(int id,
                                                     EventInfoRetrievalOptions options,
                                                     CancellationToken cancellationToken)
 {
     return(await _context.EventInfos
            .UseOptions(options ?? new EventInfoRetrievalOptions())
            .FirstOrDefaultAsync(e => e.EventInfoId == id, cancellationToken)
            ?? throw new NotFoundException($"Event {id} not found"));
 }
コード例 #3
0
 public static async Task <List <EventInfo> > GetPastEventsAsync(
     this IEventInfoRetrievalService service,
     EventInfoFilter filter              = null,
     EventInfoRetrievalOptions options   = null,
     CancellationToken cancellationToken = default)
 {
     return((await PageReader <EventInfo> .ReadAllAsync((offset, limit, token) =>
                                                        service.ListEventsAsync(new EventListRequest(offset, limit)
     {
         Filter = EventInfoFilter.PastEvents(filter)
     }, options, token), cancellationToken))
            .ToList());
 }
コード例 #4
0
        public async Task <List <EventInfo> > ListEventsAsync(
            EventInfoFilter filter            = null,
            EventRetrievalOrder order         = EventRetrievalOrder.StartDate,
            EventInfoRetrievalOptions options = null)
        {
            var query = _context.EventInfos.AsNoTracking()
                        .UseOptions(options ?? new EventInfoRetrievalOptions())
                        .UseFilter(filter ?? new EventInfoFilter())
                        .UseOrder(order);

            query = await AddOrgFilterIfNeededAsync(query);

            return(await query.ToListAsync());
        }
 public static async Task <List <EventInfo> > GetUnpublishedEventsAsync(
     this IEventInfoRetrievalService service,
     EventInfoFilter filter              = null,
     EventInfoRetrievalOptions options   = null,
     CancellationToken cancellationToken = default)
 {
     return(await service.ListEventsAsync(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         StatusOneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         }
     }, EventRetrievalOrder.StartDate, options, cancellationToken));
 }
コード例 #6
0
        public static IQueryable <EventInfo> UseOptions(this IQueryable <EventInfo> query,
                                                        EventInfoRetrievalOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!options.ForUpdate)
            {
                query = query.AsNoTracking();
            }

            if (options.LoadOrganizerUser)
            {
                query = query.Include(e => e.OrganizerUser);
            }

            if (options.LoadOrganization)
            {
                var includableQueryable = query.Include(e => e.Organization);
                if (options.LoadOrganizationMembers)
                {
                    includableQueryable.ThenInclude(o => o.Members);
                }

                query = includableQueryable;
            }

            if (options.LoadProducts)
            {
                query = query
                        .Include(e => e.Products)
                        .ThenInclude(p => p.ProductVariants);
            }

            if (options.LoadRegistrations)
            {
                query = query.Include(e => e.Registrations);
            }

            if (options.LoadCollections)
            {
                query = query.Include(e => e.Collections);
            }

            return(query);
        }
 public static async Task <List <EventInfo> > GetFeaturedEventsAsync(
     this IEventInfoRetrievalService service,
     EventInfoFilter filter              = null,
     EventInfoRetrievalOptions options   = null,
     CancellationToken cancellationToken = default)
 {
     return(await service.ListEventsAsync(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         FeaturedOnly = true,
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         },
         StartDateAfter = DateTime.Now
     }, EventRetrievalOrder.StartDate, options, cancellationToken));
 }
コード例 #8
0
        public async Task <EventInfo> GetEventInfoByIdAsync(int id,
                                                            EventInfoRetrievalOptions options,
                                                            CancellationToken cancellationToken)
        {
            var query = _context.EventInfos
                        .AsNoTracking()
                        .Where(e => e.EventInfoId == id)
                        .UseOptions(options ?? new EventInfoRetrievalOptions());

            var @event = await query.SingleOrDefaultAsync(cancellationToken);

            if (@event == null)
            {
                throw new NotFoundException($"Event {id} not found");
            }

            return(@event);
        }
コード例 #9
0
        public async Task <Paging <EventInfo> > ListEventsAsync(
            EventListRequest request,
            EventInfoRetrievalOptions options,
            CancellationToken cancellationToken)
        {
            var query = _context.EventInfos
                        .AsNoTracking()
                        .UseOptions(options ?? new EventInfoRetrievalOptions())
                        .UseFilter(request.Filter)
                        .UseOrder(request.Order);

            if (request.Filter.AccessibleOnly)
            {
                query = await AddOrgFilterIfNeededAsync(query, cancellationToken);
            }

            return(await Paging <EventInfo> .CreateAsync(query, request, cancellationToken));
        }
 public static async Task <List <EventInfo> > GetOnDemandEventsAsync(
     this IEventInfoRetrievalService service,
     EventInfoFilter filter              = null,
     EventInfoRetrievalOptions options   = null,
     CancellationToken cancellationToken = default)
 {
     return(await service.ListEventsAsync(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         },
         TypeOneOf = new[]
         {
             EventInfo.EventInfoType.OnlineCourse
         }
     }, EventRetrievalOrder.Title, options, cancellationToken));
 }
コード例 #11
0
        public async Task <List <EventInfo> > ListEventsAsync(
            EventInfoFilter filter,
            EventRetrievalOrder order,
            EventInfoRetrievalOptions options,
            CancellationToken cancellationToken)
        {
            filter ??= new EventInfoFilter();

            var query = _context.EventInfos
                        .AsNoTracking()
                        .UseOptions(options ?? new EventInfoRetrievalOptions())
                        .UseFilter(filter)
                        .UseOrder(order);

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

            return(await query.ToListAsync(cancellationToken));
        }
コード例 #12
0
 public static async Task <List <EventInfo> > GetUpcomingEventsAsync(this IEventInfoRetrievalService service, EventInfoRetrievalOptions options = null)
 {
     return(await service.ListEventsAsync(new EventInfoFilter
     {
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         },
         StartDateAfter = DateTime.Now
     }, EventRetrievalOrder.StartDate, options));
 }
コード例 #13
0
 public static async Task <List <EventInfo> > GetOngoingEventsAsync(this IEventInfoRetrievalService service, EventInfoRetrievalOptions options = null)
 {
     return(await service.ListEventsAsync(new EventInfoFilter
     {
         TodaysEventsOnly = true,
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         }
     }, EventRetrievalOrder.StartDate, options));
 }
コード例 #14
0
 public static async Task <List <EventInfo> > GetUnpublishedEventsAsync(this IEventInfoRetrievalService service, EventInfoRetrievalOptions options = null)
 {
     return(await service.ListEventsAsync(new EventInfoFilter
     {
         StatusOneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         }
     }, EventRetrievalOrder.StartDate, options));
 }
コード例 #15
0
        public static IQueryable <EventInfo> UseOptions(this IQueryable <EventInfo> query, EventInfoRetrievalOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.LoadOrganizerUser)
            {
                query = query.Include(e => e.OrganizerUser);
            }

            if (options.LoadOrganization)
            {
                query = query.Include(e => e.Organization);
            }

            if (options.LoadProducts)
            {
                query = query
                        .Include(e => e.Products)
                        .ThenInclude(p => p.ProductVariants);
            }

            if (options.LoadRegistrations)
            {
                query = query.Include(e => e.Registrations);
            }

            return(query);
        }