public CommentDisplayModel(Blog.Entities.Comment com)
 {
     Id         = com.Id;
     Content    = com.Content;
     CreateTime = com.CreateTime.ToLongDateString();
     Author     = com.Author ?? "Anomynous";
     Email      = com.Email;
     ParentId   = com.ParentId;
     Children   = new List <CommentDisplayModel>();
 }
        public void AddNewComment(string content, int authorId, int articleId)
        {
            using (ObjectContext context = new ObjectContext(_connectionString))
            {
                var comments = context.CreateObjectSet<Comment>();
                int maxId = comments.Any() ? comments.Max(x => x.Id) : 1;

                Comment comment = new Comment()
                {
                    Id = +maxId,
                    Content = content,
                    ArticleId = articleId,
                    AuthorId = authorId,
                    CommDate = DateTime.Now
                };
                comments.AddObject(comment);
                context.SaveChanges();
            }
        }
Beispiel #3
0
 public ActionResult CommentListPartial(Comment[] commetaries)
 {
     CommentViewModel[] commViewList = commetaries.Select(x => ToCommentViewModel(x)).ToArray();
     ViewBag.Commentaries = commViewList;
     return View();
 }
Beispiel #4
0
 private CommentViewModel ToCommentViewModel(Comment comment)
 {
     return new CommentViewModel()
     {
         UserName = _userRepository.GetUser(comment.AuthorId).Username,
         Content = comment.Content,
         Date = comment.CommDate
     };
 }