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)))); }
private async Task CheckEventAccessAsync(int eventId) { var eventInfo = await _eventInfoRetrievalService .GetEventInfoByIdAsync(eventId); await _eventInfoAccessControlService .CheckEventManageAccessAsync(eventInfo); }
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); }