Ejemplo n.º 1
0
        public List<Comment> GetAllComments()
        {
            var list = new List<Comment>();
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand("select c.CommentID, c.BlogPostID, c.StatusID, s.StatusType, c.UserID,c.Nickname,c.DateOfComment, c.CommentContent from Comment c inner join Status s on c.StatusID = s.StatusID", cn);
                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var comment = new Comment()
                        {
                            Status = new Status(),
                            User = new User()
                        };
                        comment.CommentID = dr.GetInt32(0);
                        comment.BlogPostID = dr.GetInt32(1);
                        comment.Status.StatusID = dr.GetInt32(2);
                        comment.Status.StatusType = dr.GetString(3);
                        comment.User.UserId = dr["UserID"] is DBNull ? String.Empty : dr.GetString(7);
                        comment.Nickname = dr.GetString(5);
                        comment.DateOfComment = dr.GetDateTime(6);
                        comment.CommentContent = dr.GetString(7);

                        list.Add(comment);
                    }
                }
            }
            return list;
        }
Ejemplo n.º 2
0
 public void CreateComment(Comment comment)
 {
     using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
     {
         cn.Query(
             "INSERT INTO Comment(BlogPostID, CommentContent, StatusID, Nickname, DateOfComment) VALUES (@PostID, @Content, @Status, @Name, @Date)",
             new {PostID = comment.BlogPostID, Content = comment.CommentContent, Status = comment.Status.StatusID, Name = comment.Nickname, Date = comment.DateOfComment});
     }
 }
Ejemplo n.º 3
0
        public void CreateCommentTest()
        {
            var repo = new CommentRepo();
            var comment = new Comment()
            {
                BlogPostID = 1,
                CommentContent = "This is a comment test",
                Status = new Status() { StatusID = 1 },
                User = new User(),
                Nickname = "Jake"

            };
            repo.CreateComment(comment);

            var list = repo.GetAllCommentsByPostID(1);
            Assert.AreEqual(1, list.Count);
        }
Ejemplo n.º 4
0
 public void CreateComment(Comment comment)
 {
     if(comment.DateOfComment >= DateTime.Today)
         _repo.CreateComment(comment);
 }
Ejemplo n.º 5
0
 public void CreateComment(Comment comment)
 {
 }