public async Task <bool> Delete(Guid commentId, Guid userId)
        {
            var comment = await _repository.GetRecipeComment(commentId);

            if (comment != null && comment.IdUser == userId)
            {
                await _repository.DeleteComment(commentId);

                await _repository.SaveChanges();

                return(true);
            }

            return(false);
        }
Exemple #2
0
        public ActionResult DeleteComment(int id)
        {
            try
            {
                bool isModerator = User.IsInRole("Moderator");
                if (isModerator == false)
                {
                    return(HttpNotFound());
                }
                var commentToDelete = db.FindComment(id);
                if (commentToDelete == null)
                {
                    throw new Exception();
                }

                db.DeleteComment(commentToDelete);
                db.Save();
                return(RedirectToAction("Details", "Recipe", new { id = commentToDelete.RecipeId }));
            }
            catch
            {
                return(HttpNotFound());
            }
        }