Esempio n. 1
0
        static void UpdateUser()
        {
            //Update
            string firstNameUpdate, lastNameUpdate, dobUpdate;
            int    id;

            BudgieDBCFModel      context = new BudgieDBCFModel();
            BudgieUserLogic      newUser = new BudgieUserLogic(new BudgieUserRepository(new BudgieDBCFModel()));
            BudgieUserRepository bur     = new BudgieUserRepository(context);
            AccountRepository    ar      = new AccountRepository(context);

            Console.WriteLine(); Console.WriteLine("--- Updating an existing Budgie User ---"); Console.WriteLine();

            UpdatedList();

            Console.WriteLine();

            Console.WriteLine("Please enter the id of the Budgie User you wish to update: ");
            id = Convert.ToInt32(Console.ReadLine());

            //BudgieUser budgieUserToUpdate = context.budgieUsers.Find(id);
            //Account accountToUpdate = context.accounts.Where(a => a.accountOwnerId == id).First();

            Console.WriteLine();

            Console.WriteLine("Updating first name (e.g. Ben): ");
            firstNameUpdate = (Console.ReadLine());
            //budgieUserToUpdate.firstName = firstNameUpdate;

            Console.WriteLine();

            Console.WriteLine("Updating last name (e.g. Bowes): ");
            lastNameUpdate = (Console.ReadLine());
            //budgieUserToUpdate.lastName = lastNameUpdate;

            Console.WriteLine();

            Console.WriteLine("Updating date of birth (e.g. DDMMYY (040191)): ");
            dobUpdate = (Console.ReadLine());
            //budgieUserToUpdate.dob = dobUpdate;

            bur.updateBudgieUser(id, firstNameUpdate, lastNameUpdate, dobUpdate);
            ar.updateNewAccount(id, lastNameUpdate, dobUpdate);
            //accountToUpdate.accountNumber = (lastNameUpdate + dobUpdate);

            Console.WriteLine("The following updates have been made: " + firstNameUpdate + " " + lastNameUpdate + " " + dobUpdate + " Account Number: " + (lastNameUpdate + dobUpdate));
            Console.WriteLine();

            Console.WriteLine("Press any key to save changes and continue: ");
            Console.ReadLine();
            context.SaveChanges();
            RestartApplication();
        }
Esempio n. 2
0
        static void AddUser()
        {
            string firstName, lastName, emailAddress, dob, password, confirmPassword;
            int    newAccountId = 0;

            BudgieDBCFModel      context = new BudgieDBCFModel();
            BudgieUserLogic      newUser = new BudgieUserLogic(new BudgieUserRepository(new BudgieDBCFModel()));
            BudgieUserRepository bur     = new BudgieUserRepository(context);
            AccountRepository    ar      = new AccountRepository(context);

            Console.WriteLine(); Console.WriteLine("--- Creating a new Budgie User ---"); Console.WriteLine();

            Console.WriteLine("Please enter your email address (e.g. [email protected]): ");
            emailAddress = (Console.ReadLine());
            bool isInDatabase = newUser.CheckForDuplicateEmail(emailAddress);

            if (isInDatabase == true)
            {
                Console.WriteLine("This email is already in use, please quit and log into your original account or restart the application and try again.");
            }
            else
            {
                Console.WriteLine();

                Console.WriteLine("Please enter your first name (e.g. Ben): ");
                firstName = (Console.ReadLine());

                Console.WriteLine();

                Console.WriteLine("Please enter your last name (e.g. Bowes): ");
                lastName = (Console.ReadLine());

                Console.WriteLine();

                Console.WriteLine("Please enter your date of birth (e.g. DDMMYY (040191)): ");
                dob = (Console.ReadLine());

                Console.WriteLine();

                Console.WriteLine("Please enter your new password: "******"Please confirm your new password: "******"Your passwords do not match, please restart the application and try again.");
                    Console.WriteLine();
                    RestartApplication();
                }
                else
                {
                    //Add
                    BudgieUser newBudgieUser = new BudgieUser()
                    {
                        firstName = firstName, lastName = lastName, emailAddress = emailAddress, dob = dob, password = password
                    };

                    bur.addNewBudgieUser(newBudgieUser);
                    //context.budgieUsers.Add(newBudgieUser);

                    //context.SaveChanges();

                    Console.WriteLine("New BudgieUser has been successfully registered: Name = " + newBudgieUser.firstName + " " + newBudgieUser.lastName);
                    Console.WriteLine();
                    Console.WriteLine("Automatically creating a new bank account...");
                    Console.WriteLine();

                    foreach (BudgieUser budgieUser in context.budgieUsers)
                    {
                        if (emailAddress == budgieUser.emailAddress)
                        {
                            newAccountId = budgieUser.id;
                        }
                    }

                    Account newAccount = new Account()
                    {
                        accountNumber = lastName + dob, balance = 0, budget = 0, accountOwnerId = newAccountId
                    };

                    ar.addNewAccount(newAccount);
                    //context.accounts.Add(newAccount);

                    Console.WriteLine("Your new account has been successfully created: Account Number = " + newAccount.accountNumber);
                    Console.WriteLine();
                    Console.WriteLine("You may log in and start smart budgeting your finances today! Thank you for joining Budgie.");
                }
            }
            RestartApplication();
        }
 public BudgieUserController()
 {
     userRepo    = new BudgieUserRepository(budgieDBCFModel);
     accountRepo = new AccountRepository(budgieDBCFModel);
     buLogic     = new BudgieUserLogic(userRepo, accountRepo);
 }