public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,PhoneNumber,Location")] MVCustomer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public IActionResult ChooseALocation(MVLocation location, MVCustomer cust)
        {
            var select = location.Id;

            cust.Id = select;

            return(RedirectToAction("PlaceAnOrder", "Orders", cust));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,Location")] MVCustomer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        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 IActionResult AddNewUser(MVCustomer customer)
        {
            bool foundcust = false;


            var allcust = Repo.GetCustomers();

            foreach (var aUser in allcust)
            {
                if (aUser.FirstName == customer.FirstName && aUser.PhoneNumber == customer.PhoneNumber)
                {
                    customer.Id = aUser.Id;
                    foundcust   = true;
                    goto aNewUser;
                }
            }

aNewUser:
            if (foundcust == true)
            {
                var aCust = new MVCustomer
                {
                    Id          = customer.Id,
                    FirstName   = customer.FirstName,
                    LastName    = customer.LastName,
                    PhoneNumber = customer.PhoneNumber,
                    Location    = "RESTON"
                };
            }
            else if (foundcust == false)
            {
                //create new user
                Repo.AddCustomer(customer.FirstName, customer.LastName, customer.PhoneNumber);
                Repo.SaveChanges();
            }

            return(RedirectToAction("Index", "Locations", customer));
            // return View(user);
        }
        public IActionResult ChooseLocation(MVCustomer cust)
        {
            MVLocation location = new MVLocation();

            return(View(location));
        }
        public IActionResult Register()
        {
            MVCustomer cust = new MVCustomer();

            return(View(cust));
        }
        public IActionResult AddNewUser()
        {
            MVCustomer customer = new MVCustomer();

            return(View(customer));
        }
        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)));
        }