public void AddAmount(CurrencyEnum cur, double amount) { var curr = Currencies?.FirstOrDefault(c => c.Currency == cur); if (curr == null) { if (Currencies == null) { Currencies = new List <CurrencyUser>(); } curr = new CurrencyUser(this, amount, cur); Currencies.Add(curr); } else { curr.Amount = curr.Amount += amount; } }
public void RemoveAmount(CurrencyEnum cur, double amount) { var curr = Currencies?.FirstOrDefault(c => c.Currency == cur); if (curr == null) { if (Currencies == null) { Currencies = new List <CurrencyUser>(); } curr = new CurrencyUser(this, 0, cur); RemoveAmount(cur, amount); } if (curr.Amount < amount) { throw new WouldMakeCurrencyNegative(); } curr.Amount = curr.Amount -= amount; }