public ActionResult Edit([Bind(Include = "ID,clientId,CategoryID,Title,Content")] Recipe recipe)
        {
            if (recipe.Content == null || recipe.Title == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                recipe.CreationDate     = DateTime.Now;
                _db.Entry(recipe).State = EntityState.Modified;
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.ClientID   = new SelectList(_db.Clients, "ID", "ClientName", recipe.ClientId);
            ViewBag.CategoryID = new SelectList(_db.Categories, "ID", "Name", recipe.CategoryId);

            return(View(recipe));
        }
Esempio n. 2
0
        public ActionResult Create()
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName");
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content");

            return(View());
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var comment = _db.Comments.Find(id);

            _db.Comments.Remove(comment);
            _db.SaveChanges();

            return(RedirectToAction("Index", "Recipes"));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "ID,ClientID,RecipeID,Content,CreationDate")] Comment comment)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                _db.Comments.Add(comment);
                _db.SaveChanges();

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

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
Esempio n. 5
0
        public ActionResult Delete(int?id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var comment = _db.Comments.Find(id);

            if (comment == null)
            {
                return(HttpNotFound());
            }

            return(View(comment));
        }
Esempio n. 6
0
        public ActionResult Edit([Bind(Include = "ID,RecipeID,ClientId,Content,Score")] Comment comment)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                comment.CreationDate     = DateTime.Now;
                _db.Entry(comment).State = EntityState.Modified;
                _db.SaveChanges();

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

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
        public ActionResult PostComment(int clientId, int recipeId, string content, int score)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var comment = new Comment
            {
                Content      = content,
                Score        = score,
                ClientId     = clientId,
                RecipeId     = recipeId,
                CreationDate = DateTime.Now
            };

            _db.Comments.Add(comment);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var recipe           = _db.Recipes.Find(id);
            var commentsToRemove = _db.Comments.Where(x => x.Recipe.Id == id).ToList();

            foreach (var commentToRemove in commentsToRemove)
            {
                var comment = _db.Comments.Find(commentToRemove.Id);
                _db.Comments.Remove(comment);
            }

            _db.Recipes.Remove(recipe);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        public ActionResult Edit(int?id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var comment = _db.Comments.Find(id);

            if (comment == null)
            {
                return(HttpNotFound());
            }

            ViewBag.ClientID = new SelectList(_db.Clients, "ID", "ClientName", comment.ClientId);
            ViewBag.RecipeID = new SelectList(_db.Recipes, "ID", "Content", comment.RecipeId);

            return(View(comment));
        }
        public ActionResult Edit(int?id)
        {
            if (!AuthorizationMiddleware.Authorized(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var recipe = _db.Recipes.Find(id);

            if (recipe == null)
            {
                return(HttpNotFound());
            }

            ViewBag.ClientID   = new SelectList(_db.Clients, "ID", "ClientName", recipe.ClientId);
            ViewBag.CategoryID = new SelectList(_db.Categories, "ID", "Name", recipe.CategoryId);

            return(View(recipe));
        }