Ejemplo n.º 1
0
 public static EventInfoFilter UnpublishedEvents(EventInfoFilter filter = null)
 {
     return(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         StatusOneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         }
     });
 }
Ejemplo n.º 2
0
 public static EventInfoFilter UpcomingEvents(EventInfoFilter filter = null)
 {
     return(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Draft
         },
         StartDateAfter = SystemClock.Instance.Today()
     });
 }
Ejemplo n.º 3
0
 public static EventInfoFilter OngoingEvents(EventInfoFilter filter = null)
 {
     return(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         TodaysEventsOnly = true,
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         }
     });
 }
Ejemplo n.º 4
0
 public static EventInfoFilter FeaturedEvents(EventInfoFilter filter = null)
 {
     return(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         FeaturedOnly = true,
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         },
         StartDateAfter = SystemClock.Instance.Today()
     });
 }
 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());
 }
        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());
        }
Ejemplo n.º 7
0
 public static EventInfoFilter OnDemandEvents(EventInfoFilter filter = null)
 {
     return(new EventInfoFilter(filter ?? new EventInfoFilter())
     {
         StatusNoneOf = new[]
         {
             EventInfo.EventInfoStatus.Cancelled,
             EventInfo.EventInfoStatus.Draft
         },
         TypeOneOf = new[]
         {
             EventInfo.EventInfoType.OnlineCourse
         }
     });
 }
 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));
 }
Ejemplo n.º 9
0
 public EventInfoFilter(EventInfoFilter copy)
 {
     if (copy == null)
     {
         throw new ArgumentNullException(nameof(copy));
     }
     StatusNoneOf     = copy.StatusNoneOf;
     StatusNoneOf     = copy.StatusNoneOf;
     TypeOneOf        = copy.TypeOneOf;
     TypeNoneOf       = copy.TypeNoneOf;
     FeaturedOnly     = copy.FeaturedOnly;
     PastEventsOnly   = copy.PastEventsOnly;
     TodaysEventsOnly = copy.TodaysEventsOnly;
     StartDateAfter   = copy.StartDateAfter;
     CollectionIds    = copy.CollectionIds;
 }
 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));
 }
 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));
 }
Ejemplo n.º 12
0
 public EventInfoFilter(EventInfoFilter copy)
 {
     if (copy == null)
     {
         throw new ArgumentNullException(nameof(copy));
     }
     AccessibleOnly   = copy.AccessibleOnly;
     StatusNoneOf     = copy.StatusNoneOf;
     StatusNoneOf     = copy.StatusNoneOf;
     TypeOneOf        = copy.TypeOneOf;
     TypeNoneOf       = copy.TypeNoneOf;
     FeaturedOnly     = copy.FeaturedOnly;
     PastEventsOnly   = copy.PastEventsOnly;
     TodaysEventsOnly = copy.TodaysEventsOnly;
     StartDateBefore  = copy.StartDateBefore;
     StartDateAfter   = copy.StartDateAfter;
     EndDateBefore    = copy.EndDateBefore;
     EndDateAfter     = copy.EndDateAfter;
     CollectionIds    = copy.CollectionIds;
     OrganizationId   = copy.OrganizationId;
 }
        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));
        }
        public static IQueryable <EventInfo> UseFilter(this IQueryable <EventInfo> query, EventInfoFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            if (filter.StatusOneOf?.Any() == true)
            {
                query = query.Where(e => filter.StatusOneOf.Contains(e.Status));
            }

            if (filter.StatusNoneOf?.Any() == true)
            {
                query = query.Where(e => !filter.StatusNoneOf.Contains(e.Status));
            }

            if (filter.TypeOneOf?.Any() == true)
            {
                query = query.Where(e => filter.TypeOneOf.Contains(e.Type));
            }

            if (filter.TypeNoneOf?.Any() == true)
            {
                query = query.Where(e => !filter.TypeNoneOf.Contains(e.Type));
            }

            if (filter.FeaturedOnly)
            {
                query = query.Where(e => e.Featured);
            }

            if (filter.PastEventsOnly)
            {
                query = query.Where(e => e.DateStart <= DateTime.Now || !e.DateStart.HasValue);
            }

            if (filter.TodaysEventsOnly)
            {
                query = query.Where(i =>
                                    i.DateStart.HasValue && i.DateStart.Value.Date == DateTime.Now.Date ||
                                    i.DateStart.HasValue && i.DateEnd.HasValue && i.DateStart.Value.Date <= DateTime.Now.Date && i.DateEnd.Value.Date >= DateTime.Now.Date);
            }

            if (filter.StartDateAfter.HasValue)
            {
                query = query.Where(e => e.DateStart >= filter.StartDateAfter);
            }

            if (filter.CollectionIds?.Any() == true)
            {
                query = query.Where(e => e.CollectionMappings
                                    .Any(m => filter.CollectionIds
                                         .Contains(m.CollectionId)));
            }

            return(query);
        }
Ejemplo n.º 15
0
        public static IQueryable <EventInfo> UseFilter(this IQueryable <EventInfo> query, EventInfoFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            if (!filter.IncludeArchived)
            {
                query = query.Where(e => !e.Archived);
            }

            if (filter.StatusOneOf?.Any() == true)
            {
                query = query.Where(e => filter.StatusOneOf.Contains(e.Status));
            }

            if (filter.StatusNoneOf?.Any() == true)
            {
                query = query.Where(e => !filter.StatusNoneOf.Contains(e.Status));
            }

            if (filter.TypeOneOf?.Any() == true)
            {
                query = query.Where(e => filter.TypeOneOf.Contains(e.Type));
            }

            if (filter.TypeNoneOf?.Any() == true)
            {
                query = query.Where(e => !filter.TypeNoneOf.Contains(e.Type));
            }

            if (filter.FeaturedOnly)
            {
                query = query.Where(e => e.Featured);
            }

            var today = SystemClock.Instance.Today();

            if (filter.PastEventsOnly)
            {
                query = query.Where(e => e.DateStart <= today || !e.DateStart.HasValue);
            }

            if (filter.TodaysEventsOnly)
            {
                query = query.Where(i =>
                                    i.DateStart.HasValue && i.DateStart.Value == today ||
                                    i.DateStart.HasValue && i.DateEnd.HasValue && i.DateStart.Value <= today &&
                                    i.DateEnd.Value >= today);
            }

            if (filter.StartDate.HasValue)
            {
                query = query.Where(e => e.DateStart == filter.StartDate.Value);
            }

            if (filter.EndDate.HasValue)
            {
                query = query.Where(e => e.DateEnd == filter.EndDate);
            }

            if (filter.StartDateBefore.HasValue)
            {
                query = query.Where(e => e.DateStart <= filter.StartDateBefore);
            }

            if (filter.StartDateAfter.HasValue)
            {
                query = query.Where(e => e.DateStart >= filter.StartDateAfter);
            }

            if (filter.EndDateIsNullOrBefore.HasValue)
            {
                query = query.Where(e => !e.DateEnd.HasValue || e.DateEnd <= filter.EndDateIsNullOrBefore);
            }

            if (filter.EndDateIsNullOrAfter.HasValue)
            {
                query = query.Where(e => !e.DateEnd.HasValue || e.DateEnd >= filter.EndDateIsNullOrAfter);
            }

            if (filter.EndDateBefore.HasValue)
            {
                query = query.Where(e => e.DateEnd <= filter.EndDateBefore);
            }

            if (filter.EndDateAfter.HasValue)
            {
                query = query.Where(e => e.DateEnd >= filter.EndDateAfter);
            }

            if (filter.CollectionIds?.Any() == true)
            {
                query = query.Where(e => e.CollectionMappings
                                    .Any(m => filter.CollectionIds
                                         .Contains(m.CollectionId)));
            }

            if (filter.OrganizationId.HasValue)
            {
                query = query.Where(e => e.OrganizationId == filter.OrganizationId.Value);
            }

            return(query);
        }