// GET: Dishes public ActionResult DishesShow() { List <Dishes> dishesList = new DishesManager().GetAllDishes(); ViewBag.dishes = dishesList; return(View()); }
public ActionResult DishesRestaurant(int id) { if (HttpContext.Session.GetString("User") != null) { var restaurant = RestaurantsManager.GetRestaurant(id); ViewData["Address"] = restaurant; int idRestaurantCity = CitiesManager.GetRestaurantCity(id); HttpContext.Session.SetInt32("idCityRestaurant", idRestaurantCity); var order_dishes = new List <OrderDishmodel>(); var dishes = DishesManager.GetDishes(id); foreach (var item in dishes) { var dishOrder = new Models.OrderDishmodel(); dishOrder.dish = DishesManager.GetDish(item.IdDishes); dishOrder.dish.Name = item.Name; order_dishes.Add(dishOrder); } return(View(order_dishes)); } else { return(RedirectToAction("Index", "Login")); } }
//Allows a customer to delete a dishe from the cart. If there is multiple times the same dish, quantity will be decremented. public IActionResult DeleteItem(int idDish) { DishesManager dManager = new DishesManager(Configuration); int price = dManager.GetDishePrice(idDish); HttpContext.Session.SetInt32("TotalAmount", (int)HttpContext.Session.GetInt32("TotalAmount") - price); List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); var itemToRemove = cart.Single(d => d.Dishe.idDishes == idDish); //In case of the element the customer wants to delete is the last one, we empty the session. if (cart.Count == 1) { SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", null); } //If the item has more than 1 quantity, we just decrement it but do not delete the entire else if (itemToRemove.Quantity > 1) { cart.Remove(itemToRemove); itemToRemove.Quantity--; cart.Add(itemToRemove); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { cart.Remove(itemToRemove); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } return(RedirectToAction("Index", "Cart")); }
//Display dishes served by the selected restaurant public ActionResult Dishes(int id) { ViewBag.username = HttpContext.Session.GetString("username"); ViewBag.userType = HttpContext.Session.GetInt32("userType"); DishesManager dManager = new DishesManager(Configuration); return(View(dManager.GetDishesOfRestaurant(id))); }
//Allows customer to add a dish to his cart public ActionResult AddToCart(int id) { //We retrieve the dishe's price DishesManager dManager = new DishesManager(Configuration); Dishes dishe = new Dishes(); int price = dManager.GetDishePrice(id); //We add the price to the total amount, we initiate the session value if it is the first dish of the cart. if (HttpContext.Session.GetInt32("TotalAmount") != null) { HttpContext.Session.SetInt32("TotalAmount", (price + (int)HttpContext.Session.GetInt32("TotalAmount"))); } else { HttpContext.Session.SetInt32("TotalAmount", price); } //So if it is the first dish to be added we create a list of item(Dishe+quantity) in the session if (SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart") == null) { List <Item> cart = new List <Item>(); cart.Add(new Item { Dishe = dManager.GetDishe(id), Quantity = 1 }); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { /*Else if the list is already created we get it and check if the dish is already in the list. * If yes we increment the quantity, else we add the dish as a new item. */ List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); int index = DoesExist(id); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new Item { Dishe = dManager.GetDishe(id), Quantity = 1 }); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } //Redirect to the cart return(RedirectToAction("Index", "Cart")); }
public ActionResult Create(int id, OrderDish od) { int idOrder = (int)HttpContext.Session.GetInt32("idOrder"); var creation = new OrderDish(); creation.IdOrder = idOrder; creation.IdDish = id; if (od.Quantity > 0 && od.Quantity <= 20) { creation.Quantity = od.Quantity; } else { ViewData["Message"] = "La Quantité doit être entre 1 et 20 !"; return(View()); } var dish = DishesManager.GetDish(id); creation.OrderDishPrice = dish.DishPrice * creation.Quantity; var test = OrderDishManager.GetOrderDishes(idOrder); if (test != null) { foreach (var t in test) { if (t.IdDish == id) { return(RedirectToAction("Update", creation)); } } } else { OrderDishManager.AddOrderDish(creation); } return(RedirectToAction("GetAllDishes", "Dish")); }
public IActionResult AffichePanier() { var panier = OrderDishManager.GetOrderDishes((int)HttpContext.Session.GetInt32("idOrder")); List <Panier> total = new List <Panier>(); var prixTotal = OrderManager.GetOrder((int)HttpContext.Session.GetInt32("idOrder")); if (panier == null) { return(RedirectToAction("GetAllDishes", "Dish")); } foreach (var p in panier) { Panier article = new Panier(); var dish = DishesManager.GetDish(p.IdDish); article.OrderId = p.IdOrder; article.ProductId = p.IdDish; article.ProductName = dish.Name; article.Quantity = p.Quantity; article.TotalPrice = p.OrderDishPrice; total.Add(article); prixTotal.OrderPrice += article.TotalPrice; } double prix = (double)prixTotal.OrderPrice; OrderManager.UpdateOrder(prixTotal); ViewBag.prixTotalCommande = prix; return(View(total)); }
static void Main(string[] args) { /*--Customers--*/ var customerDBManager = new CustomersManager(Configuration); //Add new customer Console.WriteLine("--Add customer --"); customerDBManager.AddCustomer(new Customers { Firstname = "Ludovic", Lastname = "Sahraoui", Login = "******", Password = "******", Country_code = 1, Address = "Chemin des Salines 40" });; //var customers = customerDBManager.GetCustomer(1); //Console.WriteLine(customers.Firstname); /* * //Update new customer * var newCustomer = customerDBManager.GetCustomer(1); * newCustomer.Firstname = "Léo"; * newCustomer.Lastname = "Favre"; * customerDBManager.UpdateCustomer(newCustomer); * * /* * //Delete customer * Console.WriteLine("--Delete customer --"); * customerDBManager.DeleteCustomer(1); */ /*--Cities--*/ //Get Cities Console.WriteLine("--Get cities --"); var citiesDBManager = new CitiesManager(Configuration); var cities = citiesDBManager.GetCities(); foreach (var city in cities) { Console.WriteLine(city.Name); } /*--Courier--*/ Console.WriteLine("--Get courier 1 --"); var courierDBManager = new CourierManager(Configuration); var courier = courierDBManager.GetCourier(1); Console.WriteLine(courier.Firstname); /*--Dishes--*/ //Get dishes Console.WriteLine("--Get dishes --"); var dishesDBManager = new DishesManager(Configuration); var dishes = dishesDBManager.GetDishes(); foreach (var dish in dishes) { Console.WriteLine(dish.Name); } /*--OrderDishes--*/ /*--Orders--*/ //add order Console.WriteLine("--Add order --"); var ordersDBManager = new OrdersManager(Configuration); ordersDBManager.AddOrder(new Order { Status = "Ready", Created_at = 02042019, Delivery_time = 2, IdCourier = 1, IdCustomer = 1 });; /*--Restaurants--*/ }