public ActionResult SelectCustomPizza(int id)
        {
            Customer      customer = null;
            IList <Pizza> pizzas   = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(CustomerUrl + id);
                var response = client.GetAsync("");
                response.Wait();
                var result = response.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <Customer>();
                    readTask.Wait();

                    customer = readTask.Result;
                }
                else
                {
                    customer = null;
                    ModelState.AddModelError(string.Empty, "Server error, Get Stores is empty");
                }
            }
            var sessionOrder = UtilsSession.GetCurrentOrder(HttpContext.Session);

            sessionOrder.Customer = customer;
            if (sessionOrder.CustomerId == 0)
            {
                sessionOrder.CustomerId = id;
            }

            UtilsSession.SaveOrder(HttpContext.Session, sessionOrder);

            ViewBag.ErrorMessage = TempData["ErrorMessage"];



            Pizza pizza = UtilsSession.GetCustomPizza(HttpContext.Session);

            pizza.PizzaName = "custom";

            UtilsSession.SavePizza(HttpContext.Session, pizza);


            if (pizza.Sauce != null)
            {
                ViewBag.SauceName  = pizza.Sauce.Name;
                ViewBag.SaucePrice = pizza.Sauce.Price;
            }

            pizzas = new List <Pizza>();
            pizzas.Add(pizza);

            return(View(pizzas));
        }
        public async Task <ActionResult> SubmitCustomOrder()
        {
            var cid = UtilsSession.GetCurrentOrder(HttpContext.Session).CustomerId;

            if (UtilsSession.GetCustomPizza(HttpContext.Session).Topping.Count < 2)
            {
                TempData["ErrorMessage"] = " You Must at least 2 toppings";
                return(RedirectToAction("SelectCustomPizza", cid));
            }
            if (UtilsSession.GetCustomPizza(HttpContext.Session).SauceId == null)
            {
                TempData["ErrorMessage"] = " You Must select a sauce";
                return(RedirectToAction("SelectCustomPizza", cid));
            }
            if (UtilsSession.GetCustomPizza(HttpContext.Session).CrustId == null)
            {
                TempData["ErrorMessage"] = " You Must select a crust";
                return(RedirectToAction("SelectCustomPizza", cid));
            }


            Pizza pizza = UtilsSession.GetCustomPizza(HttpContext.Session);

            int newPizzaId;

            var json = JsonConvert.SerializeObject(pizza);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            using (var pizzaclient = new HttpClient())
            {
                var response = await pizzaclient.PostAsync(PizzaUrl, data);

                var result = response.Content.ReadAsAsync <Pizza>();
                newPizzaId = result.Id;
            }

            Pizza custpizza = UtilsSession.GetCustomPizza(HttpContext.Session);

            custpizza.Id = newPizzaId;

            UtilsSession.SavePizza(HttpContext.Session, custpizza);

            return(RedirectToAction("SelectNumCustomPizza", cid));
        }
        public ActionResult AddToppingToPizza(int id)
        {
            var cid = UtilsSession.GetCurrentOrder(HttpContext.Session).CustomerId;

            if (UtilsSession.GetCustomPizza(HttpContext.Session).Topping.Count == 5)
            {
                TempData["ErrorMessage"] = " You cannot add more than 5 toppings";
                return(RedirectToAction("SelectCustomPizza", cid));
            }

            Topping topping = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(toppingUrl + id);
                var response = client.GetAsync("");
                response.Wait();
                var result = response.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <Topping>();
                    readTask.Wait();

                    topping = readTask.Result;
                }
                else
                {
                    topping = null;
                    ModelState.AddModelError(string.Empty, "Server error, Get crust is empty");
                }
            }
            var pizza = UtilsSession.GetCustomPizza(HttpContext.Session);

            pizza.Topping.Add(topping);
            UtilsSession.SavePizza(HttpContext.Session, pizza);



            return(RedirectToAction("SelectCustomPizza", cid));
        }
        public ActionResult AddCrustToPizza(int id)
        {
            Crust crust = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(crustUrl + id);
                var response = client.GetAsync("");
                response.Wait();
                var result = response.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <Crust>();
                    readTask.Wait();

                    crust = readTask.Result;
                    System.Console.WriteLine("Pizza Retrieved!");
                }
                else
                {
                    crust = null;
                    System.Console.WriteLine("Pizza Not Retrieved!");
                    ModelState.AddModelError(string.Empty, "Server error, Get crust is empty");
                }
            }

            var pizza = UtilsSession.GetCustomPizza(HttpContext.Session);

            pizza.Crust      = crust;
            pizza.Crust.Name = crust.Name;
            pizza.CrustId    = crust.Id;

            UtilsSession.SavePizza(HttpContext.Session, pizza);

            var customer = UtilsSession.GetCurrentOrder(HttpContext.Session);

            return(RedirectToAction("SelectCustomPizza", customer.CustomerId));
        }
        public ActionResult AddSauceToPizza(int id)
        {
            Sauce sauce = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(sauceUrl + id);
                var response = client.GetAsync("");
                response.Wait();
                var result = response.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <Sauce>();
                    readTask.Wait();

                    sauce = readTask.Result;
                    System.Console.WriteLine("Sauce Retrieved!");
                }
                else
                {
                    sauce = null;
                    System.Console.WriteLine("Sauce Not Retrieved!");
                    ModelState.AddModelError(string.Empty, "Server error, Get crust is empty");
                }
            }

            var pizza = UtilsSession.GetCustomPizza(HttpContext.Session);

            pizza.Sauce   = sauce;
            pizza.SauceId = sauce.Id;

            UtilsSession.SavePizza(HttpContext.Session, pizza);

            var cid = UtilsSession.GetCurrentOrder(HttpContext.Session);

            return(RedirectToAction("SelectCustomPizza", cid.CustomerId));
        }