示例#1
0
        public IActionResult Get(int id)
        {
            var recipe = _recipeData.GetById(id);
            var result = _mapper.Map <ApiRecipe>(recipe);

            return(Ok(result));
        }
示例#2
0
        public IActionResult Detail(int recipeId)
        {
            var recipe    = _recipeData.GetById(recipeId);
            var viewModel = new RecipeViewModel(_htmlHelper)
            {
                Recipe = recipe
            };

            return(View(viewModel));
        }
        private void RetrieveRecipe(string recipeId, string message)
        {
            if (string.IsNullOrEmpty(recipeId))
            {
                Recipe             = new Recipe();
                Recipe.Ingredients = new List <string>();
                Recipe.Directions  = new List <string>();
                FormTitle          = $" {Action.Adding.ToString()} Recipe";
            }
            else
            {
                Recipe    = recipeData.GetById(recipeId);
                FormTitle = $"{Action.Editing.ToString()} {Recipe.Name}";
                Message   = message;
            }

            var categories = this.categoryData.GetAll().Select(c => new SelectListItem {
                Value = c.Id, Text = c.Name
            }).ToList();

            categories.Insert(0, new SelectListItem {
                Value = string.Empty, Text = "Select..."
            });
            Categories = categories;
        }
示例#4
0
        public IActionResult OnGet(int?ingredientId, int recipeId)
        {
            var recipe = recipeData.GetById(recipeId);

            if (ingredientId.HasValue)
            {
                Ingredient = ingredientData.GetById(ingredientId.Value);
            }
            else
            {
                Ingredient          = new Ingredient();
                Ingredient.RecipeId = recipe.Id;
            }

            if (Ingredient == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            if (Ingredient.RecipeId == recipe.Id)
            {
                return(Page());
            }
            else
            {
                return(RedirectToPage("/'Notfound"));
            }
            return(Page());
        }
示例#5
0
        public async Task <ActionResult> OnPostAsync(int recipeId)
        {
            var recipe = recipeData.GetById(recipeId);
            var user   = await userManager.GetUserAsync(User);

            favoriteRecipeData.AddToFavorites(recipe, user);

            return(Redirect(Request.Headers["Referer"].ToString()));
        }
示例#6
0
 public IActionResult OnGet(int recipeId)
 {
     Recipe = recipeData.GetById(recipeId);
     if (Recipe == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
示例#7
0
        public IActionResult OnGet(int?recipeId)
        {
            Recipe = recipeData.GetById(recipeId.Value);

            // Authorizing the user to edit their own recipes
            var currentUserId = userManager.GetUserId(User);
            var authorId      = Recipe.UserId;

            if (currentUserId == authorId)
            {
                Cuisines   = htmlHelper.GetEnumSelectList <CuisineType>();
                Difficulty = htmlHelper.GetEnumSelectList <DifficultyType>();
                if (Recipe == null)
                {
                    return(RedirectToPage("./NotFound"));
                }
                return(Page());
            }
            return(RedirectToPage("./List"));
        }
示例#8
0
        public IActionResult Detail(int recipeId)
        {
            var recipe = _recipeData.GetById(recipeId);


            int divider = recipe.GetTotalNutrient("fat") + recipe.GetTotalNutrient("carbs") + recipe.GetTotalNutrient("proteins");

            var viewModel = new RecipeViewModel(_htmlHelper)
            {
                Recipe = recipe
            };

            if (divider != 0)
            {
                viewModel.ProteinRatio = 100 * recipe.GetTotalNutrient("proteins") / divider;
                viewModel.FatRatio     = 100 * recipe.GetTotalNutrient("fat") / divider;
                viewModel.CarbRatio    = 100 * recipe.GetTotalNutrient("carbs") / divider;
            }


            return(View(viewModel));
        }
示例#9
0
        public IActionResult OnGet(string recipeId)
        {
            var recipe = recipeData.GetById(recipeId);

            if (recipe == null)
            {
                return(RedirectToPage("NotFound"));
            }

            MenuRecipeDetailModel = new MenuRecipeDetailModel {
                Recipe = recipe, CategoryNameOfRecipe = categoryData.GetById(recipe.CategoryId)?.Name
            };

            return(Page());
        }
示例#10
0
 public IActionResult OnGet(int?recipeId)
 {
     Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
     if (recipeId.HasValue)
     {
         Recipe = recipeData.GetById(recipeId.Value);
     }
     else
     {
         Recipe = new Recipe();
     }
     if (Recipe == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
示例#11
0
        public async System.Threading.Tasks.Task <IActionResult> OnGetAsync(int recipeId)
        {
            // Get the recipe
            Recipe = recipeData.GetById(recipeId);
            if (Recipe == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            // Get Current Menu for Cookbook
            CurrentMenu = HttpContext.Session.GetObjectFromJson <List <int> >("CurrentMenu");
            if (CurrentMenu == null)
            {
                CurrentMenu = new List <int>();
            }

            // Get Current User Id
            CurrentUserId = userManager.GetUserId(User);
            var user = await userManager.GetUserAsync(User);

            // Get favorites status
            IsFavorited = favoriteRecipeData.IsFavorited(Recipe, user);


            // Get Viewed Recipes
            var viewedRecipes = HttpContext.Session.GetObjectFromJson <List <int> >("ViewedRecipesKey");

            if (viewedRecipes == null)
            {
                viewedRecipes = new List <int>();
            }
            viewedRecipes.Add(recipeId);
            HttpContext.Session.SetObjectAsJson("ViewedRecipesKey", viewedRecipes);

            return(Page());
        }