public ActionResult Comment(int id) { string userName = User.Identity.Name; AccountModel user = AccountRepository.GetAccount(userName); PostModel post = PostRepository.GetPost(id); CommentModel comment = new CommentModel(); comment.UserId = user.UserId; comment.PostId = post.PostId; comment.OriginalPost = post.PostContent; return View(comment); }
public bool InsertComment(CommentModel commentModel) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightMsg_Comment comment = new WeightMsg_Comment(); comment.Comment_DateTime = DateTime.Now; comment.Comment_HTML = commentModel.CommentContent; comment.Post_ID = commentModel.PostId; comment.UserID = commentModel.UserId; entity.AddToWeightMsg_Comment(comment); int rows = entity.SaveChanges(); if (rows > 0) return true; else return false; } }
public List<CommentModel> GetComments(int postId) { List<CommentModel> commentList = new List<CommentModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var comments = entity.WeightMsg_Comment.Include("WeightMsg_Post").Include("WeightUser").Where(e => e.Post_ID == postId).OrderBy(f => f.Comment_DateTime); foreach (WeightMsg_Comment comment in comments) { CommentModel commentModel = new CommentModel(); commentModel.CommentId = comment.Comment_ID; commentModel.PostId = comment.Post_ID; commentModel.CommentDate = comment.Comment_DateTime; commentModel.DisplayName = comment.WeightUser.DisplayName; commentModel.CommentContent = comment.Comment_HTML; commentModel.UserId = comment.UserID; commentModel.UserName = comment.WeightUser.UserName; commentModel.OriginalPost = comment.WeightMsg_Post.Post_Content; commentList.Add(commentModel); } } return commentList; }
public ActionResult Comment(CommentModel commentModel) { PostRepository.InsertComment(commentModel); return RedirectToAction("Index"); }