Пример #1
0
        public IActionResult GetCommentArticle(int commentID)
        {
            PodcastComment comment = _dbContext.PodcastComments.Where(p => (p.PodcastCommentId == commentID)).FirstOrDefault();

            if (comment != null)
            {
                return(Json(new { result = comment.Article }));
            }
            return(Json(new { error = "No article found" }));
        }
Пример #2
0
 public IActionResult DeleteComment(int commentID)
 {
     if (ModelState.IsValid)
     {
         PodcastComment comment = _dbContext.PodcastComments.Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
         if (comment != null)
         {
             if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
             {
                 _dbContext.PodcastComments.Remove(comment);
                 _dbContext.SaveChanges();
                 return(Json(new { result = true }));
             }
             return(Json(new { error = "You don't have permission to delete this comment" }));
         }
         return(Json(new { error = "No comment found" }));
     }
     return(Json(new { error = "Invalid Parameters" }));
 }
Пример #3
0
 public IActionResult EditComment(int commentID, string article)
 {
     if (ModelState.IsValid)
     {
         PodcastComment comment = _dbContext.PodcastComments.Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
         if (comment != null)
         {
             if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
             {
                 comment.Article    = article;
                 comment.DateEdited = DateTime.Now;
                 _dbContext.Entry(comment).State = EntityState.Modified;
                 _dbContext.SaveChanges();
                 return(Json(new { result = true }));
             }
             return(Json(new { error = "You don't have permission to edit this comment" }));
         }
         return(Json(new { error = "No comment found" }));
     }
     return(Json(new { error = "Invalid Parameters" }));
 }
Пример #4
0
        public IActionResult CreateComment(int podcastId, string article)
        {
            if (ModelState.IsValid)
            {
                if (_dbContext.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() != null)
                {
                    PodcastComment comment = new PodcastComment();
                    comment.PodcastId  = podcastId;
                    comment.UserId     = UserHelper.GetUser(_dbContext, User.Identity.Name).UserId;
                    comment.Article    = article;
                    comment.DatePosted = DateTime.Now;
                    comment.DateEdited = DateTime.Now;

                    _dbContext.PodcastComments.Add(comment);
                    _dbContext.SaveChanges();
                    return(Json(new { result = true }));
                }
                return(Json(new { error = "That podcast does not exist" }));
            }
            return(Json(new { error = "Invalid Parameters" }));
        }