Beispiel #1
0
        public ActionResult FoodItemCreate(FoodItem iFoodItem)
        {
            if (ModelState.IsValid)
            {
                // Instantiates objects
                RestaurantBLL    lRestaurantBLL    = new RestaurantBLL();
                RestaurantMapper lRestaurantMapper = new RestaurantMapper();

                // map Model object to database object
                FoodItemDBO lFoodItemDBO = lRestaurantMapper.MapModelToDBO(iFoodItem);

                // get a unique food item id as return value
                int lFoodItemIDPK = lRestaurantBLL.CreateFoodItem(lFoodItemDBO);

                // success
                if (lFoodItemIDPK > 0)
                {
                    return(Json(new { success = true, blank = "" }));
                }
            }
            else
            {
                // check errors
                //var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            return(Json(new { success = false }));
        }
Beispiel #2
0
        /// <summary>
        /// Description: This method calls a method in DAL to update a food item with new values
        /// </summary>
        /// <param name="iFoodItemDBO">food item to be updated</param>
        /// <returns>if successfully updated, return true. Otherwise, false</returns>
        public bool UpdateFoodItemByFoodItemID(FoodItemDBO iFoodItemDBO)
        {
            // Instantiate DAL object
            RestaurantDAL lRestaurantDAL = new RestaurantDAL();

            // get result of bool value
            bool lResult = lRestaurantDAL.UpdateFoodItemByFoodItemID(iFoodItemDBO);

            return(lResult);
        }
Beispiel #3
0
        /// <summary>
        /// Description: This method calls a method in DAL to retrieve data about a food item
        /// </summary>
        /// <param name="id">a unique food item id</param>
        /// <returns>a food item with data </returns>
        public FoodItemDBO FindFoodItemByFoodItemID(int id)
        {
            // Instantiate DAL object
            RestaurantDAL lRestaurantDAL = new RestaurantDAL();

            // food item object
            FoodItemDBO lFoodItemDBO = lRestaurantDAL.FindFoodItemByFoodItemID(id);

            return(lFoodItemDBO);
        }
Beispiel #4
0
        /// <summary>
        /// Description: This method calls a method in DAL to insert food item into database
        /// </summary>
        /// <param name="iFoodItemDBO">Food item to be inserted</param>
        /// <returns>If successfully inserted, return a unique food item id. Otherwise, 0</returns>
        public int CreateFoodItem(FoodItemDBO iFoodItemDBO)
        {
            // Instantiate DAL object
            RestaurantDAL lRestaurantDAL = new RestaurantDAL();

            // a unique food item id
            int lFoodItemIDPK = lRestaurantDAL.CreateFoodItem(iFoodItemDBO);

            return(lFoodItemIDPK);
        }
Beispiel #5
0
        /// <summary>
        /// Description: This method maps Fooditem Model object to Fooditem database object
        /// </summary>
        /// <param name="iFoodItem"></param>
        /// <returns></returns>
        public FoodItemDBO MapModelToDBO(FoodItem iFoodItem)
        {
            FoodItemDBO lFoodItemDBO = new FoodItemDBO();

            // set values
            lFoodItemDBO.FoodItemIDPK       = iFoodItem.FoodItemIDPK;
            lFoodItemDBO.FoodItemName       = iFoodItem.FoodItemName;
            lFoodItemDBO.FoodTypeIDFK       = iFoodItem.FoodTypeSelected;
            lFoodItemDBO.IngredientTypeIDFK = iFoodItem.IngredientTypeSelected;
            lFoodItemDBO.Description        = iFoodItem.Description;
            lFoodItemDBO.RestaurantIDFK     = iFoodItem.RestaurantIDFK;
            lFoodItemDBO.Price = iFoodItem.Price;
            return(lFoodItemDBO);
        }
Beispiel #6
0
        /// <summary>
        /// Description: This method maps food item database object to food item Model object
        /// </summary>
        /// <param name="iFoodItemDBO">Food item database object</param>
        /// <returns>food item Model object</returns>
        public FoodItem MapDBOToModel(FoodItemDBO iFoodItemDBO)
        {
            FoodItem lFoodItem = new FoodItem();

            // set values
            lFoodItem.FoodItemIDPK           = iFoodItemDBO.FoodItemIDPK;
            lFoodItem.FoodItemName           = iFoodItemDBO.FoodItemName;
            lFoodItem.FoodTypeSelected       = iFoodItemDBO.FoodTypeIDFK;
            lFoodItem.RestaurantIDFK         = iFoodItemDBO.RestaurantIDFK;
            lFoodItem.IsSandwichRestaurant   = iFoodItemDBO.IsSandwichRestaurant;
            lFoodItem.IngredientTypeSelected = iFoodItemDBO.IngredientTypeIDFK;
            lFoodItem.Description            = iFoodItemDBO.Description;
            lFoodItem.Price = iFoodItemDBO.Price;

            return(lFoodItem);
        }
Beispiel #7
0
        public ActionResult FoodItemUpdate(FoodItem iFoodItem)
        {
            if (ModelState.IsValid)
            {
                // Instantiate objects
                RestaurantBLL    lRestaurantBLL    = new RestaurantBLL();
                RestaurantMapper lRestaurantMapper = new RestaurantMapper();

                // Map Model to DB obejcts
                FoodItemDBO lFoodItemDBO = lRestaurantMapper.MapModelToDBO(iFoodItem);

                // get result of bool if successfully updated
                bool lResult = lRestaurantBLL.UpdateFoodItemByFoodItemID(lFoodItemDBO);

                if (lResult)
                {
                    return(Json(new { success = true }));
                }
            }

            return(Json(new { success = false }));
        }
Beispiel #8
0
        public ActionResult FoodItemUpdate(int id)
        {
            // Instantiate objects
            RestaurantBLL    lRestaurantBLL    = new RestaurantBLL();
            RestaurantMapper lRestaurantMapper = new RestaurantMapper();

            // Find Food item by id
            FoodItemDBO lFoodItemDBO = lRestaurantBLL.FindFoodItemByFoodItemID(id);
            FoodItem    lFoodItem    = lRestaurantMapper.MapDBOToModel(lFoodItemDBO);

            // find the list of food types and lists
            List <FoodTypeDBO>       lFoodTypeDBOList       = lRestaurantBLL.GetAllFoodTypes();       // main, side, etc
            List <IngredientTypeDBO> lIngredientTypeDBOList = lRestaurantBLL.GetAllFoodIngredients(); // for sandwich

            // Map List of DB Objects to List of Model
            List <FoodType>       lFoodTypeList   = lRestaurantMapper.MapDBOToModel(lFoodTypeDBOList);
            List <IngredientType> lIngredientList = lRestaurantMapper.MapDBOToModel(lIngredientTypeDBOList);

            lFoodItem.FoodTypeList       = lFoodTypeList;
            lFoodItem.IngredientTypeList = lIngredientList;

            // find food info frmo db
            return(PartialView("FoodItemUpdate", lFoodItem));
        }
Beispiel #9
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);
        }