public async Task <IActionResult> List(CancellationToken cancellationToken) { var collections = await _eventCollectionRetrievalService .ListCollectionsAsync(cancellationToken : cancellationToken); return(Ok(collections .Select(c => new EventCollectionDto(c)) .ToArray())); }
private async Task ValidateProducts( Registration registration, OrderItemDto[] data, IReadOnlyDictionary <int, Product> productMap, IReadOnlyDictionary <int, ProductVariant> variantMap, CancellationToken cancellationToken = default) { foreach (var dto in data) { if (dto.Quantity <= 0) { throw new InputException($"Invalid quantity for product {dto.ProductId}: {dto.Quantity}"); } if (!productMap.ContainsKey(dto.ProductId)) { throw new InputException($"Unknown product ID: {dto.ProductId}"); } if (dto.VariantId.HasValue) { if (!variantMap.ContainsKey(dto.VariantId.Value)) { throw new InputException($"Unknown product variant ID: {dto.VariantId}"); } if (variantMap[dto.VariantId.Value].ProductId != dto.ProductId) { throw new InputException( $"Wrong product ID: {dto.ProductId} for variant ID {dto.VariantId}"); } } var product = productMap[dto.ProductId]; if (product.EventInfoId != registration.EventInfoId) { if (product.Visibility == ProductVisibility.Event) { throw new InputException( $"Product {product.ProductId} doesn't belong to event {registration.EventInfoId}"); } if (product.Visibility == ProductVisibility.Collection) { var collections = await _eventCollectionRetrievalService .ListCollectionsAsync(new EventCollectionListRequest { Filter = new EventCollectionFilter { EventInfoId = registration.EventInfoId } }, new EventCollectionRetrievalOptions { LoadMappings = true }, cancellationToken); if (!collections.Any(c => c.EventMappings .Any(m => m.EventId == product.EventInfoId))) { throw new InputException( $"Product {product.ProductId} cannot be added to order for event {registration.EventInfoId}"); } } } } }