static void Main(string[] args)
        {
            // loop to continue until user is done - key q
            string  _input = "";
            UserDTO user   = new UserDTO();
            //bool IsFound = false;
            MockDb db          = new MockDb();
            string _connection = ConfigurationManager.ConnectionStrings["DBCONN"].ToString();
            string _database   = ConfigurationManager.AppSettings["MOCKORDB"].ToString();
            DbAdo  ado         = new DbAdo(_connection);

            Printer.MainMenu();
            _input = Console.ReadLine().ToLower();

            do
            {
                // enter app as a guest
                if (_input.ToLower() == "g")
                {
                    user = new UserDTO(RoleType.Guest);
                }

                if (_input.ToLower() == "pp")
                {
                    Printer.Profile(user);
                }



                if (_input.ToLower() == "pu")
                {
                    List <UserDTO> _users = new List <UserDTO>();;
                    if (_database == DBType.Mock.ToString())
                    {
                        _users = db.GetUsers();
                    }
                    else
                    {
                        // database version
                        _users = ado.GetUsers();
                    }
                    Printer.Users(_users); // TODO: implement this
                }


                if (_input.ToLower() == "pr")
                {
                    // TODO: can I make the configurable??
                    List <RoleDTO> _roles;

                    if (_database == DBType.Mock.ToString())
                    {
                        _roles = db.GetRoles();
                    }
                    else
                    {
                        _roles = ado.GetRoles();
                    }
                    Printer.Roles(_roles); // TODO: implement this
                }

                if (_input.ToLower() == "pm")
                {
                    Printer.MainMenu();
                }

                if (_input.ToLower() == "r") // REGISTER
                {
                    UserDTO u = Printer.CollectAddUserData();
                    if (_database == DBType.Mock.ToString())
                    {
                        db.CreateUser(u);
                    }
                    else
                    {
                        // database version
                        ado.CreateUser(u);
                    }
                }

                //    else if(input.ToLower() == "l") // LOGIN
                //    {
                //        // login method and , where to go next ??

                //        // WHAT ARE THE LOGICAL STEPS FOR LOGGING IN?

                //        // step 1: prompt for username and password
                //        // step 2a: retrieve all users and put that in variable - GetUsers()
                //        // step 2b: loop thru the users list, checking username/password from the list
                //        // step 2c: compare username and password for current element in the loop
                //        // step 2d: if match, log them in and save the info
                //        // step 2f: error message, bad login and prompt to enter again

                //        Console.WriteLine("Enter your username: "******"Enter your password: "******"Match found. Welcome {0} {1}. Your Role is {2}.", loginInUser.FirstName,
                //                    loginInUser.LastName, loginInUser.Role.RoleName);
                //                IsFound = true;
                //            }
                //        }

                //        if (IsFound == false) {
                //            Console.WriteLine("User incorrect. Try again.");
                //        }

                //        // depending on the Role, we will want to provide a custom set of menu options
                //        // PATRON - least privileges
                //        // CHECKOUT STUFF
                //        // menu - search, update my profile, logout
                //        if (loginInUser.RoleID_FK == (int)Roles.Patron) // PATRON ROLE
                //        {
                //            Console.WriteLine("MENU: S - Search, P - My Profile, O - Logout");
                //            string inputPatron = Console.ReadLine();
                //            if (inputPatron.ToLower() == "o")
                //            {
                //                IsFound = false; // without this - a bug that caused an infinite loop
                //                Console.WriteLine("Logging out .... Bye {0} {1}", loginInUser.FirstName, loginInUser.LastName);
                //                continue;
                //            }
                //            else
                //            {
                //                Printer.PatronOptions(inputPatron, loginInUser);
                //            }
                //        }
                //        else if(loginInUser.RoleID_FK == (int)Roles.Librarian) // LIBRARIAN ROLE
                //        {

                //            Console.WriteLine("MENU: S - Search, P - My Profile,  B - Book, A - Author, " +
                //                " P - Publisher, G - Genre, O - Logout");
                //            string inputLibrarian = Console.ReadLine();
                //            if (inputLibrarian.ToLower() == "o")
                //            {
                //                IsFound = false; // without this - a bug that caused an infinite loop
                //                Console.WriteLine("Logging out .... Bye {0} {1}", loginInUser.FirstName, loginInUser.LastName);
                //                continue;
                //            }
                //            else
                //            {
                //                Printer.LibrarianOptions(inputLibrarian, loginInUser);
                //            }
                //        }
                //        else if (loginInUser.RoleID_FK == (int)Roles.Administrator) // ADMINISTRATOR ROLE
                //        {
                //            Console.WriteLine("MENU: S - Search, P - My Profile,  B - Book, A - Author, " +
                //                " P - Publisher, G - Genre, U - User, O - Logout");
                //            string inputAdmin = Console.ReadLine();
                //            if (inputAdmin.ToLower() == "o")
                //            {
                //                IsFound = false; // without this - a bug that caused an infinite loop
                //                Console.WriteLine("Logging out .... Bye {0} {1}", loginInUser.FirstName, loginInUser.LastName);
                //                continue;
                //            }
                //            else
                //            {
                //                Printer.AdminOptions(inputAdmin, loginInUser);
                //            }
                //        }

                //        // ADMINSTRATOR - most privieges
                //        // CHANGE PASSWORD, RESETTING STUFF
                //        // menu - search, update my profile, Book, Publisher, Genre, Users  logout
                //    }

                Printer.MainMenu();
                _input = Console.ReadLine().ToLower();
            } while (_input.ToLower() != "q");

            Printer.End();
            Console.ReadLine();     // stop program
        }
Exemple #2
0
 // Constructor
 public UnitTestDbAdo()
 {
     _conn  = this.GetConnectionString();
     _dbado = new DbAdo(_conn); //
 }