예제 #1
0
        private (Amount paid, Money remaining) Pay(Money money, Amount remainder)
        {
            Timestamp now = Timestamp.Now;

            switch (money)
            {
            case Amount amt when amt.Currency != remainder.Currency:
                return(Amount.Zero(remainder.Currency), money);

            case Amount amt when amt.Value <= remainder.Value:
                return(new Amount(amt.Currency, amt.Value), Amount.Zero(amt.Currency));

            case GiftCard gift when gift.Currency != remainder.Currency:
                return(Amount.Zero(remainder.Currency), gift);

            case GiftCard gift when gift.ValidBefore.CompareTo(now) < 0:
                return(Amount.Zero(remainder.Currency), Amount.Zero(gift.Currency));

            case GiftCard gift when gift.Value <= remainder.Value:
                return(new Amount(gift.Currency, gift.Value), Amount.Zero(gift.Currency));

            case Amount amt:
                return(remainder, amt.Subtract(remainder));

            case BankCard card when card.ValidBefore.CompareTo(now) < 0:
                return(Amount.Zero(remainder.Currency), Amount.Zero(remainder.Currency));

            case BankCard _:
                return(remainder, money);

            default:
                throw new ArgumentException("Money type not supported.");
            }
        }
예제 #2
0
 public (Amount paid, Money remaining) Pay(Amount expense)
 {
     if (expense.Currency != this.Currency)
     {
         return(Amount.Zero(expense.Currency), this);
     }
     if (expense.Value >= this.Value)
     {
         return(this, Amount.Zero(this.Currency));
     }
     return(expense, this.Subtract(expense));
 }
예제 #3
0
        public (Amount paid, Wallet remaining) Pay(Amount expense)
        {
            Amount        remainder = expense;
            Amount        paid      = Amount.Zero(expense.Currency);
            IList <Money> rests     = new List <Money>();

            foreach (Money money in this.Moneys)
            {
                (Amount stepPaid, Money stepRemaining) = this.Pay(money, remainder);
                paid = paid.Add(stepPaid);
                rests.Add(stepRemaining);
            }

            return(paid, new Wallet(rests.Where(item => !(item is Empty))));
        }
        public static (Amount paid, Money remaining) Pay(this Money money, Amount expense)
        {
            Timestamp now = Timestamp.Now;

            switch (money)
            {
            case Amount amt when amt.Currency != expense.Currency:
                return(Amount.Zero(expense.Currency), money);

            case Amount amt when amt.Value <= expense.Value:
                return(amt, Amount.Zero(amt.Currency));

            case GiftCard gift when gift.Currency != expense.Currency:
                return(Amount.Zero(expense.Currency), gift);

            case GiftCard gift when gift.ValidBefore.CompareTo(now) < 0:
                return(Amount.Zero(expense.Currency), Amount.Zero(gift.Currency));

            case GiftCard gift when gift.Value <= expense.Value:
                return(new Amount(gift.Currency, gift.Value),
                       Amount.Zero(gift.Currency));

            case Empty _:
                return(Amount.Zero(expense.Currency), money);

            case Amount amt:
                return(expense, amt.Subtract(expense));

            case BankCard card when card.ValidBefore.CompareTo(now) < 0:
                return(Amount.Zero(expense.Currency),
                       Amount.Zero(expense.Currency));

            case BankCard _:
                return(expense, money);

            default:
                throw new ArgumentException(
                          $"Unsupported money type {money.GetType().Name}.");
            }
        }
예제 #5
0
 public override Tuple <Amount, Money> Take(decimal amount) =>
 Tuple.Create(Amount.Zero(base.Currency), (Money)this);
예제 #6
0
 public override Money On(Timestamp time) =>
 time.CompareTo(this.ValidBefore) >= 0
         ? Amount.Zero(base.Currency)
         : this;