Exemplo n.º 1
0
        /// <summary>
        /// Description: This method calls a method in DAL to retrieve the total price of food items
        /// </summary>
        /// <param name="iFoodItemIDPKsString">string of ids for food item</param>
        /// <returns>total price of food items</returns>
        public int CreateUserLineOrder(UserLineOrder iUserLineOrder)
        {
            // Instantiate objects
            RestaurantDAL lRestaurantDAL = new RestaurantDAL();

            // Get Total price of items ordered if it is not a sandwich restaurant
            if (iUserLineOrder.IsSandwichRestaurant != 1)
            {
                iUserLineOrder.OrderPrice = lRestaurantDAL.GetTotalPriceByFoodItemIDs(iUserLineOrder.FoodItemsIDString);
            }

            // Insert into database
            int lResult = lRestaurantDAL.CreateUserLineOrder(iUserLineOrder);

            return(lResult);
        }
Exemplo n.º 2
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"));
        }