Example #1
0
 public RecipeViewModel(Recipe recipe, List<Category> categories, List<SubCategory> subCategories, int id, int sid)
 {
     Recipe = recipe;
     Categories = categories;
     SubCategories = subCategories;
     CategoryID = id;
     SubCategoryID = sid;
 }
Example #2
0
 public ActionResult Create()
 {
     Category selectedCategory = repository.GetAllCategories().First();
     Recipe recipe = new Recipe();
     return View(new RecipeViewModel(recipe, repository.GetAllCategories(), repository.GetSubCategoriesByCategoryId(selectedCategory.CategoryID), selectedCategory.CategoryID, 0));
 }
Example #3
0
        private void ValidateRecipeModel(Recipe recipe)
        {
            if (recipe.Category == null || recipe.Category.CategoryID <= 0)
            {
                ModelState.AddModelError(string.Empty, Constants.Constants.RecipeHasNoCategory);
                recipe.Category = repository.GetAllCategories().OrderBy(c => c.CategoryID).FirstOrDefault();
            }

            if (recipe.SubCategoryID <= 0)
            {
                ModelState.AddModelError(string.Empty, Constants.Constants.RecipeHasNoSubCategory);
            }

            if (recipe.RecipeIngredients == null || recipe.RecipeIngredients.Count() < 1)
            {
                ModelState.AddModelError(string.Empty, Constants.Constants.RecipeHasNoIngredients);
            }
        }
 public static void AddRecipe(Recipe recipe)
 {
     recipes.Add(recipe);
 }