Пример #1
0
        private async void OnDeleteBankAccount(BankAccount bankAccount)
        {
            if (Deleting())
            {
                try
                {
                    await _bankAccountsService.DeleteBankAccountAsync(bankAccount.BankAccountId);

                    BankAccounts.Remove(bankAccount);
                    Deleted();
                }
                catch (Exception ex)
                {
                    Failed(ex);
                }
            }
        }
Пример #2
0
        //
        ///
        ////
        /////System menu for an account
        static void SystemTray(BankAccount account, BankAccounts accounts, List<Log> eventLog)
        {
            Clear();
            WriteLine("Welcome back " + account.Name + "! Available options: ");
            bool valid = true;
            while (valid)
            {
                WriteLine("1. Transfer money to other account");
                WriteLine("2. Show your credentials");
                WriteLine("3. Delete account");
                WriteLine("4.Exit \n What would you like to do?");
                switch (ReadInt())
                {
                    case 1:
                        if (account != null && account.money > 0)
                        {
                            WriteLine("To what ID do you want to send the money to? ");
                            WriteLine(" ----------------------------------- \n ID List for clarification:");
                            foreach (BankAccount acc in accounts)
                            {
                                WriteLine(acc.id + "\n ---------");
                            }
                            string id = ReadLoginInfo("id");
                            WriteLine("How much money do you want to transfer? ");
                            int tempMoney = int.Parse(ReadLine());
                            double money = tempMoney;                                                                       //DATA WIDENING
                            if (money < account.money)
                            {
                                var found = accounts.FirstOrDefault(c => c.id == id);                                      //LINQ METHOD
                                /* var found = from foundId in accounts
                                   where foundId.id==id
                                   select foundId;*/
                                if (found != null)
                                {
                                    WriteLine("ID found, money transfered.");
                                    account.money = account.money - money;
                                    found.money = found.money + money;
                                    eventLog.Add(new Log { id = account.id, debugTime = DateTime.Now, debug = "Transfered money to other account" });
                                }
                            } else
                            {
                                WriteLine("You don't have that much money.");
                            }
                        }
                        else
                        {
                            WriteLine("You don't have any money to send!");
                        }
                        break;
                    case 2:
                        if (account != null)
                        {
                            Clear();
                            WriteLine("Name: {0}", account.Name);
                            WriteLine("Surname: {0}", account.Surname);
                            WriteLine("Birth date: {0}", account.year);
                            WriteLine("Money: {0}", account.money);
                            eventLog.Add(new Log { id = account.id, debugTime = DateTime.Now, debug = "Showed the credentials of an account" });
                        } else
                        {
                            WriteLine("There is no such account.");
                        }
                        break;
                    case 3:
                        if (account != null && (PermissionTypes.Delete & account.permissions) == PermissionTypes.Delete)
                        {
                            WriteLine("Do you really want to delete this account? Y/N");
                            string temp = ReadLine();
                            switch (temp)
                            {
                                case "Y":
                                    var deleteThis = accounts.SingleOrDefault(c => c.id == account.id);
                                    if (deleteThis != null)
                                    {
                                        eventLog.Add(new Log { id = account.id, debugTime = DateTime.Now, debug = "Deleted account" });
                                        accounts.Remove(acc : deleteThis);                  //NAMED ARGUMENT
                                        account = null;
                                        WriteLine("Deleted successfully!");
                                    }
                                    break;
                                case "N":
                                    Clear();
                                    WriteLine("Account is not deleted.");
                                    break;
                            }
                        }
                        else
                        {
                            WriteLine("You do not have permission to delete account!");
                            Read();
                            Clear();
                        }
                        break;
                    case 4:
                        if(account != null)
                        {
                            eventLog.Add(new Log { id = account.id, debugTime = DateTime.Now, debug = "Logged off" });
                        }

                        valid = false;
                        Clear();
                        break;
                    default:
                        WriteLine("Wrong input!");
                        Read();
                        Clear();
                        break;
                }
            }            
        }
Пример #3
0
 public void RemoveBank(BankAccount obj)
 {
     BankAccounts.Remove(obj);
 }