Exemple #1
0
        public ActionResult Add()
        {
            var viewModel = new RecipeCategoryViewModel()
            {
                Recipe       = new Recipe(),
                CategoryList = _context.Category.ToList()
            };

            return(View(viewModel));
        }
Exemple #2
0
        public ActionResult PendingEdit(int id)
        {
            var result = _context.Recipe.Find(id);

            if (result == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new RecipeCategoryViewModel()
            {
                Recipe       = result,
                CategoryList = _context.Category.ToList()
            };

            return(View("Add", viewModel));
        }
Exemple #3
0
        public ActionResult Save(Recipe recipe)
        {
            //Server side validation - start
            if (!ModelState.IsValid)
            {
                var viewModel = new RecipeCategoryViewModel()
                {
                    Recipe       = recipe,
                    CategoryList = _context.Category.ToList()
                };

                return(View("Add", viewModel));
            }
            //**********Server side validation - end *********
            if (recipe.ID == 0)
            {
                recipe.Approve = false;
                recipe.UserID  = User.Identity.GetUserId();
                _context.Recipe.Add(recipe);
            }
            else
            {
                var RecipeDb = _context.Recipe.First(c => c.ID == recipe.ID);

                RecipeDb.Title       = recipe.Title;
                RecipeDb.CategoryID  = recipe.CategoryID;
                RecipeDb.CookTime    = recipe.CookTime;
                RecipeDb.Country     = recipe.Country;
                RecipeDb.Description = recipe.Description;
                RecipeDb.Direction   = recipe.Direction;
                RecipeDb.Ingredients = recipe.Ingredients;
                RecipeDb.NumOfServ   = recipe.NumOfServ;
                RecipeDb.PrepTime    = recipe.PrepTime;
                RecipeDb.UserID      = User.Identity.GetUserId();
                RecipeDb.Approve     = true;
            }

            _context.SaveChanges();

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