//Lorsque l'utilisateur valide sa commande, la livraison est crée. Recherche le deliveryman adapté (même ville que restaurant) et
        //pas plus de 5 livraisons avec status "A livrer" (Tranche de 30 minutes pas réussi)
        public ActionResult CreateDelivery()
        {
            int idOrder        = HttpContext.Session.GetInt32("IdOrder").GetValueOrDefault();
            int idRestaurant   = HttpContext.Session.GetInt32("IdRestaurant").GetValueOrDefault();
            int idDeliveryTime = HttpContext.Session.GetInt32("Id_Delivery_time").GetValueOrDefault();
            int idCity         = HttpContext.Session.GetInt32("IdCity").GetValueOrDefault();

            Delivery newDelivery = new Delivery {
                FK_idOrder = idOrder, FK_idRestaurant = idRestaurant, FK_idDelivery_Time = idDeliveryTime, Status = "A livrer"
            };

            DeliveryManager.AddDelivery(newDelivery);

            int idRightDeliveryman = DeliverymanManager.GetRightDeliveryman(idCity);

            //Si la méthode ne trouve aucun livreur disponible, renvoie sur la page NoDeliverymanAvailable
            if (idRightDeliveryman == 0)
            {
                return(RedirectToAction("NoDeliverymanAvailable", "Delivery"));
            }
            else
            {
                //Si la méthode trôuve un livreur, insertion dans la livraison de son ID
                //Redirige vers la page de confirmation de la livraison
                DeliveryManager.UpdateDelivery(newDelivery.IdDelivery, idRightDeliveryman);
                return(RedirectToAction("DeliveryConfirmed", "Delivery"));
            }
        }
        public static void Suite(int idCustomer)
        {
            var restaurantDbManager    = new RestaurantManager(Configuration);
            var dishDbManager          = new DishManager(Configuration);
            var delivery_TimeDbManager = new Delivery_TimeManager(Configuration);
            var orderDbManager         = new OrderManager(Configuration);
            var customerDbManager      = new CustomerManager(Configuration);
            var deliveryDbManager      = new DeliveryManager(Configuration);
            var orderDishDbManager     = new Order_DishManager(Configuration);
            var deliverymanDbMangager  = new DeliverymanManager(Configuration);

            Console.WriteLine("[1] New order, [2] Cancel order");
            string orderChoice = Console.ReadLine();

            if (orderChoice == "1")
            {
                Console.WriteLine("Restaurants list : ");

                var restaurants = restaurantDbManager.GetAllRestaurants();

                foreach (var restaurant in restaurants)
                {
                    Console.WriteLine(restaurant.ToString());
                }

                Console.WriteLine("Choose the restaurant");
                string idRestaurant = Console.ReadLine();


                var dishes = dishDbManager.GetAllDishes(int.Parse(idRestaurant));

                foreach (var dish in dishes)
                {
                    Console.WriteLine(dish.ToString());
                }

                Console.WriteLine("Choose your dish");
                string dishChoice = Console.ReadLine();

                int dishPrice = dishDbManager.GetDishPrice(int.Parse(dishChoice));

                Console.WriteLine("How many times do you want this dish ?");
                string dishQuantity = Console.ReadLine();

                int totalPrice = dishPrice * int.Parse(dishQuantity);

                var newOrder = orderDbManager.AddOrder(new Order {
                    Status = "In procedure", FK_idCustomer = idCustomer
                });

                orderDishDbManager.AddOrder_Dish(new Order_Dish {
                    Quantity = dishQuantity, FK_idDish = int.Parse(dishChoice), FK_idOrder = newOrder.IdOrder
                });

                //Sans plusieurs ordres, ça fonctionne

                /*while (dishChoice != "0")
                 * {
                 *  Console.WriteLine("Would you like something else ? If your order is done, insert [0]");
                 *  dishChoice = Console.ReadLine();
                 *  dishPrice = dishDbManager.GetDishPrice(int.Parse(dishChoice));
                 *
                 *  if (dishChoice != "0")
                 *  {
                 *      Console.WriteLine("How many times do you want this dish ?");
                 *      dishQuantity = Console.ReadLine();
                 *      totalPrice += dishPrice * int.Parse(dishQuantity);
                 *  }
                 *
                 *  //Bug ici à corriger
                 *  orderDishDbManager.AddOrder_Dish(new Order_Dish { Quantity = dishQuantity, FK_idDish = int.Parse(dishChoice), FK_idOrder = newOrder.IdOrder});
                 * }*/

                Console.WriteLine("The total of your command is : CHF " + totalPrice + ".-");

                Console.WriteLine("When do you want your order to be delivered ? Choose the time with the ID");


                var delivery_times = delivery_TimeDbManager.GetAllDelivery_Time();
                foreach (var delivery_time in delivery_times)
                {
                    Console.WriteLine(delivery_time.ToString());
                }

                string deliveryTimeChoice = Console.ReadLine();

                Console.WriteLine("Do you validate this order ? Yes [Y], No [N]");
                string validationChoice = Console.ReadLine();

                if (validationChoice == "Y")
                {
                    Console.WriteLine("Thank you for ordering with Liam & Mathieu Food Delivery !");
                    Console.WriteLine("Your order will be there at " + delivery_TimeDbManager.GetDelivery_Time(int.Parse(deliveryTimeChoice)));


                    int idCityFromRestaurant = restaurantDbManager.GetidCityFromRestaurant(int.Parse(idRestaurant));

                    var deliverymans = deliverymanDbMangager.GetAllDeliveryman(idCityFromRestaurant);

                    foreach (var deliveryman in deliverymans)
                    {
                        //if(deliveryman.FK_idDelivery<5 && deliveryman.)
                    }

                    deliveryDbManager.AddDelivery(new Delivery {
                        FK_idOrder = newOrder.IdOrder, FK_idRestaurant = int.Parse(idRestaurant), FK_idDelivery_Time = int.Parse(deliveryTimeChoice)
                    });
                }

                else
                {
                    Console.WriteLine("You canceled the order. See you soon !");
                }
            }
            else
            {
                Console.WriteLine("Here is the list of your orders : ");

                var orders = orderDbManager.GetAllOrdersForOneCustomer(idCustomer);

                foreach (var order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("Choose the order you want to delete with the id");
                string orderDelete = Console.ReadLine();
                var    code        = customerDbManager.Code(idCustomer) + orderDelete;
                Console.WriteLine("Here is your cancellation code for the chosen order :" + ' ' + code);
                Console.WriteLine("Insert you cancellation code :");
                string codeInserted = Console.ReadLine();
                while (codeInserted != code)
                {
                    Console.WriteLine("Cancellation code wrong. Try again.");
                    codeInserted = Console.ReadLine();
                }
                Console.WriteLine("Are you sure you want to cancel this order ? Yes [Y], No [N]");
                string choice = Console.ReadLine();
                if (choice == "Y")
                {
                    //Change status order
                    Console.WriteLine("Your order has been successfully cancelled !");
                }
                Console.WriteLine("Your order has not been cancelled");
            }
        }
Beispiel #3
0
        //Insert the cart into the database
        public IActionResult ProceedCheckout(int idAvailability, int idStaff, TimeSpan choosenTime)
        {
            ViewBag.username    = HttpContext.Session.GetString("username");
            ViewBag.userType    = HttpContext.Session.GetInt32("userType");
            ViewBag.totalAmount = HttpContext.Session.GetInt32("TotalAmount");
            int                 idCredentials = (int)HttpContext.Session.GetInt32("id");
            CustomerManager     cManger       = new CustomerManager(Configuration);
            int                 idCustomer    = cManger.GetCustomerIDByCredentials(idCredentials);
            AvailibilityManager aManager      = new AvailibilityManager(Configuration);

            if (idAvailability % 15 < 14 && idAvailability % 15 >= 1)
            {
                //additioning the counter of the cur. time + cur. time + 15 + cur. time + 30
                int totalCounter = aManager.GetCounter(idAvailability) + aManager.GetCounter(idAvailability + 1) + aManager.GetCounter(idAvailability + 2);

                if (totalCounter >= 4)
                {
                    //Make deliveryBoy unavailable at the choosen time, 0 means unavailable
                    aManager.UpdateAvailability(idAvailability, 0);
                }

                for (int i = idAvailability; i <= idAvailability + 2; i++)
                {
                    //increment counter
                    aManager.IncrementCounter(i);
                }
            }
            else if (idAvailability % 15 == 14)

            {
                int totalCounter = aManager.GetCounter(idAvailability) + aManager.GetCounter(idAvailability + 1);

                if (totalCounter >= 4)
                {
                    //Make deliveryBoy unavailable at the choosen time
                    aManager.UpdateAvailability(idAvailability, 0);
                }

                for (int i = idAvailability; i <= idAvailability + 1; i++)
                {
                    //increment counter
                    aManager.IncrementCounter(i);
                }
            }
            else if (idAvailability % 15 == 0)
            {
                int totalCounter = aManager.GetCounter(idAvailability);

                if (totalCounter >= 4)
                {
                    //Make deliveryBoy unavailable at the choosen time
                    aManager.UpdateAvailability(idAvailability, 0);
                }

                aManager.IncrementCounter(idAvailability);
            }

            //First we add the delivery
            DeliveryManager dManager = new DeliveryManager(Configuration);

            dManager.AddDelivery(choosenTime, idStaff);
            int lastDelivery = dManager.GetLastId();

            OrderManager oManager = new OrderManager(Configuration);

            //Then we create the order
            oManager.AddOrder(idCustomer, lastDelivery);
            int lastOrder = oManager.GetLastId();
            //Finaly we link each dish to the order in the dish_order table
            List <Item>         cart      = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");
            Dishes_orderManager doManager = new Dishes_orderManager(Configuration);

            foreach (Item dish in cart)
            {
                doManager.AddDishes_order(dish.Dishe.idDishes, lastOrder, dish.Quantity);
            }
            //This way we respect every foreign key and we do not generate errors.
            cart = null;
            //Clean up cart
            SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            HttpContext.Session.SetInt32("TotalAmount", 0);
            return(View());
        }