示例#1
0
        public void ApplyCredit(CreditTransaction trans)
        {
            if (trans.Amount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(trans.Amount), "Amount cannot be less than 0.");
            }

            account.ApplyCredit(trans.Amount);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hit return on an empty line to cancel...");
            Console.WriteLine("Enter a value. Negative values are debits, positive are credits.");

            var svc = new AccountSvc();

            while (true)
            {
                var line = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                if (double.TryParse(line, out var val))
                {
                    try
                    {
                        if (val < 0)
                        {
                            var trans = new DebitTransaction(val);
                            svc.ApplyDebit(trans);
                        }
                        else
                        {
                            var trans = new CreditTransaction(val);
                            svc.ApplyCredit(trans);
                        }
                    }
                    catch (ArgumentOutOfRangeException e)
                    {
                        Console.WriteLine(e.Message.Split('\r', '\n')[0]);
                    }
                }
                else
                {
                    Console.WriteLine("Unable to process transaction.");
                }
            }
        }