public IActionResult Register(MVCustomer cust) { bool isUser = false; TempData["firstname"] = cust.FirstName; TempData["lastname"] = cust.LastName; TempData["phone"] = cust.PhoneNumber; TempData["Count"] = 1;// counter for numbers pizza increments in the ordersController TempData["order_total"] = 0; var allCust = Repo.GetCustomers(); foreach (var oneCust in allCust) { if (oneCust.FirstName == cust.FirstName && oneCust.PhoneNumber == cust.PhoneNumber) { cust.Id = oneCust.Id; TempData["custid"] = cust.Id; isUser = true; break; } } if (isUser == true) { } else if (isUser == false) { TempData["welcomemsg"] = "Welcome " + cust.FirstName; //create new user Repo.AddCustomer(cust.FirstName, cust.LastName, cust.PhoneNumber, cust.Location = "RESTON"); Repo.SaveChanges(); //get id of new user here var item = Repo.GetCustomers().FirstOrDefault(x => x.FirstName == cust.FirstName && x.PhoneNumber == cust.PhoneNumber); cust.Id = item.Id; TempData["custid"] = cust.Id; } return(RedirectToAction("ChooseLocation", "Locations", cust)); }
public ActionResult MakeOrder(IFormCollection viewCollection, MVCustomer cust) { Random rdm = new Random(); int ONum = rdm.Next(1, 1000000); int UseridTD = int.Parse(TempData.Peek("custid").ToString()); string LocationTD = TempData.Peek("locationName").ToString(); string NameTD = TempData.Peek("firstname").ToString(); string LastnameTD = TempData.Peek("lastname").ToString(); string PhoneTD = TempData.Peek("phone").ToString(); if (Count == 12) { ViewData["msg"] = "ERROR YOU CANNOT ORDER MORE THAN 12 PIZZAS!!!!! "; return(RedirectToAction(nameof(MakeOrder))); } string selectedSize = viewCollection["SelectedSize"]; string selectedTopping = viewCollection["SelectedTopping"]; string selectedCrust = viewCollection["SelectedCrust"]; if (selectedSize == "Small") { price = 5.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 5.00; TempData["order_total"] = total; } else if (selectedSize == "Medium") { price = 10.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 10.00; TempData["order_total"] = total; } else if (selectedSize == "Large") { price = 15.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 15.00; TempData["order_total"] = total; } else if (selectedCrust == "1") { price = .50; total = int.Parse(TempData.Peek("order_total").ToString()); total += .50; TempData["order_total"] = total; } else { price = 20.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 20.00; TempData["order_total"] = total; } if (TempData.Peek("Count").ToString() == "1") { Count = 1; } else { Count = int.Parse(TempData.Peek("Count").ToString()); } if (Count < 2)//only if the order is new is going to be created { //add order Repo.AddOrders(ONum, NameTD, LastnameTD, LocationTD, price, total, DateTime.Now, "T'Challa Slice", PhoneTD); Repo.SaveChanges(); } bool PG = bool.Parse(selectedCrust); Repo.AddPizza(selectedSize, selectedTopping, PG, ONum); Repo.SaveChanges(); // increment counter to know next time, that this is not a new order. Count++; TempData["Count"] = Count; var orderId = Repo.GetOrders().FirstOrDefault(x => x.CustomerPhoneNumber == PhoneTD && x.CustomerName == NameTD); TempData["orderId"] = orderId.Id; return(RedirectToAction(nameof(MakeOrder))); }