public static bool CheckOrderDateTime(Plocation location, Puser user) { List <Porder> orders = new Crud().GetOrders(); for (int i = orders.Count - 1; i >= 0; i--) { if (orders[i].PUser.PUserId == user.PUserId) //Extract the latest Order by the user { DateTime now = DateTime.Now; DateTime datetime = DateTime.Parse(orders[i].PDate + " " + orders[i].PTime); if (orders[i].CLocationId != location.LocationId) //Checks NOT Location { if ((now - datetime).TotalHours <= 24) //Checks within 24 hours period { return(false); } } if (orders[i].CLocationId == location.LocationId) //Checks YES Location { if ((now - datetime).TotalHours <= 2) //Checks within 2 hours period { return(false); } } } } return(true); }
public static bool InsertUser(string firstName, string lastName, string username, string password, string email, string street, string city, string state, string zipcode) { bool inserted = LocationHandler.InsertLocation(street, city, state, zipcode); List <Plocation> locations = LocationHandler.GetLocationData(); if (inserted == true) { Puser user = new Puser { Firstname = firstName, Lastname = lastName, Username = username, PPassword = password, Email = email, LocationId = locations[locations.Count - 1].LocationId }; int icount = new Crud().AddUser(user); if (icount == 0) { return(false); } } else { return(false); } return(true); }
public static Puser ValidateUser(string username, string password) { Puser user = GetUser(username); if (user != null && user.PPassword.Equals(password)) { return(user); } return(null); }
private static void DisplayMainOption(Puser user) { if (isEmployee) { IUserView userView = new AdministratorView(); //Polymorphism userView.displayView(user); } else { IUserView userView = new CustomerView(); //Polymorphism userView.displayView(user); } }
internal static void DisplayUserDetails(Puser user) { isEmployee = UserHandler.CheckIfEmployee(user); string userType = !isEmployee ? "Customer" : "Employee"; Console.WriteLine(); Console.WriteLine($" First Name: {user.Firstname}"); Console.WriteLine($" Last Name: {user.Lastname}"); Console.WriteLine($" Email: {user.Email}"); Console.WriteLine($" User Type: {userType}"); DisplayMainOption(user); }
private bool SignInUser(ref Puser user1) { string username = base.GetInput(" Type in your username: "******" Type in your password: "); Console.WriteLine(); Puser user = UserHandler.ValidateUser(username, password); user1 = user; return((user != null) ? true : false); }
public void displayView(Puser user) { this.user = user; MainOptions(); switch (option - 1) { case (int)menuCustomerConst.Order: { CustomerLocation(); bool validateDate = OrderHandler.CheckOrderDateTime(location, user); if (validateDate == true) { CustomerPizzas(); CustomerOrder(); } else { Console.WriteLine("Can't Order From another Location within 24 hours"); Console.WriteLine("Pls Choose another location:"); displayView(user); listCount = 1; } break; } case (int)menuCustomerConst.View: { List <Porder> orders = OrderHandler.GetOrders(); OrderView.DisplayOrders(orders); break; } } }
public void AuthenticateUser() { int option = 0; Console.WriteLine(); Console.WriteLine(" Enter (1) to Sign in or (2) to Sign Up if you dont an account with us:"); do { Console.WriteLine(); option = base.GetValidatedOption(2); } while (option == -1); switch (option - 1) { case (int)authOptions.signIn: { bool validateLogin = false; Puser user = null; do { Console.WriteLine(); validateLogin = SignInUser(ref user); } while (!validateLogin); MainView.DisplayUserDetails(user); break; } case (int)authOptions.signUp: { SignUpView signUp = new SignUpView(); signUp.SignUpUser(); break; } } }
public static bool CheckIfEmployee(Puser user) { return(new Crud().GetEmployee(user) != null ? true : false); }
public void displayView(Puser user) { this.user = user; Console.WriteLine("===================== ADMINISTRATOR =================="); Console.WriteLine(); Console.WriteLine($"Choose from the options below from 1 to {menuAdmin.Length}"); Console.WriteLine(); int listCount = 1; int option; for (int i = 0; i < menuAdmin.Length - 1; listCount++, i++) { Console.WriteLine($" ({listCount}) \t {menuAdmin[i]}"); } Console.WriteLine(); do { option = base.GetValidatedOption(menuAdmin.Length - 1); } while (option == -1); //Load Locations from domainusing List <Plocation> locations = LocationHandler.GetLocationData(); switch (option - 1) { case (int)menuAdminConst.Stores: { LocationView.DisplayLocationsOptions(locations); break; } case (int)menuAdminConst.Pizzas: { LocationView.DisplayLocationsOptions(locations); do { option = base.GetValidatedOption(locations.Count - 1); } while (option == -1); //Load Pizzas from domain List <Pizza> pizzas = PizzaHandler.GetPizzasFromLocation(locations[option - 1]); //Display pizzas PizzaView.DisplayPizzas(pizzas); break; } case (int)menuAdminConst.Order: { List <Porder> orders = OrderHandler.GetOrders(); OrderView.DisplayOrders(orders); break; } case (int)menuAdminConst.Customer: { List <Customer> customers = CustomerHandler.GetCustomers(); CustomerDetailsView.DisplayCustomerDetails(customers); break; } case (int)menuAdminConst.Sales: { break; } case (int)menuAdminConst.Users: { List <Puser> users = UserHandler.GetUsers(); UserDetailsView.DisplayUserDetails(users); break; } } string option1; do { option1 = base.GetInput("Type in YES to continue or NO to quit. "); if (option1.ToLower().Equals("yes")) { displayView(user); } else if (option1.ToLower().Equals("no")) { Console.WriteLine("Thank you for choosing PizaBox"); Environment.Exit(0); } else { Console.WriteLine("Incorrect Option, pls try again."); Console.WriteLine(); } } while (option1.ToLower().Equals("yes") || option1.ToLower().Equals("no")); Console.WriteLine(); }