public PartialViewResult AddComment(int postId, string content) { if (SpamDetector.IsContentSpam(content)) { return(null); } Post post = context.Posts.Where(a => a.PostId == postId).First(); ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } CommentPost commentPost = new CommentPost() { Body = content, DateOfInsert = DateTime.Now, PostId = post.PostId, UserId = User.Identity.GetUserId(), User = user }; var sentimentalInt = new SentimentalInterpreter(); var isContentHappy = sentimentalInt.IsHappy(commentPost.Body); if (isContentHappy) { commentPost.IsHappy = true; } context.CommentPosts.Add(commentPost); context.SaveChanges(); post.Comments.Add(commentPost); CurrentPostUserViewModel vm = new CurrentPostUserViewModel { LoggedUser = user, Post = post }; vm.Post.Comments = vm.Post.Comments.OrderBy(a => a.DateOfInsert).ToList(); return(PartialView("_ListOfComments", vm)); }
public PartialViewResult ListOfPostComment(Post element) { ApplicationUser user = null; string id = GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } CurrentPostUserViewModel vm = new CurrentPostUserViewModel { LoggedUser = user, Post = element }; vm.Post.Comments = vm.Post.Comments.OrderBy(a => a.DateOfInsert).ToList(); return(PartialView("_ListOfComments", vm)); }