예제 #1
0
        public async Task CheckOrderReadAccessAsync(
            Order order,
            CancellationToken cancellationToken)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var registration = await GetOrderRegistrationAsync(order, cancellationToken);

            await _registrationAccessControlService
            .CheckRegistrationReadAccessAsync(registration, cancellationToken);
        }
        public async Task CheckCertificateReadAccessAsync(
            Certificate certificate,
            CancellationToken cancellationToken)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }

            var reg = await GetRegistrationForCertificateAsync(certificate, cancellationToken);

            await _registrationAccessControlService
            .CheckRegistrationReadAccessAsync(reg, cancellationToken);
        }
        public async Task <Registration> GetRegistrationByIdAsync(int id,
                                                                  RegistrationRetrievalOptions options,
                                                                  CancellationToken cancellationToken)
        {
            options ??= RegistrationRetrievalOptions.Default;

            var registration = await _context.Registrations
                               .AsNoTracking()
                               .WithOptions(options)
                               .Where(r => r.RegistrationId == id)
                               .FirstOrDefaultAsync(cancellationToken);

            if (registration == null)
            {
                throw new NotFoundException($"Registration {id} not found.");
            }

            await _registrationAccessControlService
            .CheckRegistrationReadAccessAsync(registration);

            return(registration);
        }
        public async Task <Registration> GetRegistrationByIdAsync(int id,
                                                                  RegistrationRetrievalOptions options,
                                                                  CancellationToken cancellationToken)
        {
            options ??= RegistrationRetrievalOptions.Default;

            var registration = await _context.Registrations
                               .WithOptions(options)
                               .FirstOrDefaultAsync(r => r.RegistrationId == id, cancellationToken)
                               ?? throw new NotFoundException($"Registration {id} not found.");

            if (options.ForUpdate)
            {
                await _registrationAccessControlService
                .CheckRegistrationUpdateAccessAsync(registration, cancellationToken);
            }
            else
            {
                await _registrationAccessControlService
                .CheckRegistrationReadAccessAsync(registration, cancellationToken);
            }

            return(registration);
        }