Exemplo n.º 1
0
        public ActionResult SubmitOrder(OrderViewModel orderViewModel)
        {
            try
            {
                ViewBag.Sent = false;

                if (Session["EmailAddress"] != null)
                {
                    var emailAddress = Session["EmailAddress"].ToString();
                    var userId       = db.Customers.Where(a => a.EmailAddress == emailAddress).Select(t => t.CustomerId).FirstOrDefault();
                    var pizzaId      = db.Pizzas.Where(a => a.PizzaName == orderViewModel.pizzaName).Select(t => t.PizzaId).FirstOrDefault();
                    var baseId       = db.Bases.Where(a => a.SizeOfPizza == orderViewModel.size).Select(t => t.BaseId).FirstOrDefault();
                    var drinkId      = db.CoolDrinks.Where(a => a.Flavour == orderViewModel.drink).Select(t => t.DrinkId).FirstOrDefault();
                    var toppingId    = db.Toppings.Where(a => a.Description == orderViewModel.topping).Select(t => t.TopId).FirstOrDefault();
                    //saving to Delivery Method
                    var deliveryMethodId = db.SaveDeliveryDetails(orderViewModel.delivery, orderViewModel.address, orderViewModel.number).FirstOrDefault();

                    //Saving to order
                    var orderId = db.SaveOrder(userId, deliveryMethodId, baseId, drinkId, 1, pizzaId, DateTime.Now);

                    ViewBag.Sent = true;
                    return(RedirectToAction("CustOrderHistory"));
                }
                else
                {
                    ViewBag.Successful = "Unsuccessufully: Please login before you place an order";
                }


                //Save To Pizza
                // }
                return(RedirectToAction("Menu"));
            }
            catch (Exception e)
            {
                throw;
            }
        }