示例#1
0
        internal static IQueryable<Event> ApplyFilters(GetReportDataRequest request, IQueryable<Event> query)
        {
            query = ApplyKeywordFilter(request, query);
            query = ApplyStartDateFilter(request, query);
            query = ApplyEndDateFilter(request, query);
            query = ApplyTopicFilter(request, query);
            query = ApplyTypeFilter(request, query);
            query = ApplyPresenterFilter(request, query);
            query = ApplyContactNameFilter(request, query);
            query = ApplyStatusFilter(request, query);
            query = ApplyRegistrationDateFilter(request, query);

            //Filter events based on event occurrence criteria
            var eventsOccQuery = query.SelectMany(ev => ev.EventOccurrences);
            eventsOccQuery = FilterByOccurrenceDate(request.OccurrenceStartDate, request.OccurrenceEndDate, eventsOccQuery);
            eventsOccQuery = FilterByCustomLocation(request.CustomLocation, eventsOccQuery);
            query = query.Where(q => q.EventOccurrences.Intersect(eventsOccQuery).Any());

            return query;
        }
示例#2
0
        internal static IEnumerable<ReportEventDto> GetEvents(IEnumerable<EventData> events, GetReportDataRequest request)
        {
            var startDate = (request.RegistrationStartDate.HasValue ? request.RegistrationStartDate.Value : new DateTime(1900, 1, 1));
            var endDate = (request.RegistrationEndDate.HasValue ? request.RegistrationEndDate.Value : new DateTime(3000, 1, 1));

            var results = events.Select(e => new ReportEventDto
            {
                Id = e.Event.Id,
                Title = e.Event.Title,
                Description = e.Event.SummaryDescription,
                OrgUnitId = e.Event.OrgUnitId,
                OrgUnitName = e.OrgUnitName,
                CreatedDate = e.Event.CreatedDate,
                PublishDate = e.Event.PublishDate,
                DynamicFormsId = e.Event.DynamicFormsId,
                TotalRevenue = e.Event.EventOccurrences
                    .Where(o => string.IsNullOrEmpty(request.ContactName) || o.ContactName == request.ContactName)
                    .Where(o => string.IsNullOrEmpty(request.Presenter) || o.Presenter == request.Presenter)
                    .Sum(o => o.EventOccurrenceAttendees.Sum(a => a.AmountPaid)),
                TotalNumberOfRegistrants = e.Event.EventOccurrences
                    .Where(o => string.IsNullOrEmpty(request.ContactName) || o.ContactName == request.ContactName)
                    .Where(o => string.IsNullOrEmpty(request.Presenter) || o.Presenter == request.Presenter)
                    .Sum(o => o.EventOccurrenceAttendees.Where(a => a.EventRegistration.RegistrationDate >= startDate && a.EventRegistration.RegistrationDate <= endDate).Count())
            }).ToArray();

            return results;
        }
示例#3
0
        private static IQueryable<Event> ApplyTypeFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            if (request.EventTypeId.HasValue)
                query = query.Where(e => e.EventTypeAssociations.Any(a => a.EventTypeId == request.EventTypeId.Value));

            return query;
        }
示例#4
0
        private static IQueryable<Event> ApplyStartDateFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            if (request.StartDate.HasValue)
                query = query.Where(e => e.PublishDate > request.StartDate.Value);

            return query;
        }
示例#5
0
        private static IQueryable<Event> ApplyStatusFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            if (request.Status.HasValue)
                query = query.Where(e => e.IsEnabled == request.Status);

            return query;
        }
示例#6
0
        private static IQueryable<Event> ApplyRegistrationDateFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            var startDate = request.RegistrationStartDate.HasValue;
            var endDate = request.RegistrationEndDate.HasValue;

            if (startDate && endDate)
            {
                query = query.Where(e => e.EventOccurrences.SelectMany(o => o.EventOccurrenceAttendees.Where
                    (a =>
                        a.EventRegistration.RegistrationDate >= request.RegistrationStartDate.Value &&
                        a.EventRegistration.RegistrationDate <= request.RegistrationEndDate.Value)).Any());
            }
            else if (startDate)
            {
                query = query.Where(e => e.EventOccurrences.SelectMany(o => o.EventOccurrenceAttendees.
                    Where(a => a.EventRegistration.RegistrationDate >= request.RegistrationStartDate.Value)).Any());
            }
            else if (endDate)
            {
                query = query.Where(e => e.EventOccurrences.SelectMany(o => o.EventOccurrenceAttendees.Where(a => a.EventRegistration.RegistrationDate <= request.RegistrationEndDate.Value)).Any());
            }
            return query;
        }
示例#7
0
        private static IQueryable<Event> ApplyPresenterFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            if (!string.IsNullOrEmpty(request.Presenter))
                query = query.Where(e => e.EventOccurrences.Any(o => o.Presenter == request.Presenter));

            return query;
        }
示例#8
0
        private static IQueryable<Event> ApplyKeywordFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            if (!string.IsNullOrEmpty(request.Keyword))
                query = query.Where(e => e.Title.Contains(request.Keyword) || e.SummaryDescription.Contains(request.Keyword));

            return query;
        }
示例#9
0
        private static IQueryable<Event> ApplyContactNameFilter(GetReportDataRequest request, IQueryable<Event> query)
        {
            if (!string.IsNullOrEmpty(request.ContactName))
                query = query.Where(e => e.ContactName == request.ContactName || e.EventOccurrences.Any(o => o.ContactName == request.ContactName));

            return query;
        }
示例#10
0
 private GetReportDataResponse GetReportResponse()
 {
     var eventsRequest = new GetReportDataRequest()
     {
         Keyword = GetFilterValue("Keyword"),
         ContactName = GetFilterValue("ContactName"),
         Presenter = GetFilterValue("Presenter"),
         EventTopicId = string.IsNullOrEmpty(GetFilterValue("EventTopic")) ? new int?() : int.Parse(GetFilterValue("EventTopic")),
         EventTypeId = string.IsNullOrEmpty(GetFilterValue("EventType")) ? new int?() : int.Parse(GetFilterValue("EventType")),
         CustomLocation = GetFilterValue("Location"),
         OrgUnitId = string.IsNullOrEmpty(GetFilterValue("SponsoringLocation")) ? new int?() : int.Parse(GetFilterValue("SponsoringLocation")),
         IncludeDescendants = false,
         IncludeLinked = false,
         StartDate = string.IsNullOrEmpty(GetFilterValue("PublishDate")) ? new DateTime?() : DateTime.Parse(GetFilterValue("PublishDate")),
         EndDate = string.IsNullOrEmpty(GetFilterValue("UnpublishDate")) ? new DateTime?() : DateTime.Parse(GetFilterValue("UnpublishDate")),
         OccurrenceStartDate = string.IsNullOrEmpty(GetFilterValue("OccurrenceDateRangeStart")) ? new DateTime?() : DateTime.Parse(GetFilterValue("OccurrenceDateRangeStart")),
         OccurrenceEndDate = string.IsNullOrEmpty(GetFilterValue("OccurrenceDateRangeEnd")) ? new DateTime?() : DateTime.Parse(GetFilterValue("OccurrenceDateRangeEnd")),
         RegistrationStartDate = string.IsNullOrEmpty(GetFilterValue("RegistrationStartDate")) ? new DateTime?() : DateTime.Parse(GetFilterValue("RegistrationStartDate")),
         RegistrationEndDate = string.IsNullOrEmpty(GetFilterValue("RegistrationEndDate")) ? new DateTime?() : DateTime.Parse(GetFilterValue("RegistrationEndDate")),
         Status = string.IsNullOrEmpty(GetFilterValue("Enabled")) ? new bool?() : GetFilterValue("Enabled") == "Enabled"
     };
     var eventsResponse = ProcessRequest<GetReportDataResponse>(eventsRequest);
     return eventsResponse;
 }