Пример #1
0
        public ActionResult DeleteComment(int id, string slug, int postId)
        {
            if (DeleteCommentCode.Equals(slug, StringComparison.CurrentCultureIgnoreCase))
            {
                var post = _db.Posts.Find(postId);
                if (post == null)
                {
                    return(RedirectToAction("AllPosts"));
                }

                _db.Entry(post).Collection("Comments").Load();
                if (post.Comments == null)
                {
                    return(RedirectToAction("AllPosts"));
                }

                var comment = post.Comments.FirstOrDefault(f => f.Id == id);
                if (comment != null)
                {
                    post.Comments.Remove(comment);
                    _db.SaveChanges();
                    return(RedirectToAction("Post", new { id = postId }));
                }
            }

            return(RedirectToAction("AllPosts"));
        }
Пример #2
0
        public virtual void SaveArticleComments(int articleId, int userId, string comments)
        {
            if (articleId <= 0)
            {
                throw new ArgumentException(nameof(articleId));
            }

            if (userId <= 0)
            {
                throw new ArgumentException(nameof(userId));
            }

            if (string.IsNullOrWhiteSpace(comments))
            {
                throw new ArgumentException(nameof(comments));
            }

            // validate article
            var article = GetById <Article>(articleId, false, true);

            // validate user
            var user = GetById <User>(userId, false, true);

            var articleFeedback = (GetArticleFeeback(articleId, userId)).FirstOrDefault();

            articleFeedback = SetArticleCommentsFields(comments, article, user, articleFeedback);

            blogDbContext.SaveChanges();
        }
Пример #3
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }