public ActionResult UserPreview(Models.OrderModel order) { //show what the stats are ViewData["count"] = HttpContext.Session.GetInt32("pizzacount"); //find out what our cost is at, in string form for some reason i can't explain HttpContext.Session.GetString("pizzacost"); ViewData["cost"] = HttpContext.Session.GetString("pizzacost"); //attempt to push pizza to the database. //first create new pizza order PizzaOrder finalpizza = new PizzaOrder(); //obtain value for pizzacounter int pizzacounter = (int)HttpContext.Session.GetInt32("pizzacounter"); //loop through all my sessions that are storing my pizza objects //make pizza objects and add them to my order and pizzatable. for (int i = 0; i < pizzacounter; i++) { //intialize temppizzastring string temppizzastring = ""; temppizzastring = HttpContext.Session.GetString($"pizzastring{i + 1}"); Pizza mypiz = new Pizza(); mypiz = mypiz.recreatePizza(temppizzastring); finalpizza.addPizza(mypiz); } //add current location to pizzaorder so it doesn't break my sql query finalpizza.LocationAddress = HttpContext.Session.GetString("location"); //make a pizzauser cause its an input for my database add method. PizzaUser pizuser = new PizzaUser(); pizuser.username = HttpContext.Session.GetString("username"); bool didorderwork = false; if (PC.CheckOrderConditions(finalpizza.LocationAddress, pizuser.username)) { didorderwork = PC.AddPizzaOrder(finalpizza, pizuser); } else { didorderwork = false; } if (didorderwork) { //finally try to add the thing to the database ViewData["isOrdervalid"] = "Order is valid"; return(RedirectToAction("login", "user", order)); } else { ViewData["isOrdervalid"] = "Order is invalid"; return(View()); } }