//Vue complexe utilisant le modèle OrderDetailsViewModel //Permet d'afficher le nom du restaurant de la commande, le numéro de la commande, les plats choisis (bug, 1 seul plat est affiché), //la quantité par plats, le prix unitaire d'un plat, l'heure de livraison... public ActionResult OrderDetails() { List <OrderDetailsViewModel> listeOrderDetails = new List <OrderDetailsViewModel>(); OrderDetailsViewModel orderDetails = new OrderDetailsViewModel(); int idCustomer = HttpContext.Session.GetInt32("IdCustomer").GetValueOrDefault(); int idOrder = HttpContext.Session.GetInt32("IdOrder").GetValueOrDefault(); int idRestaurant = HttpContext.Session.GetInt32("IdRestaurant").GetValueOrDefault(); int idDeliveryTime = HttpContext.Session.GetInt32("Id_Delivery_time").GetValueOrDefault(); OrderManager.UpdateOrderDeliveryTime(idOrder, idDeliveryTime); List <DTO.Order_Dish> listeOrder_Dishes = Order_DishManager.GetAllOrder_Dish(idOrder); DTO.Customer customer = CustomerManager.GetCustomer(idCustomer); DTO.Order order = OrderManager.GetOrder(idOrder); DTO.Restaurant restaurant = RestaurantManager.GetRestaurant(idRestaurant); orderDetails.Customers = customer; orderDetails.Orders = order; orderDetails.Restaurants = restaurant; orderDetails.Cities = CityManager.GetCity(customer.FK_idCity); orderDetails.Delivery_Times = Delivery_TimeManager.GetDelivery_Time(idDeliveryTime); foreach (DTO.Order_Dish od in listeOrder_Dishes) { orderDetails.Order_Dishes = od; orderDetails.Dishes = DishManager.GetDish(od.FK_idDish); } listeOrderDetails.Add(orderDetails); return(View(listeOrderDetails)); }
//Method that add an item into the shopping cart public ActionResult AddItem(int id) { if (HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart") == null) { List <Cart> cart = new List <Cart>(); cart.Add(new Cart { dish = DishManager.GetDish(id), quantity = 1, totalPriceProduct = DishManager.GetDish(id).Price }); HttpContext.Session.SetObjectAsJson("Cart", cart); } else { int index = isExist(id); if (index != -1) { List <Cart> cart = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); cart.Select(m => m.dish.IdDish == id); cart[index].quantity++; cart[index].totalPriceProduct += DishManager.GetDish(id).Price; HttpContext.Session.SetObjectAsJson("Cart", cart); } else { List <Cart> cart = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); cart.Add(new Cart { dish = DishManager.GetDish(id), quantity = 1, totalPriceProduct = DishManager.GetDish(id).Price }); HttpContext.Session.SetObjectAsJson("Cart", cart); } } return(RedirectToAction(("ShoppingCart"))); }
//Remove the dish from your cart public ActionResult RemoveAllItems(int id) { List <Cart> cart = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); var itemToRemove = cart.Single(r => r.dish.IdDish == id); cart.Remove(itemToRemove); HttpContext.Session.SetObjectAsJson("Cart", cart); Dish dish = DishManager.GetDish(id); int idResto = dish.IdRestaurant; return(RedirectToAction("Details/" + idResto)); }
//method that removes a dish from the cart public ActionResult RemoveItem(int id) { List <Cart> cart = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); var itemToRemove = cart.Single(r => r.dish.IdDish == id); int index = isExist(id); if (cart[index].quantity >= 2) { cart[index].quantity--; cart[index].totalPriceProduct -= DishManager.GetDish(id).Price; HttpContext.Session.SetObjectAsJson("Cart", cart); } return(RedirectToAction("ShoppingCart")); }
//Show the details of an order public ActionResult DetailsOrder(int id) { OrderManager.GetOrder(id); List <Cart> cartlist = new List <Cart>(); var dishes = Order_DishesManager.GetOrder_Dishes(id); foreach (var item in dishes) { Dish dish = DishManager.GetDish(item.IdDish); Cart cart = new Cart(); cart.dish = dish; cart.quantity = item.Quantity; cart.totalPriceProduct = item.Quantity * dish.Price; cartlist.Add(cart); } return(View(cartlist)); }
//Add an item to the shopping cart public ActionResult AddItem(int id) { if (HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart") == null) { List <Cart> cart = new List <Cart>(); cart.Add(new Cart { dish = DishManager.GetDish(id), quantity = 1, totalPriceProduct = DishManager.GetDish(id).Price }); HttpContext.Session.SetObjectAsJson("Cart", cart); } else { int index = isExist(id); if (index != -1) { List <Cart> cart = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); cart.Select(m => m.dish.IdDish == id); cart[index].quantity++; cart[index].totalPriceProduct += DishManager.GetDish(id).Price; HttpContext.Session.SetObjectAsJson("Cart", cart); } else { List <Cart> cart = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); cart.Add(new Cart { dish = DishManager.GetDish(id), quantity = 1, totalPriceProduct = DishManager.GetDish(id).Price }); HttpContext.Session.SetObjectAsJson("Cart", cart); } } Dish dish = DishManager.GetDish(id); int idResto = dish.IdRestaurant; string name = RestaurantManager.GetRestaurant(idResto).Name; return(RedirectToAction("Details/" + idResto)); }