private static void Transfer(ATMContext db) { userName = Read("Enter the name of the account you would like to transfer to: "); bool userNameTrue = db.UserInfo.Any(u => u.Username == (userName)); while (userNameTrue == false) { Console.WriteLine("That user does not exist."); userName = Read("Enter the name of the account you would like to transfer to: "); userNameTrue = db.UserInfo.Any(u => u.Username == (userName)); } userInstance = db.UserInfo.Where(x => x.Username == userName).First(); balanceInfo = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First(); double balanceTransfer = balanceInfo.Balance; var deposit = Read("How much would you like to Transfer?: "); double depositAmount = int.Parse(deposit); double newBalanceTransferTO = depositAmount + balanceTransfer; AccountInfo accountInfo = new AccountInfo { Balance = newBalanceTransferTO, Deposit = depositAmount, UserInfo = userInstance, DateTime = DateTime.Now, }; db.AccountInfo.Add(accountInfo); db.SaveChanges(); Console.WriteLine("Please verify your account information to make the transfer."); UserLogin(db); double balance = balanceInfo.Balance; var withdraw = deposit; double withdrawAmount = int.Parse(withdraw); double newBalance; if (withdrawAmount > balance) { Console.WriteLine("You overdrew your account. You will be charged a $15 fee."); double overdrawnBalance = withdrawAmount + 15; newBalance = balance - overdrawnBalance; } else { newBalance = balance - withdrawAmount; } AccountInfo accountInfo2 = new AccountInfo { Balance = newBalance, Withdraw = withdrawAmount, UserInfo = userInstance, DateTime = DateTime.Now, }; db.AccountInfo.Add(accountInfo2); db.SaveChanges(); Console.WriteLine($" Your new account balance is ${newBalance}"); Pause(); }
private void Cash_card_btn_Click(object sender, RoutedEventArgs e) { try { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ATMContext"]; using (ATMContext context = new ATMContext(settings.ConnectionString)) { int money = Convert.ToInt32(TextBox.Text); CardCash cardCash = new CardCash(); string tB = TextBox.Text; if (tB == "10" || tB == "50" || tB == "100" || tB == "200" || tB == "500" || tB == "1000") { var x = context.CardCash.Single(x => x.CardID == _cardId); if (x.Cash > money) { x.Cash -= money; context.SaveChanges(); MessageBox.Show("Выдача денег"); TextBox.Text = ""; } else { MessageBox.Show($"На карт не достаточно средств!\n Баланс на карте: {cardAtmRepository.GetBalanse(_cardId)}"); } } else { MessageBox.Show("Банкомат может выддат только 10,50,100,200,500,1000"); } } } catch (Exception) { } }
private static void Withdraw(ATMContext db) { userInstance = db.UserInfo.Where(x => x.Username == userName).First(); balanceInfo = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First(); double balance = balanceInfo.Balance; var withdraw = Read("How much would you like to withdraw? : "); double withdrawAmount = int.Parse(withdraw); double newBalance; if (withdrawAmount > balance) { Console.WriteLine("You overdrew your account. You will be charged a $15 fee."); double overdrawnBalance = withdrawAmount + 15; newBalance = balance - overdrawnBalance; } else { newBalance = balance - withdrawAmount; } AccountInfo accountInfo = new AccountInfo { Balance = newBalance, Withdraw = withdrawAmount, UserInfo = userInstance, DateTime = DateTime.Now, }; db.AccountInfo.Add(accountInfo); db.SaveChanges(); Console.WriteLine($" Your new account balance is ${newBalance}"); }
public void CreateCard() { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ATMContext"]; using (ATMContext context = new ATMContext(settings.ConnectionString)) { Card card = new Card(); card.Number = "1234528415234582"; context.Cards.Add(card); context.SaveChanges(); PINCode pin = new PINCode(); pin.CardID = 1; pin.Code = GetCodeHash("1234"); context.PINCodes.Add(pin); context.SaveChanges(); } }
public void SetCardToRemote(string cardNumber) { RemoteCard card = new RemoteCard(); card.Number = cardNumber; _context.RemoteCards.Add(card); _context.Cards.Remove(_context.Cards.Single(x => x.Number == cardNumber)); _context.SaveChanges(); }
private static void AccountCreation(ATMContext db) { AccountInfo accountInfo = new AccountInfo { Balance = 0, Withdraw = 0, Deposit = 0, DateTime = DateTime.Now, UserInfo = userInstanceNewAcc, }; db.AccountInfo.Add(accountInfo); db.SaveChanges(); }
private static void Deposit(ATMContext db) { userInstance = db.UserInfo.Where(x => x.Username == userName).First(); balanceInfo = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First(); double balance = balanceInfo.Balance; var deposit = Read("How much would you like to Deposit? : "); double depositAmount = int.Parse(deposit); double newBalance; newBalance = depositAmount + balance; AccountInfo accountInfo = new AccountInfo { Balance = newBalance, Deposit = depositAmount, UserInfo = userInstance, DateTime = DateTime.Now, }; db.AccountInfo.Add(accountInfo); db.SaveChanges(); Console.WriteLine($" Your new account balance is ${newBalance}"); }
private static void NewUser(ATMContext db) { var userName = Read("Enter a new username: "******"That Username is already taken."); userName = Read("Enter a new username: "******"Enter a password: "); UserInfo userInfo = new UserInfo { Username = userName, Password = password, JoinDateTime = DateTime.Now, }; db.UserInfo.Add(userInfo); db.SaveChanges(); userInstanceNewAcc = db.UserInfo.Where(x => x.Username == userName).First(); }