public static bool CardAmountIsEnough(CardAccount account, decimal requestedAmount) { var cardAmount = account.CardCash; if (cardAmount < requestedAmount) { return(false); } return(true); }
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); }
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."); }