Пример #1
0
 public AmountCurrency Sum(AmountCurrency amountCurrency)
 {
     if (amountCurrency.Currency != this.Currency)
     {
         throw new InvalidOperationException("Cannot sum different currencies");
     }
     else
     {
         return(new AmountCurrency(
                    amountCurrency.Amount + this.Amount,
                    this.Currency.ToString()));
     }
 }
Пример #2
0
        public void AddDebtAmount(AmountCurrency debtAmount)
        {
            //Check if this currency exists in the DebtByCurrency list
            var debtItem = DebtAmountsByCurrency.FirstOrDefault(x => x.Currency == debtAmount.Currency);

            if (debtItem != null)
            {
                debtItem.Amount += debtAmount.Amount;
            }
            else
            {
                //If no amount with this currency has been added yet,
                //create a new item and add this amount
                DebtAmountsByCurrency.Add(new AmountCurrency(debtAmount.Amount, debtAmount.Currency.Value));
            }
        }