Пример #1
0
        /// <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();
                }
            }
        }