Esempio n. 1
0
        public ActionResult DeleteComment(int?commentId)
        {
            Comment comment = _commentRepo.FindComment(commentId);

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

            if ((comment.UserId == User.Identity.GetUserId()) || User.IsInRole("Admin"))
            {
                try
                {
                    _commentRepo.DeleteComment(comment);
                    _commentRepo.SaveChanges();
                    TempData["scrollId"] = "commentContent";
                    return(Redirect(Request.UrlReferrer.ToString()));
                }
                catch (Exception e)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
        public ActionResult DeleteComment(int id)
        {
            var comment = _repository.GetCommentById(id);

            _repository.DeleteComment(comment);
            _repository.SaveChanges();
            return(NoContent());
        }
Esempio n. 3
0
        public async Task <ActionResult> DeleteComment(int id)
        {
            var commentModelFromRepo = await _repository.GetCommentByIdAsync(id);

            if (commentModelFromRepo == null)
            {
                return(NotFound());
            }

            _repository.DeleteComment(commentModelFromRepo);
            await _repository.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 4
0
 public void DeleteComment(int id)
 {
     _repo.DeleteComment(id);
 }