public ActionResult DeleteOrder(int id) { Order_DishesManager.DeleteOrder_Dishes(id); OrderManager.DeleteOrder(id); string name = User.Identity.Name; User user = UserManager.GetUserByEmail(name); int idcustomer = CustomerManager.GetCustomerByIdUser(user.IdUser); return(RedirectToAction("Customer", "Account")); }
//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)); }
//Method that creates the order public ActionResult Order(string deliverytime) { User user = UserManager.GetUserByEmail(User.Identity.Name); int idCustomer = CustomerManager.GetCustomerByIdUser(user.IdUser); var cartlists = HttpContext.Session.GetObjectFromJson <List <Cart> >("Cart"); int idresto = cartlists[0].dish.IdRestaurant; var idcity = RestaurantManager.GetCityFromRestaurant(idresto); var users = UserManager.GetUsersByIdCity(idcity); var couriers = CourierManager.GetCouriersByUserIdSameCity(users); //Check if there is a courier in the same city as the restaurant if (!couriers.Any()) { return(RedirectToAction("NoFreeCourier")); } var orders = OrderManager.GetOrders(); List <Courier> courierFree = new List <Courier>(); //Retrieve the date of the order and the delivery date from the view ShoppingCart or Restaurants/Details string tspan = Convert.ToString(deliverytime); DateTime dt = DateTime.Now; DateTime ts = DateTime.Parse(tspan); foreach (var courier in couriers) { if (OrderManager.GetNumberOfOrder(courier.IdCourier, ts) < 5) { courierFree.Add(courier); } } //Check if any courier is available if (!courierFree.Any()) { return(RedirectToAction("NoFreeCourier")); } var courriers = CourierManager.GetCouriers(); OrderManager.GetNumberOfOrder(courriers[0].IdCourier, ts); //Insert the order from the cart Order order = new Order(); order.Status = "Not delivered"; order.Date = dt; order.ShippingDate = ts; order.TotalPrice = cartlists.Sum(m => m.totalPriceProduct); order.IdCourier = courierFree[0].IdCourier; order.IdClient = idCustomer; Order order1 = OrderManager.AddOrder(order); //Insert each dish and quantity into Order_Dishes foreach (var product in cartlists) { Order_Dishes productordered = new Order_Dishes(); productordered.Quantity = product.quantity; productordered.IdDish = product.dish.IdDish; productordered.IdOrder = order1.IdOrder; Order_DishesManager.AddOrder_Dishes(productordered); } var cart = new List <Cart>(); HttpContext.Session.SetObjectAsJson("Cart", cart); return(RedirectToAction("Confirmation", "Cart")); }