Example #1
0
        //GET: home/index
        public ActionResult Index(string searchString)
        {
            SqlConnect recipeLoader = new SqlConnect();

            recipeLoader.retriveData("select * from Recipe");

            recipeList = RecipeAccess.getInstance().getRecipeList(recipeLoader.sqlTable);


            if (!String.IsNullOrEmpty(searchString))
            {
                switch (searchString.ToLower())
                {
                case "all":
                    break;

                case "food":
                    recipeList = recipeList.Where(s => s.type.Equals("food")).ToList();
                    break;

                case "drinks":
                    recipeList = recipeList.Where(s => s.type.Equals("drinks")).ToList();
                    break;

                default:
                    recipeList = recipeList.Where(s => s.name.ToLower().Contains(searchString.ToLower())).ToList <Recipe>();
                    break;
                }
            }

            return(View(recipeList));
        }
Example #2
0
        public ActionResult Dashboard()
        {
            List <Recipe> favouritedRecipeList = new List <Recipe>();
            List <Recipe> myRecipeList         = new List <Recipe>();

            //load from home recipe list
            //List<Recipe> recipeList = HomeController.recipeList;

            //load from database recipe list
            SqlConnect recipeLoader = new SqlConnect();

            recipeLoader.retriveData("select * from Recipe");

            List <Recipe> recipeList = RecipeAccess.getInstance().getRecipeList(recipeLoader.sqlTable);

            foreach (Recipe recipe in recipeList)
            {
                if (recipe.isEditable)
                {
                    myRecipeList.Add(recipe);
                }
                if (recipe.isFavourited)
                {
                    favouritedRecipeList.Add(recipe);
                }
            }

            return(View(new UserDashboardModel(myRecipeList, favouritedRecipeList)));
        }
Example #3
0
        public void AlterFav(string id)
        {
            int    recipe_id = Convert.ToInt32(id);
            Recipe recipe    = RecipeAccess.getInstance().getRecipe(recipe_id);

            int user_id = UserAccess.getInstance().getUser().id;

            //Toggle Favourites from database
            if (recipe.isFavourited)
            {
                //do unfavourite (remove)
                SqlConnect unfavouriteSQL = new SqlConnect();
                //unfavouriteSQL.cmdExecute("delete from favourites where user_id='" + user_id + "'and recipe_id='" + recipeId + "'", "Error removing from favourites");
                List <KeyValuePair <string, object> > param = new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>("@user_id", user_id),
                    new KeyValuePair <string, object>("@recipe_id", recipeId)
                };

                unfavouriteSQL.executeStoredProcedure("DeleteFavourites", param);
            }
            else
            {
                //do favourite (add)
                SqlConnect favouriteSQL = new SqlConnect();
                //favouriteSQL.cmdExecute("insert into favourites values('" + user_id + "','" + recipeId + "')", "Error saving to favourites");
                List <KeyValuePair <string, object> > param = new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>("@user_id", user_id),
                    new KeyValuePair <string, object>("@recipe_id", recipeId)
                };

                favouriteSQL.executeStoredProcedure("SetFavourites", param);
            }
        }
Example #4
0
        /************/
        /*** READ ***/
        /************/

        // GET: /Recipe/recipe/{id}
        public ActionResult Recipe(int id)
        {
            //Recipe recipe = getRecipeFromHome(id);
            Recipe recipe = RecipeAccess.getInstance().getRecipe(id);

            recipeId = id;

            return(View(recipe));
        }
Example #5
0
        //GET: /Recipe/Edit/{id}
        public ActionResult Edit(int recipeId)
        {
            //int recipeId = 1;
            //System.Diagnostics.Debug.Print("Id: " + recipeId);

            Recipe recipe = RecipeAccess.getInstance().getRecipe(recipeId);

            return(View(recipe));
        }
Example #6
0
        public ActionResult Create(Recipe recipe)
        {
            //upload image
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file.ContentType.ToLower() != "image/jpg" &&
                    file.ContentType.ToLower() != "image/jpeg" &&
                    file.ContentType.ToLower() != "image/pjpeg" &&
                    file.ContentType.ToLower() != "image/gif" &&
                    file.ContentType.ToLower() != "image/x-png" &&
                    file.ContentType.ToLower() != "image/png")
                {
                    ModelState.AddModelError("", "Not a valid image file");
                    return(View());
                }

                //string dd = DateTime.Now();

                if (file != null && file.ContentLength > 0)
                {
                    var imgName  = Path.GetFileName(file.FileName);
                    var fileName = generateUniqueID() + imgName;
                    var path     = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);
                    file.SaveAs(path);

                    recipe.img = fileName;  // [IMAGE]
                }
            }

            List <string> ingedrientsList = new List <string>();
            //get list of ingedrients
            string ingedrients = Request["ingedrients"].ToString();

            //System.Diagnostics.Debug.Print(ingedrients);

            string[] str = ingedrients.Split(',');      //separating ingedrients

            foreach (string s in str)
            {
                if (!string.IsNullOrWhiteSpace(s))
                {
                    ingedrientsList.Add(s);     // [INGEDRIENTS]
                }
            }

            //Response.Write("Valid Ingedrients count: " + ingedrientsList.Count);

            //recipe.id = HomeController.recipeList.Count + 1;    // [ID]
            recipe.id        = RecipeAccess.getInstance().getNewRecipeId();
            recipe.creatorId = UserAccess.getInstance().getUser().id;   // [CREATOR ID]

            /*************************************/
            /*************************************/
            //Write to database
            //Write recipe to [Recipe]

            //SqlConnect sql = new SqlConnect();
            //sql.cmdExecute("insert into recipe values ('" + recipe.id + "','" + recipe.creatorId + "','" + recipe.name + "','" + recipe.type + "','" + recipe.img + "','" + recipe.description + "','" + recipe.process + "')");

            //Write ingedrients to [Ingedrients]
            //foreach (string ingedrient in ingedrientsList)
            //{
            //    sql.cmdExecute("insert into Ingedrients values('" + recipe.id + "','" + ingedrient + "')");
            //}
            /*************************************/

            SqlConnect createSql = new SqlConnect();

            System.Diagnostics.Debug.Print("Type: " + recipe.type);

            List <KeyValuePair <string, object> > param = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("@id", recipe.id),
                new KeyValuePair <string, object>("@creatorId", recipe.creatorId),
                new KeyValuePair <string, object>("@name", recipe.name),
                new KeyValuePair <string, object>("@type", recipe.type),
                new KeyValuePair <string, object>("@img", recipe.img),
                new KeyValuePair <string, object>("@description", recipe.description),
                new KeyValuePair <string, object>("@process", recipe.process)
            };

            createSql.executeStoredProcedure("CreateRecipe", param);

            foreach (string ingedrient in ingedrientsList)
            {
                param.Clear();
                param.Add(new KeyValuePair <string, object>("@recipe_id", recipe.id));
                param.Add(new KeyValuePair <string, object>("@ingedrient", ingedrient));

                createSql.executeStoredProcedure("CreateRecipeIngedrients", param);
            }

            //return View();
            //return RedirectToAction("Index", "Home");
            return(RedirectToAction("Recipe", "Recipe", new { id = recipe.id }));
        }
Example #7
0
 //GET: /recipe/delete
 public ActionResult Delete()
 {
     //Are you sure?
     return(View(RecipeAccess.getInstance().getRecipe(recipeId)));
 }