Exemplo n.º 1
0
        public ActionResult OrderSelection(int id)
        {
            // Instantiate objects
            RestaurantBLL    lRestaurantBLL = new RestaurantBLL();
            RestaurantMapper lMapper        = new RestaurantMapper();

            // current user id
            int lUserIDFK = Convert.ToInt32(Session["AUTHUserIDPK"]);

            // get delivery day for the restaurant
            int lDayOfWeek = lRestaurantBLL.FindDayOfDelieveryByRestaurantID(id);
            int today      = (int)DateTime.Now.DayOfWeek;

            // Check if it is the first order for the restaurant of the current user this week
            bool AlreadyOrdered = lRestaurantBLL.FindOrderCountThisWeekByUserIDAndRestaurantID(lUserIDFK, id);

            // The user already ordered, return to restaurant index page with message
            if (AlreadyOrdered)
            {
                // message for user
                TempData["msg"] = "<script>alert('You have already ordered!');</script>";
                return(RedirectToAction("Index", "Restaurant"));
            }
            else if (lDayOfWeek != today)
            {
                if (lDayOfWeek > today)
                {
                    // message for trying to order for future
                    TempData["msg"] = "<script>alert('You cannot order today.');</script>";
                }
                else
                {
                    // message for past day
                    TempData["msg"] = "<script>alert('You can order next week.');</script>";
                }

                return(RedirectToAction("Index", "Restaurant"));
            }

            // Instantiate FoodItemListUtil object
            FoodItemsListUtil lFoodItemsListUtil = new FoodItemsListUtil();

            // Find if the restaurant offer sandwich
            lFoodItemsListUtil.Restaurant           = lRestaurantBLL.FindRestaurantByRestaurantID(id);
            lFoodItemsListUtil.IsSandwichRestaurant = lFoodItemsListUtil.Restaurant.IsSandwichRestaurant;
            lFoodItemsListUtil.RestaurantIDFK       = id;

            // populate menus for restaurants that do NOT offer sandwich
            if (lFoodItemsListUtil.IsSandwichRestaurant == 0)
            {
                // Entree List - Drop down
                lFoodItemsListUtil.EntreeList = lRestaurantBLL.GetAllEntreeByRestaurantID(id);

                // Side List - Check box
                lFoodItemsListUtil.SideList = lRestaurantBLL.GetAllSidesByRestaurantID(id);


                // Beverage List - Drop Down
                lFoodItemsListUtil.BeverageList = lRestaurantBLL.GetAllBeveragesByRestaurantID(id);
            }

            // populate menus for restaurants that do offer sandwich
            else
            {
                // Cheese List
                lFoodItemsListUtil.CheeseList = lRestaurantBLL.GetAllCheeseByRestaurantID(id);

                // Meat List
                lFoodItemsListUtil.MeatList = lRestaurantBLL.GetAllMeatByRestaurantID(id);

                // Bread List
                lFoodItemsListUtil.BreadList = lRestaurantBLL.GetAllBreadByRestaurantID(id);

                // Veggie List
                lFoodItemsListUtil.VeggieList = lRestaurantBLL.GetAllVeggieByRestaurantID(id);

                // Condiment List
                lFoodItemsListUtil.CondimentList = lRestaurantBLL.GetAllCondimentByRestaurantByID(id);
            }

            // Map database object to Model
            FoodItemsListUtilModel lListUtilModel = lMapper.MapDBOToModel(lFoodItemsListUtil);

            return(View(lListUtilModel));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Description: This method maps Model object to database object
        /// </summary>
        /// <param name="iFoodItemsListUtil">Model Object with entrees, sides, beverages or choices for sandwich</param>
        /// <returns>Database Object that has data about entrees, sides, beverages or choices for sandwich</returns>
        public FoodItemsListUtil MapModelToDBO(FoodItemsListUtilModel iUtilModel)
        {
            // object to be returned
            FoodItemsListUtil lFoodItemsList = new FoodItemsListUtil();

            // map data about restaurant
            lFoodItemsList.RestaurantIDFK       = iUtilModel.RestaurantIDFK;
            lFoodItemsList.RestaurantName       = iUtilModel.RestaurantName;
            lFoodItemsList.IsSandwichRestaurant = iUtilModel.IsSandwichRestaurant;
            lFoodItemsList.SandwichPrice        = iUtilModel.PerSandwichPrice;
            lFoodItemsList.UserIDFK             = iUtilModel.UserIDFK;
            lFoodItemsList.UserNote             = iUtilModel.UserNote;

            // Is NOT sandwich restaurant
            if (iUtilModel.IsSandwichRestaurant == 0)
            {
                // store Selected sides
                lFoodItemsList.SideList = new List <FoodItemDBO>();

                // map entree
                lFoodItemsList.EntreeID   = iUtilModel.EntreeID;
                lFoodItemsList.EntreeName = iUtilModel.EntreeName;


                // check for null
                if (iUtilModel.SideList != null)
                {
                    // map each side chosen
                    foreach (FoodItem each in iUtilModel.SideList.Where(foodItem => foodItem.IsSelected == true).ToList())
                    {
                        FoodItemDBO lFoodItemDBO = new FoodItemDBO();

                        //set values
                        lFoodItemDBO.FoodItemIDPK = each.FoodItemIDPK;
                        lFoodItemDBO.FoodItemName = each.FoodItemName;
                        lFoodItemDBO.IsSelected   = each.IsSelected;

                        lFoodItemsList.SideList.Add(lFoodItemDBO);
                    }
                }

                // map Beverage
                lFoodItemsList.BeverageID   = iUtilModel.BeverageID;
                lFoodItemsList.BeverageName = iUtilModel.BeverageName;
            }
            else
            {
                // lists to stored selected ones
                lFoodItemsList.VeggieList    = new List <FoodItemDBO>();
                lFoodItemsList.CondimentList = new List <FoodItemDBO>();

                // map cheese
                lFoodItemsList.CheeseID   = iUtilModel.CheeseID;
                lFoodItemsList.CheeseName = iUtilModel.CheeseName;

                // map meat
                lFoodItemsList.MeatID   = iUtilModel.MeatID;
                lFoodItemsList.MeatName = iUtilModel.MeatName;

                // map bread
                lFoodItemsList.BreadID   = iUtilModel.BreadID;
                lFoodItemsList.BreadName = iUtilModel.BreadName;

                // check for null
                if (iUtilModel.VeggieList != null)
                {
                    // map each veggie chosen
                    foreach (FoodItem each in iUtilModel.VeggieList.Where(veggie => veggie.IsSelected == true).ToList())
                    {
                        FoodItemDBO lFoodItemDBO = new FoodItemDBO();

                        // set values
                        lFoodItemDBO.FoodItemIDPK = each.FoodItemIDPK;
                        lFoodItemDBO.FoodItemName = each.FoodItemName;
                        lFoodItemDBO.IsSelected   = each.IsSelected;

                        lFoodItemsList.VeggieList.Add(lFoodItemDBO);
                    }
                }

                // check for null
                if (iUtilModel.CondimentList != null)
                {
                    // map each condiment chosen
                    foreach (FoodItem each in iUtilModel.CondimentList.Where(condiment => condiment.IsSelected == true).ToList())
                    {
                        FoodItemDBO lFoodItemDBO = new FoodItemDBO();

                        // set values
                        lFoodItemDBO.FoodItemIDPK = each.FoodItemIDPK;
                        lFoodItemDBO.FoodItemName = each.FoodItemName;
                        lFoodItemDBO.IsSelected   = each.IsSelected;

                        lFoodItemsList.CondimentList.Add(lFoodItemDBO);
                    }
                }
            }

            return(lFoodItemsList);
        }
Exemplo n.º 3
0
        public ActionResult OrderSelection(FoodItemsListUtilModel iFoodItemListUtil)
        {
            // instantiate objects
            RestaurantBLL    lRestaurantBLL    = new RestaurantBLL();
            RestaurantMapper lRestaurantMapper = new RestaurantMapper();

            // check if every input is valid and check if user chosed more than 1 food item
            if (ModelState.IsValid)
            {
                // map Model to database object
                FoodItemsListUtil lFoodItemsListUtil = lRestaurantMapper.MapModelToDBO(iFoodItemListUtil);

                // Instantiate UserLineOrder object
                UserLineOrder lUserLineOrder = new UserLineOrder();

                // Get user choices for restaurants that do not offer sandwich
                if (iFoodItemListUtil.IsSandwichRestaurant == 0)
                {
                    // count the number of sides chosen
                    int SideListCount = lFoodItemsListUtil.SideList.Where(s => s.IsSelected == true).ToList().Count;

                    // check if user chosed more than 1 food item
                    if (lFoodItemsListUtil.EntreeID == null && SideListCount == 0 && lFoodItemsListUtil.BeverageID == null)
                    {
                        TempData["msg"] = "<script>alert('Please choose at least 1 food item.');</script>";
                        return(RedirectToAction("OrderSelection", "Restaurant", new { id = iFoodItemListUtil.RestaurantIDFK }));
                    }


                    // limit number of sides to choose
                    if (SideListCount <= 2)
                    {
                        // create order and get the order id from the inserted row in UserOrder
                        int lUserOrderIDPK = lRestaurantBLL.CreateUserOrder(lFoodItemsListUtil);

                        lUserLineOrder.UserOrderIDFK = lUserOrderIDPK;
                        lUserLineOrder.FoodItemsList = new List <FoodItemDBO>();

                        // add selected entree to the list
                        lUserLineOrder.FoodItemsList.Add(new FoodItemDBO(Convert.ToInt32(lFoodItemsListUtil.EntreeID), lFoodItemsListUtil.EntreeName));

                        // add selected sides to the list
                        foreach (FoodItemDBO each in lFoodItemsListUtil.SideList)
                        {
                            lUserLineOrder.FoodItemsList.Add(each);
                        }

                        // add selected beverage to the list
                        lUserLineOrder.FoodItemsList.Add(new FoodItemDBO(Convert.ToInt32(lFoodItemsListUtil.BeverageID), lFoodItemsListUtil.BeverageName));
                    }
                    else
                    {
                        // message for choosing too many sides
                        TempData["msg"] = "<script>alert('You should choose less than 2 sides');</script>";
                        return(RedirectToAction("OrderSelection", "Restaurant", new { id = iFoodItemListUtil.RestaurantIDFK }));
                    }
                }

                // get user choices for restaurants that do offer sandwich
                else
                {
                    // Get the user id from the inserted row in UserOrder
                    int lUserOrderIDPK = lRestaurantBLL.CreateUserOrder(lFoodItemsListUtil);

                    // Insert into database (UserLineOrder) - UserOrderIDFK, FoodItemFK
                    lUserLineOrder.UserOrderIDFK = lUserOrderIDPK;
                    lUserLineOrder.FoodItemsList = new List <FoodItemDBO>();

                    // add selected cheese to the list
                    lUserLineOrder.FoodItemsList.Add(new FoodItemDBO(Convert.ToInt32(lFoodItemsListUtil.CheeseID), lFoodItemsListUtil.CheeseName));

                    // add selected meat to the list
                    lUserLineOrder.FoodItemsList.Add(new FoodItemDBO(Convert.ToInt32(lFoodItemsListUtil.MeatID), lFoodItemsListUtil.MeatName));

                    // add selected bread to the list
                    lUserLineOrder.FoodItemsList.Add(new FoodItemDBO(Convert.ToInt32(lFoodItemsListUtil.BreadID), lFoodItemsListUtil.BreadName));

                    // add selected veggies to the list
                    foreach (FoodItemDBO each in lFoodItemsListUtil.VeggieList)
                    {
                        lUserLineOrder.FoodItemsList.Add(each);
                    }

                    // add selected condiments to the list
                    foreach (FoodItemDBO each in lFoodItemsListUtil.CondimentList)
                    {
                        lUserLineOrder.FoodItemsList.Add(each);
                    }
                }

                // Append each food item id and name as string if foodItemsList is not emtory
                if (lUserLineOrder.FoodItemsList != null)
                {
                    foreach (FoodItemDBO each in lUserLineOrder.FoodItemsList)
                    {
                        lUserLineOrder.FoodItemsIDString   += each.FoodItemIDPK + ",";
                        lUserLineOrder.FoodItemsNameString += each.FoodItemName + ",";
                    }

                    // set values
                    lUserLineOrder.OrderPrice           = iFoodItemListUtil.PerSandwichPrice;
                    lUserLineOrder.IsSandwichRestaurant = iFoodItemListUtil.IsSandwichRestaurant;

                    // insert all food items selected into database
                    int lResult = lRestaurantBLL.CreateUserLineOrder(lUserLineOrder);

                    if (lResult > 0)
                    {
                        // redirect to order confirmation page
                        return(RedirectToAction("OrderConfirm", new { UserLineOrder = lUserLineOrder.FoodItemsNameString }));
                    }
                    else
                    {
                        // message on failure
                        TempData["msg"] = "<script>alert('Your Order is not submitted. Please try again.');</script>";
                    }
                }
            }
            else
            {
                // Model - not valid
                TempData["msg"] = "<script>alert('Please Fill all Required Information');</script>";
            }


            return(RedirectToAction("Index", "Restaurant"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Description: This method maps database object to Model object
        /// </summary>
        /// <param name="iFoodItemsListUtil">Object that has data about entrees, sides, beverages or choices for sandwich</param>
        /// <returns>Model Object with entrees, sides, beverages or choices for sandwich</returns>
        public FoodItemsListUtilModel MapDBOToModel(FoodItemsListUtil iFoodItemsListUtil)
        {
            FoodItemsListUtilModel lUtilModel = new FoodItemsListUtilModel();

            // set values for model object
            lUtilModel.RestaurantIDFK       = iFoodItemsListUtil.Restaurant.RestaurantIDPK;
            lUtilModel.RestaurantName       = iFoodItemsListUtil.Restaurant.RestaurantName;
            lUtilModel.IsSandwichRestaurant = iFoodItemsListUtil.Restaurant.IsSandwichRestaurant;
            lUtilModel.RestaurantNotice     = iFoodItemsListUtil.Restaurant.Notice;
            lUtilModel.PerSandwichPrice     = iFoodItemsListUtil.Restaurant.SandwichPrice;

            // for a restaurant that does not offer sandwich
            if (lUtilModel.IsSandwichRestaurant == 0)
            {
                // For restaurants that do not offer sandwich
                lUtilModel.EntreeList   = new List <FoodItem>();
                lUtilModel.SideList     = new List <FoodItem>();
                lUtilModel.BeverageList = new List <FoodItem>();

                // populate list for entree, side and beverage
                // map each entree
                foreach (FoodItemDBO each in iFoodItemsListUtil.EntreeList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;

                    lUtilModel.EntreeList.Add(lFood);
                }


                // map each side
                foreach (FoodItemDBO each in iFoodItemsListUtil.SideList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;

                    lUtilModel.SideList.Add(lFood);
                }

                // map each beverage
                foreach (FoodItemDBO each in iFoodItemsListUtil.BeverageList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;

                    lUtilModel.BeverageList.Add(lFood);
                }
            }
            else
            {
                // For restaurants that offer sandwich
                lUtilModel.CheeseList    = new List <FoodItem>();
                lUtilModel.MeatList      = new List <FoodItem>();
                lUtilModel.BreadList     = new List <FoodItem>();
                lUtilModel.VeggieList    = new List <FoodItem>();
                lUtilModel.CondimentList = new List <FoodItem>();

                // populate list for cheese, meat, bread, veggie, and condiment
                // map each Cheese
                foreach (FoodItemDBO each in iFoodItemsListUtil.CheeseList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;

                    lUtilModel.CheeseList.Add(lFood);
                }

                // map each Meat
                foreach (FoodItemDBO each in iFoodItemsListUtil.MeatList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;

                    lUtilModel.MeatList.Add(lFood);
                }

                // map each Bread
                foreach (FoodItemDBO each in iFoodItemsListUtil.BreadList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;
                    lUtilModel.BreadList.Add(lFood);
                }

                // map each Veggie
                foreach (FoodItemDBO each in iFoodItemsListUtil.VeggieList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;
                    lUtilModel.VeggieList.Add(lFood);
                }

                // map each Condiment
                foreach (FoodItemDBO each in iFoodItemsListUtil.CondimentList)
                {
                    FoodItem lFood = new FoodItem();

                    // set values
                    lFood.FoodItemIDPK = each.FoodItemIDPK;
                    lFood.FoodItemName = each.FoodItemName;
                    lFood.IsSelected   = each.IsSelected;
                    lUtilModel.CondimentList.Add(lFood);
                }
            }

            return(lUtilModel);
        }