public double CalculatePrice(ProductAggregate product, OrderAggregateLineDiscount discount) { if (product == null) { throw new ArgumentNullException(nameof(product)); } if (discount == null) { throw new ArgumentNullException(nameof(discount)); } double result = product.Price; switch (discount.PromotionType) { case DiscountAggregatePromotions.FixedAmount: result -= discount.Value; break; case DiscountAggregatePromotions.Percentage: result = result - ((result * discount.Value) / 100); break; } return(result); }
public static OrderAggregateLine ToAggregate(this OrderLine orderLine) { if (orderLine == null) { throw new ArgumentNullException(nameof(orderLine)); } OrderAggregateLineDiscount discount = null; if (orderLine.Discount != null) { discount = new OrderAggregateLineDiscount { Id = orderLine.Discount.Id, Code = orderLine.Discount.Code, PromotionType = (DiscountAggregatePromotions)orderLine.Discount.PromotionType, Validity = (DiscountAggregateValidities)orderLine.Discount.Validity, Value = orderLine.Discount.Value, MoneySavedPerProduct = orderLine.MoneySavedPerProduct }; } return(new OrderAggregateLine { Id = orderLine.Id, Price = orderLine.Price, ProductId = orderLine.ProductId, Quantity = orderLine.Quantity, OrderLineDiscount = discount }); }
public double CalculateMoneySaved(ProductAggregate product, OrderAggregateLineDiscount discount) { if (product == null) { throw new ArgumentNullException(nameof(product)); } if (discount == null) { throw new ArgumentNullException(nameof(discount)); } switch (discount.PromotionType) { case DiscountAggregatePromotions.FixedAmount: return(discount.Value); case DiscountAggregatePromotions.Percentage: return((product.Price * discount.Value) / 100); } return(0); }