public PercentageTaxPolicy(decimal rate, Func <OrderedProduct, decimal> taxableAmountPolicy, Func <Order, IEnumerable <OrderedProduct> > taxibleItemsPolicy, ITaxPolicy previousPolicy = null) : base(previousPolicy) { _rate = rate; _taxableAmountPolicy = taxableAmountPolicy; _taxableItemsPolicy = taxibleItemsPolicy; }
public PercentageTaxPolicy( decimal rate, Func<OrderedProduct, decimal> taxableAmountPolicy, Func<Order, IEnumerable<OrderedProduct>> taxibleItemsPolicy, ITaxPolicy previousPolicy = null) : base(previousPolicy) { _rate = rate; _taxableAmountPolicy = taxableAmountPolicy; _taxableItemsPolicy = taxibleItemsPolicy; }
public void Handle() { int orderId = 1234; Order order = _orderRepository.Get(orderId); TaxPolicyFactory policyFactory = new TaxPolicyFactory(); ITaxPolicy taxPolicy = policyFactory.CreateTaxPolicy(order.Customer); Invoice invoice = _invoiceService.CreateInvoice(order, taxPolicy); //TODO: Save repository into the store }
//Prefer to have factory here. Followed by DDD rules about domain service definition. //Should be used when one aggregate is being transformed to another one. public Invoice CreateInvoice(Order order, ITaxPolicy taxPolicy) { Invoice invoice = new Invoice(order.Customer); foreach (var orderLine in order.OrderLines) { Tax tax = taxPolicy.CalculateTax(orderLine.Product, orderLine.TotalEffectivePrice); InvoiceLine line = new InvoiceLine(orderLine.Product, orderLine.Quantity, orderLine.TotalEffectivePrice, tax); invoice.AddLine(line); } return(invoice); }
public Invoice Issuance(Order order, ITaxPolicy taxPolicy) { // TODO refactor to InvoiceFactory, testability Invoice invoice = new Invoice(order.ClientId); foreach (OrderedProduct orderedProduct in order.OrderedProducts) { Product product = ProductRepository.Load(orderedProduct.ProductId); Money net = orderedProduct.EffectiveCost; Tax tax = taxPolicy.CalculateTax(product.Type, net); InvoiceLine invoiceLine = new InvoiceLine(product, orderedProduct.Quantity, net, tax); invoice.AddItem(invoiceLine); } return(invoice); }
public void ApplyTaxPolicy(ITaxPolicy taxPolicy) { taxPolicy.ApplyTaxes(this); }
public MillitaryTaxPolicy(ITaxPolicy previousPolicy = null) : base(previousPolicy) { }
internal TaxPolicy(ITaxPolicy previousPolicy) { _previousPolicy = previousPolicy; }
public MillitaryTaxPolicy(ITaxPolicy previousPolicy = null) : base(previousPolicy) { }
internal TaxPolicy(ITaxPolicy previousPolicy) { _previousPolicy = previousPolicy; }
public static Order In(this Order order, ITaxPolicy taxPolicy) { order.ApplyTaxPolicy(taxPolicy); return order; }
public FlatTaxPolicy(decimal fixedTax, ITaxPolicy previousPolicy = null) : base(previousPolicy) { _fixedTax = fixedTax; }
public void ApplyTaxPolicy(ITaxPolicy taxPolicy) { taxPolicy.ApplyTaxes(this); }
public FlatTaxPolicy(decimal fixedTax, ITaxPolicy previousPolicy = null) : base(previousPolicy) { _fixedTax = fixedTax; }
public static Order In(this Order order, ITaxPolicy taxPolicy) { order.ApplyTaxPolicy(taxPolicy); return(order); }