Esempio n. 1
0
        public async Task ExportParticipantListToExcelAsync(Stream stream, IRegistrationExportService.Options options = null)
        {
            using var spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook);

            var workbookPart = spreadsheetDocument.AddWorkbookPart();

            workbookPart.Workbook = new Workbook();

            var worksheetPart = workbookPart.AddNewPart <WorksheetPart>();
            var sheetData     = new SheetData();

            if (options?.ExportHeader == true)
            {
                WriteHeader(sheetData);
            }

            var reader = new PageReader <Registration>(async(offset, limit, token) =>
                                                       await _registrationRetrievalService.ListRegistrationsAsync(
                                                           new RegistrationListRequest
            {
                Offset     = offset,
                Limit      = limit,
                OrderBy    = RegistrationListOrder.RegistrationTime,
                Descending = true,
                Filter     = new RegistrationFilter
                {
                    EventInfoId = options?.EventInfoId
                }
            }, new RegistrationRetrievalOptions
            {
                IncludeUser      = true,
                IncludeEventInfo = true,
                IncludeOrders    = true,
                IncludeProducts  = true,
            }, token));

            while (await reader.HasMoreAsync())
            {
                foreach (var registration in await reader.ReadNextAsync())
                {
                    WriteRow(sheetData, registration);
                }
            }

            worksheetPart.Worksheet = new Worksheet(sheetData);

            // Add Sheets to the Workbook.
            var sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());

            // Append a new worksheet and associate it with the workbook.
            sheets.Append(new Sheet
            {
                Id      = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
                SheetId = 1,
                Name    = "Participants"
            });

            workbookPart.Workbook.Save();
            spreadsheetDocument.Close();
        }
        private async Task <EventSynchronizationResult> SyncAllRegistrationsAsync(IExternalSyncProviderService syncProviderService, EventInfo eventInfo,
                                                                                  CancellationToken cancellationToken)
        {
            var result = new EventSynchronizationResult(syncProviderService.Name);

            var reader = new PageReader <Registration>(async(offset, limit, token) =>
                                                       await _registrationRetrievalService.ListRegistrationsAsync(
                                                           new IRegistrationRetrievalService.Request
            {
                Offset             = offset,
                Limit              = limit,
                EventInfoId        = eventInfo?.EventInfoId,
                IncludingUser      = true,
                IncludingEventInfo = true,
                VerifiedOnly       = true,
                OrderBy            = IRegistrationRetrievalService.Order.RegistrationTime
            }, token));

            while (await reader.HasMoreAsync(cancellationToken))
            {
                foreach (var registration in await reader.ReadNextAsync(cancellationToken))
                {
                    var externalAccount = await CreateExternalAccountIfNotExists(syncProviderService, registration, result);

                    if (externalAccount != null)
                    {
                        await SyncRegistrationAsync(syncProviderService, registration, externalAccount, result);
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        private async Task <List <NotificationRecipient> > GetRecipientsAsync(
            NotificationType notificationType,
            int eventId,
            int?productId,
            Registration.RegistrationStatus[] registrationStatuses,
            Registration.RegistrationType[] registrationTypes)
        {
            var recipients = new List <NotificationRecipient>();

            // Default status if not provided: Verified, attended and finished
            registrationStatuses ??= new[]
            {
                Registration.RegistrationStatus.Verified,
                Registration.RegistrationStatus.Attended,
                Registration.RegistrationStatus.Finished
            };

            // Default registration type is participants
            registrationTypes ??= new[]
            {
                Registration.RegistrationType.Participant
            };

            var reader = new PageReader <Registration>(async(offset, limit, token) =>
                                                       await _registrationRetrievalService.ListRegistrationsAsync(
                                                           new RegistrationListRequest
            {
                Limit  = limit,
                Offset = offset,
                Filter = new RegistrationFilter
                {
                    EventInfoId = eventId,
                    ProductIds  = productId.HasValue
                                ? new[] { productId.Value }
                                : null,
                    ActiveUsersOnly = true,
                    HavingStatuses  = registrationStatuses,
                    HavingTypes     = registrationTypes
                }
            },
                                                           new RegistrationRetrievalOptions
            {
                LoadUser  = true,
                ForUpdate = true
            }, token));

            while (await reader.HasMoreAsync())
            {
                recipients.AddRange((from registration in await reader
                                     .ReadNextAsync()
                                     select NotificationRecipient.Create(registration, notificationType))
                                    .Where(r => r != null)); // user may have no phone, or email
            }

            return(recipients);
        }
Esempio n. 4
0
        public async Task <ActionResult <NotificationResponseDto> > SendEmail(EmailNotificationDto dto, CancellationToken cancellationToken)
        {
            var email = new EmailNotification
            {
                Subject      = dto.Subject,
                BodyMarkdown = dto.BodyMarkdown
            };

            if (dto.Recipients?.Any() != true && dto.Filter?.IsDefined != true)
            {
                return(BadRequest("Either recipient list of registrant filter must be specified"));
            }

            var recipients = dto.Recipients ?? Array.Empty <string>();

            if (dto.Filter?.IsDefined == true)
            {
                var reader = new PageReader <Registration>(async(offset, limit, token) =>
                                                           await _registrationRetrievalService.ListRegistrationsAsync(
                                                               new RegistrationListRequest
                {
                    Limit  = limit,
                    Offset = offset,
                    Filter = new RegistrationFilter
                    {
                        EventInfoId              = dto.Filter.EventId,
                        AccessibleOnly           = true,
                        ActiveUsersOnly          = true,
                        HavingEmailConfirmedOnly = true,
                        HavingStatuses           = dto.Filter.RegistrationStatuses,
                        HavingTypes              = dto.Filter.RegistrationTypes
                    }
                },
                                                               new RegistrationRetrievalOptions
                {
                    IncludeUser = true
                }, token));

                var recipientList = new List <string>();

                while (await reader.HasMoreAsync(cancellationToken))
                {
                    recipientList.AddRange(from registration in await reader
                                           .ReadNextAsync(cancellationToken)
                                           let userName = registration.User?.Name
                                                          let userEmail = registration.User?.Email
                                                                          where !string.IsNullOrEmpty(userEmail)
                                                                          select $"{userName} <{userEmail}>");
                }

                recipients = recipientList
                             .Distinct()
                             .ToArray();
            }

            if (recipients.Any())
            {
                await _emailNotificationService.SendEmailToRecipientsAsync(email, recipients, cancellationToken);
            }
            else
            {
                _logger.LogWarning("No recipients were selected by the notification filter criteria");
            }

            return(Ok(new NotificationResponseDto
            {
                TotalRecipients = recipients.Length
            }));
        }