public static List <dom.Pizza> GetPizzasByOrderID(int orderID) { var _db = new dat.PizzaStoreDbContext(); var datapizzas = _db.Pizza.Where(p => p.OrderId == orderID).ToList(); var domPizzaList = new List <dom.Pizza>(); foreach (var item in datapizzas) { if ((bool)item.Active) { var dompizza = new dom.Pizza() { CrustId = (int)item.CrustId , crustSize = (int)item.Size , OrderId = (int)item.OrderId , ModifiedDate = item.ModifiedDate , Id = (int)item.PizzaId }; dompizza.Toppings = PizzaHelper.GetIngredientsByPizza(item); dompizza.CrustFactor = PizzaHelper.GetFactorByCrustID(item.CrustId); dompizza.price = dompizza.CalculateCost(); domPizzaList.Add(dompizza); } } return(domPizzaList); }
public ActionResult DeletePizza(int id) { var _db = new dat.PizzaStoreDbContext(); var datapizza = _db.Pizza.Where(p => p.PizzaId == id).FirstOrDefault(); datapizza.Active = false; _db.SaveChanges(); return(OrderMenu()); }
public ActionResult ThankYou() { dat.PizzaStoreDbContext _db = new dat.PizzaStoreDbContext(); var orderID = HttpContext.Session.GetInt32("orderID"); var dataOrder = _db.Order.Where(o => o.OrderId == orderID).FirstOrDefault(); dataOrder.TimeStamp = DateTime.Now; dataOrder.Voidable = false; _db.SaveChanges(); return(View("ThankYou")); }
public ActionResult DeleteTopping(int id) { var _db = new dat.PizzaStoreDbContext(); int pid = (int)HttpContext.Session.GetInt32("pizzaID"); var pipairs = _db.PizzaIngredient.Where(pi => pi.PizzaId == pid).ToList(); var targetTopping = pipairs.FirstOrDefault(pi => pi.IngredientId == id); targetTopping.Active = false; _db.SaveChanges(); return(EditPizza(pid)); }
public ActionResult ValidateUser() { var _db = new dat.PizzaStoreDbContext(); var userlist = UserHelper.GetUsers(); var domuser = userlist.FirstOrDefault(u => u.name == HttpContext.Session.GetString("ActiveUser")); var datauser = _db.User.Where(u => u.Name == HttpContext.Session.GetString("ActiveUser")).FirstOrDefault(); var orderlist = UserHelper.GetOrdersByUser(datauser); var validorders = new List <dom.Order>(); foreach (var o in orderlist) { if (o.Voidable == false) { validorders.Add(o); } } domuser.History = validorders; if (domuser.TimeTest() == false) { ViewData["Name"] = domuser.name; ViewData["OpenTime"] = (domuser.History[(domuser.History.Count) - 1].TimeStamp.AddHours(2).ToString()); return(View("Timeout")); } byte locationid = 0; if (domuser.History.Count != 0) { var now = DateTime.Now; if (domuser.History[(domuser.History.Count) - 1].TimeStamp.Date == now.Date) { locationid = domuser.History[(domuser.History.Count) - 1].StoreID; HttpContext.Session.SetString("forcelocation", $" {domuser.name} can only order from store {locationid} until midnight"); } } if (locationid != 0) { return(StartOrder(locationid)); } else { return(ChooseLocation()); } }
public ActionResult ViewOrders() { var enteredUser = new LocationUser() { Name = HttpContext.Session.GetString("ActiveUser") }; dat.PizzaStoreDbContext _db = new dat.PizzaStoreDbContext(); var dataUser = _db.User.Where(u => u.Name == enteredUser.Name).FirstOrDefault(); enteredUser.History = UserHelper.GetOrdersByUser(dataUser); enteredUser.AssignCrusts(); ViewData["name"] = enteredUser.Name; return(View("ViewOrders", enteredUser)); }
public IActionResult loguserin(LocationUser enteredUser) { dat.PizzaStoreDbContext _db = new dat.PizzaStoreDbContext(); var dataUser = _db.User.Where(u => u.Name == enteredUser.Name).FirstOrDefault(); if (dataUser == null) { HttpContext.Session.SetString("UserError", "Your username is not found."); return(RedirectToAction("SignUp", "Home")); } if (dataUser.Password != enteredUser.password) { ViewData["ErrorMessage"] = "Passwords don't match"; return(View("signIn")); } HttpContext.Session.SetString("ActiveUser", dataUser.Name); return(View("Index")); }