public ActionResult Details(int id)
        {
            //creation of multiple variables to check conditions and for the display
            IOrderDB               order             = new OrderDB(Configuration);
            IOrderManager          om                = new OrderManager(order);
            ICustomerDB            customer          = new CustomerDB(Configuration);
            ICustomerManager       cm                = new CustomerManager(customer);
            ICityDB                citydb            = new CityDB(Configuration);
            ICityManager           cityman           = new CityManager(citydb);
            IDelivery_staffDB      dsDB              = new Delivery_staffDB(Configuration);
            IDelivery_staffManager dsM               = new Delivery_staffManager(dsDB);
            IDishDB                dish              = new DishDB(Configuration);
            IDishManager           dishManager       = new DishManager(dish);
            IOrder_dishesDB        order_Dishes      = new Order_dishesDB(Configuration);
            IOrder_dishesManager   odm               = new Order_dishesManager(order_Dishes);
            IRestaurantDB          restaurant        = new RestaurantDB(Configuration);
            IRestaurantManager     restaurantManager = new RestaurantManager(restaurant);

            //Creations of multiple ViewData for the display
            var customerlist = cm.GetCustomers();

            ViewData["Customers"] = customerlist;
            var citylist = cityman.GetCities();

            ViewData["City"] = citylist;
            var allOrders = om.GetOrders();

            ViewData["AllOrders"] = allOrders;
            var allStaff = dsM.GetDelivery_staffs();

            ViewData["AllStaffs"] = allStaff;
            var allDishes = dishManager.GetAllDishes();

            ViewData["AllDishes"] = allDishes;
            var allOrderDishes = odm.GetAllOrders_dishes();

            ViewData["AllOrderDishes"] = allOrderDishes;
            var allRestaurants = restaurantManager.GetRestaurants();

            ViewData["AllRestaurants"] = allRestaurants;

            ViewBag.nameDL = HttpContext.Session.GetString("nameDL");
            var od = om.GetOrders_ds(id); //Get all orders according to the deliverer's id

            List <Order> odtrie = new List <Order>();

            //Creation of a list which will only contain the non delivery order(s)
            foreach (Order o in od)
            {
                if (o.status.Equals("non delivery"))
                {
                    odtrie.Add(o);
                }
            }

            return(View(odtrie)); //Display the non delivery order(s)
        }
示例#2
0
        // GET: Customer/Details/5
        public ActionResult Details()
        {
            if ((string)HttpContext.Session.GetString("login") != "Aucun customer n'est log" && (string)HttpContext.Session.GetString("login") != null) // A customer is logged ?
            {
                //Get the login of the current customer
                ViewBag.login = HttpContext.Session.GetString("login");

                //creation of multiple variables to check conditions and for the display
                IOrderDB               order           = new OrderDB(Configuration);
                IOrderManager          om              = new OrderManager(order);
                IDelivery_staffDB      dsDB            = new Delivery_staffDB(Configuration);
                IDelivery_staffManager dsM             = new Delivery_staffManager(dsDB);
                IDishDB              dish              = new DishDB(Configuration);
                IDishManager         dishManager       = new DishManager(dish);
                IOrder_dishesDB      order_Dishes      = new Order_dishesDB(Configuration);
                IOrder_dishesManager odm               = new Order_dishesManager(order_Dishes);
                IRestaurantDB        restaurant        = new RestaurantDB(Configuration);
                IRestaurantManager   restaurantManager = new RestaurantManager(restaurant);

                //Get the id of the current customer
                var id = (int)HttpContext.Session.GetInt32("id");

                //Get an orderlist according to the customer id
                var ordersList = om.GetOrders(id);

                //Creations of multiple ViewData for the display
                var allOrders = om.GetOrders();
                ViewData["AllOrders"] = allOrders;
                var allStaff = dsM.GetDelivery_staffs();
                ViewData["AllStaffs"] = allStaff;
                var allDishes = dishManager.GetAllDishes();
                ViewData["AllDishes"] = allDishes;
                var allOrderDishes = odm.GetAllOrders_dishes();
                ViewData["AllOrderDishes"] = allOrderDishes;
                var allRestaurants = restaurantManager.GetRestaurants();
                ViewData["AllRestaurants"] = allRestaurants;

                //Check if the customer has not order
                if (ordersList == null)
                {
                    return(RedirectToAction("DetailsNoOrder", "Customer", new { user = id.ToString() }));
                }
                else
                {
                    return(View(ordersList)); // Return the Details view
                }
            }
            else
            {
                return(RedirectToAction("Index", "Customer")); // return to the login page
            }
        }
示例#3
0
        //Display the dish(es) in a specific order
        public ActionResult DishesInOrder(int id)
        {
            IDishDB      dish        = new DishDB(Configuration);
            IDishManager dishManager = new DishManager(dish);

            IOrder_dishesDB      order_Dishes = new Order_dishesDB(Configuration);
            IOrder_dishesManager odm          = new Order_dishesManager(order_Dishes);

            //Creation of a ViewData for the display
            var allDishes = dishManager.GetAllDishes();

            ViewData["AllDishes"] = allDishes;


            var orderDishes = odm.GetOrders_dishes(id);

            return(View(orderDishes)); //Display the list of dish(es)
        }
示例#4
0
        //POST : Restaurtant/command
        public ActionResult Command()
        {
            //take back the Form
            string platun       = Request.Form["platun"];
            string platunun     = Request.Form["platunun"];
            string platununun   = Request.Form["platununun"];
            string platunununun = Request.Form["platunununun"];
            string deliveryTime = Request.Form["deliveryTime"];

            IDishDB                dish                = new DishDB(Configuration);
            IOrderDB               orderdb             = new OrderDB(Configuration);
            IOrder_dishesDB        orderddb            = new Order_dishesDB(Configuration);
            IDelivery_staffDB      dldb                = new Delivery_staffDB(Configuration);
            IRestaurantDB          restodb             = new RestaurantDB(Configuration);
            IDishManager           dishManager         = new DishManager(dish);
            IOrderManager          orderManager        = new OrderManager(orderdb);
            IOrder_dishesManager   order_DishesManager = new Order_dishesManager(orderddb);
            IDelivery_staffManager dlmanager           = new Delivery_staffManager(dldb);
            IRestaurantManager     restoManager        = new RestaurantManager(restodb);

            //creation of lists for create the orders and the order_dishes
            List <Dish_Order> dishlist = new List <Dish_Order>();
            //List of dish
            List <Dish> plat = dishManager.GetDishes((int)HttpContext.Session.GetInt32("idResto"));
            //List of quantity
            List <string> s = new List <string>();

            s.Add(platun);
            s.Add(platunun);
            if (platununun != null)
            {
                s.Add(platununun);
            }
            if (platunununun != null)
            {
                s.Add(platunununun);
            }

            int   x = 0;
            int   quantitytemp;
            float pricetemp;
            float priceGeneral = 0;

            //Creation of my ViewModel Dish_Order
            foreach (Dish d in plat)
            {
                Dish_Order order = new Dish_Order();
                order.Dish_Id    = d.dish_Id;
                order.Name       = d.name;
                order.Price      = d.price;
                pricetemp        = d.price;
                order.Quantity   = Int32.Parse(s.ElementAt(x));
                quantitytemp     = Int32.Parse(s.ElementAt(x));
                order.totalPrice = quantitytemp * pricetemp;
                priceGeneral    += quantitytemp * pricetemp;
                dishlist.Add(order);
                x++;
            }

            //Set the Final price for the view
            ViewBag.prix = priceGeneral;

            //if the customer has select at least 1 dish
            if (priceGeneral != 0)
            {
                //Create a new Order
                Order ikse = new Order();
                ikse.delivery_time = deliveryTime;
                ikse.totalPrice    = priceGeneral;
                ikse.customer_Id   = (int)HttpContext.Session.GetInt32("id");

                //select whitch delivery staff is available
                var dslist       = dlmanager.GetDelivery_staffs();
                int idDs         = -1;
                var listeresto   = restoManager.GetRestaurants();
                int cityCodeTemp = 0;

                //Select the list of delivery staff
                foreach (Delivery_staff ds in dslist)
                {
                    //find the city of the restaurant
                    foreach (Dish d in plat)
                    {
                        if (d.dish_Id == dishlist[0].Dish_Id)
                        {
                            foreach (Restaurant r in listeresto)
                            {
                                if (d.restaurant_Id == r.restaurant_Id)
                                {
                                    cityCodeTemp = r.cityCode;
                                }
                            }
                        }
                    }

                    //if the delivery staff is at the good city
                    if (ds.cityCode == cityCodeTemp)
                    {
                        var isbusy    = false;
                        var oListByDl = orderManager.GetOrders_ds(ds.delivery_staff_Id);
                        int cptOrder  = 0;
                        foreach (Order o in oListByDl)
                        {
                            //select the orders non delivery
                            if (o.status == "non delivery")
                            {
                                //change the 11:00 in 1100, change the minutes from base 60 to base 100 for calculation
                                string deliveryTimePourInt = o.delivery_time.Remove(2, 1);
                                string deliveryTimePartOne = deliveryTimePourInt.Substring(0, 2);
                                string deliveryTimePartTwo = deliveryTimePourInt.Substring(2);
                                int    test = Int32.Parse(deliveryTimePartTwo);
                                switch (test)
                                {
                                case 0:
                                    break;

                                case 15:
                                    test = 25;
                                    break;

                                case 30:
                                    test = 50;
                                    break;

                                case 45:
                                    test = 75;
                                    break;
                                }
                                deliveryTimePartTwo = test.ToString();

                                int deliveryTimeInt = Int32.Parse(deliveryTimePartOne + deliveryTimePartTwo);
                                //correct the houres
                                if (deliveryTimeInt % 10 == 0)
                                {
                                    deliveryTimeInt *= 10;
                                    if (deliveryTimeInt / 10000 != 0)
                                    {
                                        deliveryTimeInt /= 10;
                                    }
                                }
                                //same think for the delivery time of the order
                                string deliveryTimeForCompare = deliveryTime.Remove(2, 1);

                                string dtPartOne = deliveryTimeForCompare.Substring(0, 2);
                                string dtPartTwo = deliveryTimeForCompare.Substring(2);
                                int    essai     = Int32.Parse(dtPartTwo);
                                switch (essai)
                                {
                                case 0:
                                    break;

                                case 15:
                                    essai = 25;
                                    break;

                                case 30:
                                    essai = 50;
                                    break;

                                case 45:
                                    essai = 75;
                                    break;
                                }
                                dtPartTwo = essai.ToString();
                                int dTForCompare = Int32.Parse(dtPartOne + dtPartTwo);
                                if (dTForCompare % 10 == 0)
                                {
                                    dTForCompare *= 10;
                                    if (dTForCompare / 10000 != 0)
                                    {
                                        dTForCompare /= 10;
                                    }
                                }
                                int compare = (deliveryTimeInt - dTForCompare);

                                //if the order is within 15 minutes before or after the delivery staff's order
                                if (compare <= 25 && compare >= -25)
                                {
                                    cptOrder++;
                                }
                            }
                        }
                        //if the staff is busy
                        if (cptOrder >= 5)
                        {
                            isbusy = true;
                        }
                        //if the staff is free
                        if (isbusy == false)
                        {
                            //assign the staff to the order
                            idDs = ds.delivery_staff_Id;
                        }
                    }
                }
                //if a staff is free
                if (idDs != -1)
                {
                    //assign the staff
                    ikse.delivery_staff_Id = idDs;

                    //create the order in the database
                    var orderaiedi = orderManager.AddOrder(ikse);

                    //create the order dishes and add to the database
                    foreach (Dish_Order disho in dishlist)
                    {
                        Order_dishes order_dishes_ = new Order_dishes();
                        order_dishes_.order_Id = orderaiedi;
                        order_dishes_.dish_Id  = disho.Dish_Id;
                        order_dishes_.quantity = disho.Quantity;
                        order_dishes_.price    = disho.totalPrice;
                        if (order_dishes_.quantity != 0)
                        {
                            order_DishesManager.AddOrder_dishes(order_dishes_);
                        }
                    }
                    //return the normal view
                    return(View());
                }
                //if no staff is free
                else
                {
                    //return the error view
                    return(RedirectToAction("ErrorNoDs", "Restaurant"));
                }
            }
            //if the customer didn't select any dish, return the error view
            return(RedirectToAction("ErrorNoQuantity", "Restaurant"));
        }