private static void MakeWithdrawTransaction(string cardNumber, string pinNumber, decimal amountOfMoney, bool transactionContinue) { if (transactionContinue) { ATMEntities db = new ATMEntities(); using (db) { using (TransactionScope withdrawTransaction = new TransactionScope()) { var bankAccount = (from a in db.CardAccounts where a.CardNumber == cardNumber && a.CardPIN == pinNumber select a).First(); if (bankAccount == null) { Console.WriteLine("Wrong Account Data!!!"); } else if (bankAccount.CardCash < amountOfMoney) { Console.WriteLine("Insufficient amount of money!!!"); } else { bankAccount.CardCash -= amountOfMoney; db.SaveChanges(); AddTransactionRecord(cardNumber, amountOfMoney, db); withdrawTransaction.Complete(); Console.WriteLine("Transaction successful!"); } } } } else { Console.WriteLine("Transaction failure!!!"); } }
private static void AddTransactionRecord(string cardNumber, decimal amountOfMoney, ATMEntities db) { using (TransactionScope recordTransacion = new TransactionScope()) { var newTransactionRecord = new TransactionsHistory() { CardNumber = cardNumber, TransactionDate = DateTime.Now, Ammount = amountOfMoney }; db.TransactionsHistories.Add(newTransactionRecord); db.SaveChanges(); recordTransacion.Complete(); } }