private static decimal? CardAmount(string cardNumber) { decimal? moneyAmount; using (ATMEntities db = new ATMEntities()) { moneyAmount = db.CardAccounts.Where(x => cardNumber != null && x.CardNumber == cardNumber).Select(a => a.CardCash).First(); } return moneyAmount; }
private static bool CardValidation(string cardNumber, string cardPin) { bool isValid; using (ATMEntities db = new ATMEntities()) { bool isCardNumberValid = db.CardAccounts.Any(a => a.CardNumber == cardNumber); bool isCardPinValid = db.CardAccounts.Any(b => b.CardPIN == cardPin); if (isCardNumberValid && isCardPinValid) { isValid = true; } else { isValid = false; } } return isValid; }
private static void WithdrawTransfer(string cardNumber, string cardPin, decimal moneyValue) { using (ATMEntities db = new ATMEntities()) { var account = db.CardAccounts.FirstOrDefault(x => x.CardNumber == cardNumber && x.CardPin == cardPin); account.CardCash = account.CardCash - moneyValue; DateTime transactionDate = DateTime.Now; Console.WriteLine("Successful, remaining availability: {0}", account.CardCash); TransactionsHistory currentTransaction = new TransactionsHistory() { Id = account.Id, CardNumber = cardNumber, Ammount = account.CardCash, TransactionDate = transactionDate }; db.TransactionsHistories.Add(currentTransaction); db.SaveChanges(); } }