-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathEarnPoints.cs
29 lines (25 loc) · 1.07 KB
/
EarnPoints.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
namespace Memstate.Docs.GettingStarted.QuickStart.Commands
{
public class EarnPoints : Command<LoyaltyDB, Customer>
{
public EarnPoints(int customerId, int points)
{
CustomerId = customerId;
Points = points;
}
public int CustomerId { get; }
public int Points { get; }
// it is safe to return a live customer object linked to the Model because
// (1) the class is serializable and a remote client will get a serialized copy
// and (2) in this particular case Customer is immutable.
// if you have mutable classes, then please rather return a view, e.g. CustomerBalance or CustomerView class
public override Customer Execute(LoyaltyDB model)
{
var customer = model.Customers[CustomerId];
var newPoints = customer.LoyaltyPointBalance + Points;
var customerWithNewBalance = new Customer(CustomerId, newPoints);
model.Customers[CustomerId] = customerWithNewBalance;
return customerWithNewBalance;
}
}
}