public UserViewModel(PizzaStoreDBContext dbo) { var UF = new UserFactory(); User = UF.Create(); _db = dbo; }
public static CustomerRepository LoginPrompt(CustomerRepository customer, PizzaStoreDBContext dbContext) { System.Console.WriteLine("1. Sign in"); System.Console.WriteLine("2. Create new account"); string signInInput; do { signInInput = System.Console.ReadLine().ToLower(); if (signInInput != "1" && signInInput != "2") { System.Console.WriteLine("Invalid input. Please try again."); } } while (signInInput != "1" && signInInput != "2"); if (signInInput == "1") { customer = customer.SignIn(dbContext); } else if (signInInput == "2") { customer = customer.NewUser(dbContext); } return(customer); }
public void SetCurrentUser(PizzaStoreDBContext _db) { var UR = new UserRepository(_db); User.CurrentUser = true; UR.Add(User); }
public OrderController(PizzaStoreDBContext dbContext, OrderRepo orderRepo, CartViewModel cart, UserManager <IdentityUser> userMnger) { _context = dbContext; _orderRepo = orderRepo; _cart = cart; _userMnger = userMnger; }
public StoreViewModel(PizzaStoreDBContext dbo) { var SF = new StoreFactory(); Store = SF.Create(); _db = dbo; }
public void SetCurrentStore(PizzaStoreDBContext _db) { var SR = new StoreRepository(_db); Store.CurrentStore = true; SR.Add(Store); }
public StoreController(StoreViewModel store, PizzaStoreDBContext DBContext, StoreRepo StoreRepo, LocationsRepo LocationRepo) { _DBContext = DBContext; _store = store; _LocationRepo = LocationRepo; _StoreRepo = StoreRepo; }
public LocationRepository(PizzaStoreDBContext database) { Database = database ?? throw new ArgumentNullException(nameof(database)); Database.Database.EnsureCreated(); inventoryRepo = new InventoryJunctionRepository(Database); }
private static void CreateAdminRole(PizzaStoreDBContext DBContext, RoleManager <IdentityRole> _mnger, UserManager <IdentityUser> _User) { bool roleExists = _mnger.RoleExistsAsync("Admin").Result; if (roleExists) { return; } var role = new IdentityRole() { Name = "Admin" }; _mnger.CreateAsync(role).Wait(); var user = new IdentityUser() { UserName = "******", Email = "*****@*****.**" }; string adminPassword = "******"; var userResult = _User.CreateAsync(user, adminPassword).Result; if (userResult.Succeeded) { _User.AddToRoleAsync(user, "Admin").Wait(); } }
public static void InitializeMapper(PizzaStoreDBContext database) { Database = database ?? throw new ArgumentNullException(nameof(database)); inventoryRepo = new dbr.InventoryJunctionRepository(database); ingredientRepo = new dbr.IngredientRepository(database); orderJunctionRepo = new dbr.OrderJunctionRepository(database); pizzaRepo = new dbr.PizzaJunctionRepository(database); }
public OrderRepository(PizzaStoreDBContext database) { Database = database ?? throw new ArgumentNullException(nameof(database)); orderJunctionRepo = new OrderJunctionRepository(database); pizzaJunctionRepo = new PizzaJunctionRepository(database); Database.Database.EnsureCreated(); }
public static void DisplayPizzas(PizzaStoreDBContext dbContext) { Console.WriteLine("1. Cheese"); Console.WriteLine("2. Pepperoni"); Console.WriteLine("3. Meat Lovers"); Console.WriteLine("4. Veggie"); Console.WriteLine("5. Hawaiian"); Console.WriteLine("6. Golden Sun"); }
public static void DisplayLocations(PizzaStoreDBContext dbContext) { using (dbContext) { foreach (var item in dbContext.Location) { System.Console.WriteLine($"{item.Id}. {item.Name}"); } } }
public Startup(IConfiguration configuration) { Configuration = configuration; var options = new DbContextOptionsBuilder <PizzaStoreDBContext>() .UseSqlServer(Configuration.GetConnectionString("MVCPizzaStore")).Options; var database = new PizzaStoreDBContext(options); db.Mapper.InitializeMapper(database); SyncAllFromDatabase(database); }
public void ConvertDelete(PizzaStoreDBContext db) { var PR = new PizzaRepository(db); foreach (var p in Pizzas) { if (p.IsSelected) { PR.Remove(p.Id); } } }
public void Reload() { using (PizzaStoreDBContext context = (PizzaStoreDBContext)PSDBContextProvider.Current.NewPSDBContext) { // probably a lot of wasted time here Locations = context.Pslocation.Select(l => new Location(l)).ToList(); Users = context.Psuser.Include(u => u.DefaultLocation).ToList() .Select(u => new User(u, Locations.First(l => l.Dao.LocationId == u.DefaultLocationId))).ToList(); Orders = context.Psorder.Include(o => o.Location).Include(o => o.User).Include(o => o.PsorderPart).ToList() .Select(o => new Order(o, Locations.First(l => l.Dao.LocationId == o.Location.LocationId), Users.First(u => u.Dao.UserId == o.User.UserId))).ToList(); } }
public static void Initialize(PizzaStoreDBContext DBContext, IServiceProvider serviceProvider) { DBContext.Database.EnsureCreated(); if (DBContext.Pizza.Any()) { return; } ClearDatabase(DBContext); // CreateAdminRole(DBContext); SeedDB(DBContext); }
public void ConvertSpecial(PizzaViewModel pizzaViewModel, PizzaStoreDBContext _db) { var CR = new CrustRepository(_db); var SR = new SizeRepository(_db); var PR = new PizzaRepository(_db); var TR = new ToppingRepository(_db); var OR = new OrderRepository(_db); var UR = new UserRepository(_db); var STR = new StoreRepository(_db); var PF = new PizzaFactory(); var tempSpecialty = PF.Create(); tempSpecialty = PR.Get(SelectedPizza); var tempPizza = PF.Create(); tempPizza.Name = SelectedPizza; tempPizza.Description = tempSpecialty.Description; tempPizza.Size = SR.Get(pizzaViewModel.Size); tempPizza.Crust = CR.Get(pizzaViewModel.Crust); tempPizza.Toppings = new List <ToppingsModel>(); tempPizza.SpecialPizza = true; foreach (var t in tempSpecialty.Toppings) { var tempTopping = new ToppingsModel() { Name = t.Name, Description = t.Description }; tempPizza.Toppings.Add(tempTopping); TR.Add(tempTopping); } var cart = OR.GetCurrentOrder(); var OF = new OrderFactory(); if (cart != null) { OR.AddPizza(cart.Id, tempPizza); } else { cart = OF.Create(); cart.Pizzas.Add(tempPizza); cart.CurrentOrder = true; OR.UpdateCurrentOrder(cart); var tempUser = UR.Get(User); UR.AddOrder(tempUser.Id, cart); var tempStore = STR.Get(Store); STR.AddOrder(tempStore.Id, cart); } }
public static void SyncAllFromDatabase(PizzaStoreDBContext database) { // Order here matters. Sync.IngredientProcessor.Initialize(database); Sync.IngredientProcessor.SyncFromDatabase(); // Location needs to know what ingredients are availabe Sync.LocationProcessor.Initialize(database); Sync.LocationProcessor.SyncFromDatabase(); Sync.UserProcessor.Initialize(database); Sync.UserProcessor.SyncFromDatabase(); Sync.OrderProcessor.Initialize(database); Sync.OrderProcessor.SyncFromDatabase(); }
public void GetCart(PizzaStoreDBContext _db) { var OF = new OrderFactory(); var OR = new OrderRepository(_db); var cart = OR.GetCurrentOrder(); if (cart != null) { Cart = cart; } else { Cart = OF.Create(); OR.Add(Cart); } }
public CustomerRepository SignIn(PizzaStoreDBContext dbContext) { string customerName; string pass; while (true) { do { Console.WriteLine("Please enter your username:"******"Username cannot be empty."); } } while (customerName.Length == 0); do { Console.WriteLine("Please enter your password:"******"Password cannot be empty."); } } while (pass.Length == 0); try { if (dbContext.Customer.First(u => u.UserName == customerName && u.Password == pass) != null) { break; } } catch { Console.WriteLine("Either your username or password is incorrect. Please try again."); } } Customer customerInfo = dbContext.Customer.First(u => u.UserName == customerName && u.Password == pass); CustomerRepository customerObj = DBContextToObj(customerInfo); return(customerObj); }
public PizzaViewModel(PizzaStoreDBContext dbo) { var cRepo = new CrustRepository(dbo); Crusts = cRepo.GetAll(); var sRepo = new SizeRepository(dbo); Sizes = sRepo.GetAll(); var tRepo = new ToppingRepository(dbo); Toppings = new List <ToppingsModel>(); Toppings2 = new List <CheckBoxTopping>(); foreach (ToppingsModel t in tRepo.GetAll()) { Toppings.Add(t); } foreach (var t in Toppings) { Toppings2.Add(new CheckBoxTopping() { Name = t.Name, Id = t.Id, Description = t.Description, Text = t.Name, IsSelected = false }); } var uRepo = new UserRepository(dbo); Users = uRepo.GetAll(); var stRepo = new StoreRepository(dbo); Stores = stRepo.GetAll(); var pRepo = new PizzaRepository(dbo); SpecialtyPizzas = pRepo.GetAllSpecialty(); Pizzas = new List <CheckBoxPizza>(); GetCart(dbo); if (Cart.Pizzas != null) { foreach (PizzaModel p in Cart.Pizzas) { Pizzas.Add(new CheckBoxPizza() { Name = p.Name, Id = p.Id, Description = p.Description, Text = p.Name, IsSelected = false }); } } }
public CustomerWeb SignIn(PizzaStoreDBContext dbContext) { string userName; string password; while (true) { do { Console.WriteLine("Please enter your username:"******"Username cannot be empty."); } } while (userName.Length == 0); do { Console.WriteLine("Please enter your password:"******"Password cannot be empty."); } } while (password.Length == 0); try { var customer = dbContext.Customer.First(u => u.UserName == userName && u.Password == password).ToString(); break; } catch { Console.WriteLine("Either your username or password is incorrect. Please try again."); } } Customer customerInfo = dbContext.Customer.First(u => u.UserName == userName && u.Password == password); CustomerWeb customerObj = Mapper.Map(customerInfo); return(customerObj); }
public static int PickPizza(PizzaStoreDBContext dbContext) { int pizzaInputInt; DisplayPizzas(dbContext); while (true) { System.Console.WriteLine("Select a pizza to order:"); string pizzaInputStr = System.Console.ReadLine(); //try converting string to int try { pizzaInputInt = Convert.ToInt32(pizzaInputStr); break; } catch { System.Console.WriteLine("Invalid input."); } } return(pizzaInputInt); }
private static void ClearDatabase(PizzaStoreDBContext _DBContext) { var pizzaTopping = _DBContext.PizzaToppings.ToList(); _DBContext.PizzaToppings.RemoveRange(pizzaTopping); var topping = _DBContext.Toppings.ToList(); _DBContext.Toppings.RemoveRange(topping); var Cart = _DBContext.cart.ToList(); _DBContext.cart.RemoveRange(Cart); var orders = _DBContext.order.ToList(); _DBContext.order.RemoveRange(orders); var pizzas = _DBContext.Pizza.ToList(); _DBContext.Pizza.RemoveRange(pizzas); _DBContext.SaveChanges(); }
public PizzasController(PizzaStoreDBContext context) { _context = context; }
public ViewModelOrderPizzaController(PizzaStoreRepository repo, PizzaStoreDBContext context) { Repo = repo; _context = context; }
public void FinishOrder(PizzaStoreDBContext _db) { var OR = new OrderRepository(_db); OR.UpdateCurrentOrder(); }
public void ConvertRegular(PizzaViewModel pizzaViewModel, PizzaStoreDBContext _db) { var UR = new UserRepository(_db); var STR = new StoreRepository(_db); var OR = new OrderRepository(_db); var CR = new CrustRepository(_db); var SR = new SizeRepository(_db); var PR = new PizzaRepository(_db); var TR = new ToppingRepository(_db); var PF = new PizzaFactory(); List <ToppingsModel> TM = new List <ToppingsModel>(); SelectedToppings = new List <CheckBoxTopping>(); foreach (var t in Toppings2) { if (t.IsSelected) { SelectedToppings.Add(t); } } foreach (var t in SelectedToppings) { var throwaway = TR.Get(t.Text); var tempTopping = new ToppingsModel() { Name = throwaway.Name, Description = throwaway.Description }; TM.Add(tempTopping); } //TM.Add(TR.Get(Topping)); var tempPizza = PF.Create(); tempPizza.Name = "custom"; tempPizza.Description = "custom"; tempPizza.Size = SR.Get(pizzaViewModel.Size); tempPizza.Crust = CR.Get(pizzaViewModel.Crust); tempPizza.Toppings = new List <ToppingsModel>(); tempPizza.Toppings = TM; tempPizza.SpecialPizza = false; var cart = OR.GetCurrentOrder(); var OF = new OrderFactory(); if (cart != null) { OR.AddPizza(cart.Id, tempPizza); } else { cart = OF.Create(); cart.Pizzas = new List <PizzaModel>(); cart.Pizzas.Add(tempPizza); cart.CurrentOrder = true; OR.UpdateCurrentOrder(cart); var tempUser = UR.Get(User); UR.AddOrder(tempUser.Id, cart); var tempStore = STR.Get(Store); STR.AddOrder(tempStore.Id, cart); } }
/// <summary> /// Initializes a new restaurant repository given a suitable Entity Framework DbContext. /// </summary> /// <param name="db">The DbContext</param> public PizzaStoreRepository(PizzaStoreDBContext db) { _db = db ?? throw new ArgumentNullException(nameof(db)); }