示例#1
0
        public static bool CardAmountIsEnough(CardAccount account, decimal requestedAmount)
        {
            var cardAmount = account.CardCash;

            if (cardAmount < requestedAmount)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public static bool CardNumberAndPinAreValid(CardAccount account, string pin, string number)
        {
            var cardPin    = account.CardPIN;
            var cardNumber = account.CardNumber;

            if (pin == cardPin && number == cardNumber)
            {
                return(true);
            }

            return(false);
        }
示例#3
0
        public static void WithdrawMoney(CardAccount account, string pin, string cardNumber, decimal requestedAmount)
        {
            var context     = new ATMEntities();
            var transaction = context.Database.BeginTransaction();

            if (!CardNumberAndPinAreValid(account, pin, cardNumber))
            {
                transaction.Rollback();
                throw new InvalidOperationException("Card PIN and number are invalid!");
            }

            if (!CardAmountIsEnough(account, requestedAmount))
            {
                transaction.Rollback();
                throw new InvalidOperationException("Not enough amount!");
            }

            account.CardCash -= requestedAmount;
            LogTransaction(cardNumber, requestedAmount);
            transaction.Commit();
            Console.WriteLine("Withdrawal complete.");
        }