Exemplo n.º 1
0
        public IActionResult ManuallyAddRecipe(AddRecipeForm form)
        {
            if (authProvider.IsLoggedIn)
            {
                Recipe r = new Recipe()
                {
                    Name         = form.Name,
                    Description  = form.Description,
                    DateAdded    = DateTime.Now,
                    Source       = form.Source,
                    PrepMinutes  = form.PrepMinutes,
                    CookMinutes  = form.CookMinutes,
                    UserWhoAdded = authProvider.GetCurrentUser(),

                    Steps          = form.ParseSteps(),
                    ImageLocations = form.ParseImageLocations(),
                    Ingredients    = form.ParseIngredients()
                };

                if (recipeDAL.AddRecipe(r) != null)
                {
                    return(View("Recipe", r));
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
        public IActionResult Create(RecipeViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                HttpContext.Session.SetString("NewRecipeStatus", "Partial");

                return(RedirectToAction("Create"));
            }

            List <Ingredient> ingredientList   = new List <Ingredient>();
            List <string>     ingredientStrArr = viewModel.ModelList;

            List <string> categories = new List <string>();

            categories.Add(ingredientStrArr[5]);
            categories.Add(ingredientStrArr[6]);
            categories.Add(ingredientStrArr[7]);

            Recipe recipe = new Recipe
            {
                Name         = ingredientStrArr[0],
                Description  = ingredientStrArr[1],
                Instructions = ingredientStrArr[2],
                PrepTime     = Convert.ToInt32(ingredientStrArr[3]),
                CookTime     = Convert.ToInt32(ingredientStrArr[4]),
                Categories   = categories
            };

            for (int i = 8; i < ingredientStrArr.Count; i += 4)
            {
                if (ingredientStrArr[i] != "**delete**")
                {
                    Ingredient ingredient = new Ingredient
                    {
                        Number   = ingredientStrArr[i],
                        Fraction = ingredientStrArr[i + 1],
                        Unit     = ingredientStrArr[i + 2],
                        Name     = ingredientStrArr[i + 3]
                    };

                    ingredientList.Add(ingredient);
                }
            }

            recipe.Ingredients = ingredientList;

            int recipeId = recipeDAL.AddRecipe(recipe);

            if (recipeId > 0)
            {
                HttpContext.Session.SetString("NewRecipeStatus", "Complete");

                return(RedirectToAction("Detail", "Recipe", new { id = Convert.ToString(recipeId) }));
            }

            return(RedirectToAction("Create"));
        }
Exemplo n.º 3
0
        public IActionResult Post(Recipe recipe)
        {
            IActionResult output = Unauthorized();

            if (authProvider.IsLoggedIn)
            {
                recipe.UserWhoAdded   = authProvider.GetCurrentUser();
                recipe.DateAdded      = DateTime.Now;
                recipe.ImageLocations = recipe.ImageLocations == null ? new List <string>() : recipe.ImageLocations;

                output = StatusCode(200, recipeDAL.AddRecipe(recipe));
            }

            return(output);
        }
        public ActionResult New(Recipe r, HttpPostedFileBase uploadedImage)
        {
            if (uploadedImage != null)
            {
                string fileName = System.IO.Path.GetFileName(uploadedImage.FileName);
                string path     = System.IO.Path.Combine(
                    Server.MapPath("~/images/recipe"), fileName);

                // Save
                uploadedImage.SaveAs(path);
                r.ImageName = fileName;
            }

            recipeDal.AddRecipe(r);

            //Save in Session that they just created a recipe
            TempData["StatusMessage"] = "Success! Your recipe was successfully added!";

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 5
0
        public IActionResult ParseUrl(ParseURLForm form)
        {
            ObjectResult output = StatusCode(500, error.ParseUrl);

            if (authProvider.IsLoggedIn)
            {
                User currentUser = authProvider.GetCurrentUser();

                if (form.IsSupportedWebsite())
                {
                    Recipe newRecipe = form.Parse();
                    newRecipe.UserWhoAdded = currentUser;
                    newRecipe = recipeDAL.AddRecipe(newRecipe);

                    if (newRecipe != null)
                    {
                        output = StatusCode(200, newRecipe);
                    }
                }
                else
                {
                    WebsiteRequest wr = form.GenerateWebsiteRequest();
                    wr.User = currentUser;
                    websiteRequestDAL.AddNewWebsiteRequest(wr);

                    emailProvider.NewWebsiteRequest(wr);


                    output = StatusCode(501, wr);
                }
            }
            else
            {
                output = StatusCode(401, error.NotLoggedIn);
            }

            return(output);
        }
Exemplo n.º 6
0
        public IActionResult AddRecipe(Recipes recipe)
        {
            recipeDAL.AddRecipe(recipe);

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