/// <summary> /// Make transaction. /// </summary> public void PayBills() { using (BillsPaymentSystemContext context = new BillsPaymentSystemContext()) { while (true) { try { Console.Clear(); outputProvider.DrawFrame(2); outputProvider.PayBills(); var data = inputProvider.ReadUserData(); if (data[0] < 0 || data[0] > context.Users.Count()) { throw new Exception(Strings.InvalidInput((int)data[0])); } var selectedUser = new SelectedUser(data); Console.CursorVisible = false; var currentUser = selectedUser.UserData(context); var bankAccounts = selectedUser.BankAcountData(context); var creditCards = selectedUser.CreditCardData(context); if (bankAccounts.Sum(x => x.Balance) + creditCards.Sum(x => x.Limit - x.MoneyOwed) < selectedUser.Amount) { throw new Exception(Strings.InvalidInput()); } outputProvider.StartWaiting(); Withdraw(context, bankAccounts, creditCards, selectedUser.Amount); outputProvider.Done(); break; } catch (Exception e) { outputProvider.ShowException(e.Message); if (inputProvider.Key() == ConsoleKey.Enter) { continue; } } } if (inputProvider.Key() == ConsoleKey.Enter) { var inputComander = new InputComander(); inputComander.StartReading(); } } }
/// <summary> /// Show user info. /// </summary> public void ShowUserByID() { using (BillsPaymentSystemContext context = new BillsPaymentSystemContext()) { Console.Clear(); outputProvider.DrawFrame(2); outputProvider.SelectUser(); while (true) { try { Console.Clear(); outputProvider.DrawFrame(2); outputProvider.SelectUser(); int ID = inputProvider.ReadNumber(); if (ID < 0 || ID > context.Users.Count()) { throw new Exception(Strings.InvalidInput(ID)); } var selectedUser = new SelectedUser(ID); Console.CursorVisible = false; var currentUser = selectedUser.UserData(context); var bankAccounts = selectedUser.BankAcountData(context); var creditCards = selectedUser.CreditCardData(context); outputProvider.PrintUserData(currentUser, bankAccounts, creditCards); break; } catch (Exception e) { outputProvider.ShowException(e.Message); if (inputProvider.Key() == ConsoleKey.Enter) { continue; } } } if (inputProvider.Key() == ConsoleKey.Enter) { var inputComander = new InputComander(); inputComander.StartReading(); } } }