Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (44 loc) · 1.48 KB
/
Copy pathProgram.cs
File metadata and controls
50 lines (44 loc) · 1.48 KB
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
41
42
43
44
45
46
47
48
49
50
using RulesPattern.StoreExample.Rules;
using System;
using System.Collections.Generic;
using System.Linq;
using SystemRules.RulesEngine;
namespace SystemRules
{
class Program
{
static void Main(string[] args)
{
var productA = new Product { Price = 100, Name = "Apple Watch" };
var productB = new Product { Price = 50, Name = "Samsung Watch" };
var customer = new Customer
{
Products = new List<Product> { productA, productB, productA, productA },
DateOfFirstPurchase = DateTime.Now.AddYears(-2),
DateOfBirth = DateTime.Now.AddYears(-5),
};
customer.TotalValue = customer.Products.Sum(p => p.Price);
var ruleManager = new CustomerRuleManager(customer);
var result = ruleManager.Run();
}
}
public class CustomerRuleManager
{
private readonly Customer _customer;
public CustomerRuleManager(Customer customer)
{
_customer = customer;
}
public Customer Run()
{
_customer
.ApplyRule(new BirthdayDiscountRule())
.ApplyRule(new BuyThreeGetThirdFree("Apple Watch"))
.ApplyRule(new FreeShipping())
.ApplyRule(new LoyalCustomerRule(5, 0.12m))
.ApplyRule(new NewCustomerRule())
.ApplyRule(new RetiredDiscountRule());
return _customer;
}
}
}