-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCalculatePrices.cs
executable file
·40 lines (35 loc) · 1.62 KB
/
CalculatePrices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.Immutable;
using MyCompany.ECommerce.Sales.Clients;
using MyCompany.ECommerce.Sales.Commons;
using MyCompany.ECommerce.Sales.ExchangeRates;
using MyCompany.ECommerce.Sales.Pricing.PriceLists;
using MyCompany.ECommerce.Sales.Products;
using MyCompany.ECommerce.Sales.SalesChannels;
using P3Model.Annotations.Domain.DDD;
namespace MyCompany.ECommerce.Sales.Pricing;
[DddDomainService]
public class CalculatePrices(
PriceListRepository priceLists,
OfferModifiers offerModifiers,
ExchangeRateProvider exchangeRates)
{
public async Task<Quote> For(ClientId clientId, SalesChannel salesChannel, ProductAmount productAmount,
Currency currency) =>
(await For(clientId, salesChannel, ImmutableArray.Create(productAmount), currency))
.Quotes.Single();
public Task<Offer> For(ClientId clientId, SalesChannel salesChannel,
IEnumerable<ProductAmount> productAmounts, Currency currency) =>
For(clientId, salesChannel, productAmounts.ToImmutableArray(), currency);
public async Task<Offer> For(ClientId clientId, SalesChannel salesChannel,
ImmutableArray<ProductAmount> productAmounts, Currency currency)
{
var offerRequest = OfferRequest.For(clientId, salesChannel, productAmounts);
var (basePrices, offerModifier, exchangeRate) = await (
priceLists.GetBasePricesFor(clientId, productAmounts),
offerModifiers.ChooseFor(offerRequest),
exchangeRates.GetFor(currency));
return Offer.WithBasePrices(productAmounts, basePrices)
.Apply(offerModifier)
.Apply(exchangeRate);
}
}