Ejemplo n.º 1
0
 //
 ///
 ////
 /////Registration blank to register new account
 private static void Registration(BankAccounts accounts, List<Log> eventLog)  
 {
     BankAccount account = new BankAccount();
     Write("Please enter your first name: ");
     account.Name = ReadCredentials().UppercaseFirstLetter();
     Write("Please enter your last name: ");
     account.Surname = ReadCredentials().UppercaseFirstLetter(); //EXTENTION METHOD
     Write("Please enter your birth date dd-mm-yyyy: ");
     account.year = ReadDate();
     Random rnd = new Random();
     account.id = RandomNumber(rnd, 10000, 100000);
     account.pass = RandomNumber(rnd, 100000, 1000000);
     WriteLine($"Your id is: {0}", account.id);
     WriteLine($"Your password is: {account.pass}");
     account.GiveMoney();                                        //OPTIONAL ARGUMENT
     WriteLine("Please save this information!");
     if (account.Name == "admin" || account.Name == "Admin")
     {
         GivePermissions("admin", account);
     }
     else
     {
         GivePermissions("normal", account);
     }
     accounts.Add(account);
     eventLog.Add(new Log { id = account.id, debugTime = DateTime.Now, debug = "Registered new account" });
     Read();
 }
Ejemplo n.º 2
0
        //Add account
        public void AddAccount(BankAccount accountToAdd)
        {
            var addAccount = (
               from account in this.accounts
               where account.AccountNumber == accountToAdd.AccountNumber
               select account).ToList();

            if (addAccount.Count != 0)
            {
                throw new ArgumentException(String.Format("Account with ID: {0} already exists in the system!", accountToAdd.AccountNumber));
            }
            if (!this.customers.Contains(accountToAdd.Owner))
            {
                this.AddCustomer(accountToAdd.Owner);
            }
            this.accounts.Add(accountToAdd);
            OnAccountOperation(new AccountOpperationsEventArgs(accountToAdd.AccountNumber, accountToAdd.Owner.CustomerID, "ADD",
                                                               accountToAdd.GetType().Name));
        }
Ejemplo n.º 3
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;
                }
            }            
        }
Ejemplo n.º 4
0
        //
        ///
        ////
        /////Reads account information from files

        static void GetAccountInformation(BankAccounts accounts)
        {
            string temp = "accounts.txt";
            if (!File.Exists(temp))
            {
                File.Create(temp);
            }
            else
            {
                using (StreamReader file = new StreamReader("accounts.txt"))
                {

                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        var words = line.Split(' ');
                        var account = new BankAccount
                        {
                            Name = words[0],
                            Surname = words[1],
                            year = words[2],
                            id = words[3],
                            pass = words[4],
                            money = Convert.ToDouble(words[5])
                        };
                        if (words[0] == "Admin" || words[1] == "Admin")
                        {
                            GivePermissions("Admin", account);
                        }
                        else
                        {
                            GivePermissions("normal", account);
                        }
                        accounts.Add(account);
                    }
                }
                    //file.Close();
            }
        }
Ejemplo n.º 5
0
        //
        ///
        ////
        /////Function to give certain permissions to an account

        static void GivePermissions(string value, BankAccount account)
        {
            switch (value)
            {
                case "Normal":
                case "normal":
                    account.permissions = PermissionTypes.Read | PermissionTypes.Write;
                    break;
                case "Admin":
                case "admin":
                    account.permissions = PermissionTypes.All;
                    break;
                default:
                    WriteLine("Something's wrong");
                    break;
            }
        }