public async Task <IActionResult> List(int id,
                                               [FromQuery] EventCertificateQueryDto query,
                                               CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.FormatErrors()));
            }

            var eventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(id, cancellationToken);

            await _eventInfoAccessControlService.CheckEventManageAccessAsync(eventInfo, cancellationToken);

            var certificates = await _certificateRetrievalService
                               .ListCertificatesAsync(new CertificateListRequest
            {
                Limit  = query.Limit,
                Offset = query.Offset,
                Filter = new CertificateFilter
                {
                    EventId = id
                }
            }, new CertificateRetrievalOptions
            {
                LoadIssuingOrganization = true,
                LoadIssuingUser         = true,
                LoadRecipientUser       = true
            }, cancellationToken);

            return(Ok(PageResponseDto <EventDto> .FromPaging(
                          query, certificates,
                          c => new CertificateDto(c))));
        }
예제 #2
0
        private async Task CheckEventAccessAsync(int eventId)
        {
            var eventInfo = await _eventInfoRetrievalService
                            .GetEventInfoByIdAsync(eventId);

            await _eventInfoAccessControlService
            .CheckEventManageAccessAsync(eventInfo);
        }
예제 #3
0
        public async Task <ICollection <Certificate> > CreateCertificatesForEventAsync(EventInfo eventInfo,
                                                                                       CancellationToken cancellationToken)
        {
            await _eventInfoAccessControlService
            .CheckEventManageAccessAsync(eventInfo, cancellationToken);

            var certificates = new List <Certificate>();

            for (var reader = ReadRegistrations(eventInfo, havingNoCertificateOnly: true);
                 await reader.HasMoreAsync(cancellationToken);)
            {
                certificates.AddRange(from registration in await reader.ReadNextAsync(cancellationToken)
                                      select registration.CreateCertificate());

                await _context.SaveChangesAsync(cancellationToken);
            }

            return(certificates);
        }