示例#1
0
        public ActionResult Details(string id)
        {
            RecipeModel details = recipeDal.RecipeDetail(Convert.ToInt32(id));

            details.TagsList   = recipeDal.GetTagsFromId(Convert.ToInt32(id));
            details.Categories = recipeDal.GetCatsFromId(Convert.ToInt32(id));
            if (Authorize.Registered((int?)Session["authorizationlevel"]) == true || Authorize.Admin((int?)Session["authorizationlevel"]) == true)
            {
                UserModel     user  = Session["user"] as UserModel;
                PlanModel     p     = new PlanModel();
                DropDownPlans model = new DropDownPlans();

                model.selectedRecipe = Convert.ToInt32(id);
                List <PlanModel> plans = planDal.GetAllUserPlans(user.UserID);
                foreach (PlanModel plan in plans)
                {
                    string planname = planDal.GetPlanName(plan.PlanId);
                    plan.PlanName = planname;
                }
                List <string> days  = p.Days;
                List <string> meals = p.Meals;

                //model.Recipes = recipes;
                model.PlanModels    = plans;
                model.Days          = days;
                model.Meals         = meals;
                Session["dropDown"] = model;
            }

            return(View(details));
        }
示例#2
0
 public ActionResult Admin()
 {
     if (Authorize.Admin((int?)Session["authorizationlevel"]) == true)
     {
         //ViewBag.Model = new RecipeModel();
         List <RecipeModel> model = recipeDal.GetRecipes();
         RecipeModel        users = new RecipeModel();
         Session["subscribers"] = recipeDal.SubscribedUsers();
         //model.Add(users);
         ViewBag.Subsribers = recipeDal.SubscribedUsers();
         return(View(model));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
示例#3
0
        public ActionResult AddRecipe()
        {
            if (Authorize.Registered((int?)Session["authorizationlevel"]) == true || Authorize.Admin((int?)Session["authorizationlevel"]) == true)
            {
                RecipeModel model = new RecipeModel();
                Dictionary <string, bool> choose = new Dictionary <string, bool>();
                List <string>             cats   = recipeDal.GetCategories();
                foreach (string s in cats)
                {
                    choose[s] = false;
                }
                model.ChoseCategory = choose;

                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
示例#4
0
        public ActionResult AddRecipe(RecipeModel recipe)
        {
            if (recipe.ChoseCategory == null || recipe.Ingredients == null || recipe.Name == null || recipe.Tags == null || recipe.Directions == null)
            {
                return(RedirectToAction("AddRecipe"));
            }
            UserModel user = Session["user"] as UserModel;

            // When a user logs in, Session[authorizationlevel] stores their auth level as 1, 2 ,3 or null.  From the Authorize class,
            // runs the Admin method, taking in Session cast as a int?
            // If the method returns true, only admins will be able to do this action, else returns redirect to another action.
            if (Authorize.Registered((int?)Session["authorizationlevel"]) == true || Authorize.Admin((int?)Session["authorizationlevel"]) == true)
            {
                List <string> tagArray = new List <string>();
                string        fileName = "";
                //try
                //{
                //    if (ImageName.ContentLength > 0)
                //    {
                //        fileName = Path.GetFileName(ImageName.FileName);
                //        string path = Path.Combine(Server.MapPath("~/Img/"), fileName);
                //        ImageName.SaveAs(path);
                //    }
                //    ViewBag.Message = "File Uploaded Successfully!";
                //}
                //catch
                //{
                //    ViewBag.Message = "File Upload Failed!";
                //}
                //recipe.ImageName = fileName;
                if (recipe.PublicOrPrivate != null)
                {
                    recipe.Publics = Int32.Parse(recipe.PublicOrPrivate);
                }
                int recipeId = recipeDal.NewRecipe(recipe);
                recipeDal.InsertRecipeIdAndUserId(user.UserID, recipeId);
                if (recipe.Tags != null)
                {
                    tagArray = recipe.Tags.Split(';').ToList <string>();
                    for (int i = 0; i < tagArray.Count; i++)
                    {
                        tagArray[i] = tagArray[i].ToLower();
                    }
                }

                List <int> exists = recipeDal.TagsExist(recipe.Tags);
                if (tagArray.Count != 0)
                {
                    for (int i = 0; i < tagArray.Count; i++)
                    {
                        if (exists[i] > 0)
                        {
                            int tagId = recipeDal.GetTagIdIfExists(tagArray[i].TrimStart(' '));
                            recipeDal.InsertRecipeIdAndTagId(recipeId, tagId);
                        }
                        else
                        {
                            int tagId = recipeDal.GetTagIdAfterInsert(tagArray[i].TrimStart(' '));
                            recipeDal.InsertRecipeIdAndTagId(recipeId, tagId);
                        }
                    }
                }
                foreach (KeyValuePair <string, bool> kvp in recipe.ChoseCategory)
                {
                    if (kvp.Value == true)
                    {
                        int catId = recipeDal.GetCategoryId(kvp.Key);
                        recipeDal.InsertRecipeAndCategoryId(recipeId, catId);
                    }
                }

                return(RedirectToAction("RecipeConfirmation"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }