// GET: RecipeController public IActionResult Index(RecipesIndexViewModel model) { var recipesVm = new List <RecipeViewModel>(); var recipes = _recipeService.GetAll(); foreach (var recipe in recipes) { if (_recipeService.IsVisible(recipe.Id, model.SearchText, model.CategoryName, model.IngredientName, true)) { recipesVm.Add(new RecipeViewModel { Id = recipe.Id, Name = recipe.Name, Description = recipe.Description, Note = recipe.Note, CategoryId = recipe.CategoryId }); } } model.Recipes = recipesVm; model.Categories = _categoryService.GetAll().ToSelectListItem <Category>(x => x.Name, x => x.Name); model.Ingredients = _recipeService.GetIngredients().ToSelectListItem <Ingredient>(x => x.Name, x => x.Name); return(View(model)); }
public IActionResult Index(string category) { var recipes = recipeService.GetRecipes(); if (!(category == "recentlyAdded" || category == null)) { recipes = recipeService.GetRecipes(r => r.Category.Name == category); } var vm = new RecipesIndexViewModel() { Recipes = recipes.ToList(), Categories = context.Categories.ToList(), RecipePictures = context.RecipePictures.ToList() }; return(View(vm)); }
public ActionResult GetBySeason(string season) { var recipes = this.recipes.GetBySeason(season) .To <RecipeViewModel>() .ToList(); var viewModel = new RecipesIndexViewModel { Recipes = recipes }; if (viewModel == null) { return(this.Redirect("/")); } return(this.View(viewModel)); }
public IActionResult Index(string category) { IEnumerable <Recipe> recipes = null; if (category == "recentlyAdded" || category == null) { recipes = context.Recipes.Include(r => r.Category).OrderByDescending(r => r.CreatedAt); } else { recipes = context.Recipes.Include(r => r.Category).Where(r => r.Category.Name == category); } var vm = new RecipesIndexViewModel() { Recipes = recipes.ToList(), Categories = context.Categories.ToList() }; return(View(vm)); }
// GET: Recipe public ActionResult Index() { var occasions = this.occasions.GetAll() .To <OccasionViewModel>() .ToList(); var recipes = this.recipes.GetAll() .To <RecipeViewModel>() .ToList(); var viewModel = new RecipesIndexViewModel { Occasions = occasions, Recipes = recipes }; if (viewModel == null) { return(this.Redirect("/")); } return(this.View(viewModel)); }