public async Task <ICataloguePrice> Handle(GetPriceByPriceIdQuery request, CancellationToken cancellationToken) { var price = await pricingReader.GetByPriceIdAsync(request.PriceId, cancellationToken); ICataloguePrice cataloguePrice = price switch { CataloguePriceFlat cataloguePriceFlat => new FlatCataloguePriceDto { CataloguePriceId = price.CataloguePriceId, CatalogueItemName = price.CatalogueItemName, CatalogueItemId = price.CatalogueItemId, Type = price.CataloguePriceType.Name, ProvisioningType = price.ProvisioningType.Name, CurrencyCode = price.CurrencyCode, PricingUnit = mapper.Map <IPricingUnit>(price.PricingUnit), TimeUnit = mapper.Map <ITimeUnit>(price.TimeUnit), Price = cataloguePriceFlat.Price, }, CataloguePriceTier cataloguePriceTier => new TieredCataloguePriceDto { CatalogueItemId = price.CatalogueItemId, CatalogueItemName = price.CatalogueItemName, CataloguePriceId = price.CataloguePriceId, Type = price.CataloguePriceType.Name, ProvisioningType = price.ProvisioningType.Name, CurrencyCode = price.CurrencyCode, PricingUnit = mapper.Map <IPricingUnit>(price.PricingUnit), TimeUnit = mapper.Map <ITimeUnit>(price.TimeUnit), TieredPrices = mapper.Map <IEnumerable <ITieredPrice> >(cataloguePriceTier.TieredPrices), }, _ => null, }; return(cataloguePrice); }
public async Task <ICataloguePrice> Handle(GetPriceByPriceIdQuery request, CancellationToken cancellationToken) { var price = await _pricingReader.GetByPriceIdAsync(request.PriceId, cancellationToken); ICataloguePrice cataloguePrice = null; if (price is CataloguePriceFlat cataloguePriceFlat) { cataloguePrice = new FlatCataloguePriceDto { CataloguePriceId = price.CataloguePriceId, CatalogueItemName = price.CatalogueItemName, CatalogueItemId = price.CatalogueItemId, Type = price.CataloguePriceType.Name, ProvisioningType = price.ProvisioningType.Name, CurrencyCode = price.CurrencyCode, PricingUnit = _mapper.Map <IPricingUnit>(price.PricingUnit), TimeUnit = _mapper.Map <ITimeUnit>(price.TimeUnit), Price = cataloguePriceFlat.Price }; } else if (price is CataloguePriceTier cataloguePriceTier) { cataloguePrice = new TieredCataloguePriceDto { CatalogueItemId = price.CatalogueItemId, CatalogueItemName = price.CatalogueItemName, CataloguePriceId = price.CataloguePriceId, Type = price.CataloguePriceType.Name, ProvisioningType = price.ProvisioningType.Name, CurrencyCode = price.CurrencyCode, PricingUnit = _mapper.Map <IPricingUnit>(price.PricingUnit), TimeUnit = _mapper.Map <ITimeUnit>(price.TimeUnit), TieredPrices = _mapper.Map <IEnumerable <ITieredPrice> >(cataloguePriceTier.TieredPrices) }; } return(cataloguePrice); }