Exemple #1
0
        public async Task <ActionResult <RegistrationDto> > UpdateRegistration(int id,
                                                                               [FromBody] RegistrationFormDto dto,
                                                                               CancellationToken cancellationToken)
        {
            var registration = await _registrationRetrievalService.GetRegistrationByIdAsync(id, null, cancellationToken);

            dto.CopyTo(registration);
            await _registrationManagementService.UpdateRegistrationAsync(registration, cancellationToken);

            return(Ok(new RegistrationDto(registration)));
        }
        public async Task <Order> CreateOrderForRegistrationAsync(
            Registration registration,
            OrderItemDto[] data,
            CancellationToken cancellationToken)
        {
            await _registrationAccessControlService
            .CheckRegistrationUpdateAccessAsync(registration, cancellationToken);

            data ??= Array.Empty <OrderItemDto>();

            var productIds = data.Select(o => o.ProductId).ToArray();
            var variantIds = data.Select(o => o.VariantId).ToArray();

            var productMap = await _context.Products
                             .Where(p => productIds.Contains(p.ProductId))
                             .ToDictionaryAsync(p => p.ProductId, cancellationToken);

            var variantMap = await _context.ProductVariants
                             .Where(v => variantIds.Contains(v.ProductVariantId))
                             .ToDictionaryAsync(v => v.ProductVariantId, cancellationToken);

            var lines = data.Select(o => new OrderDTO
            {
                Product  = productMap[o.ProductId],
                Variant  = o.VariantId.HasValue ? variantMap[o.VariantId.Value] : null,
                Quantity = o.Quantity
            });

            var order = registration.CreateOrder(lines);
            await _registrationManagementService.UpdateRegistrationAsync(registration, cancellationToken);

            return(order);
        }
        public async Task <ActionResult <RegistrationDto> > CreateNewRegistration(
            [FromBody] NewRegistrationDto dto,
            CancellationToken cancellationToken)
        {
            var registration =
                await _registrationManagementService.CreateRegistrationAsync(dto.EventId, dto.UserId,
                                                                             new RegistrationOptions
            {
                CreateOrder = dto.CreateOrder
            },
                                                                             cancellationToken);

            if (!dto.Empty)
            {
                dto.CopyTo(registration);
                await _registrationManagementService
                .UpdateRegistrationAsync(registration, cancellationToken);
            }

            return(Ok(new RegistrationDto(registration)));
        }