// comments
        public void CreateComment(string Id, Comment comment)
        {
            try
            {
                ConnectToDatabase();

                Post post = collection.FindOne(new { _id = Id });

                comment._CommentId = GetNewCommentId(post.Comments);

                if (comment._CommentId == 1)
                    post.Comments = new List<Comment>();

                post.Comments.Add(comment);
                collection.Update(new { _id = post.Id }, x => x.SetValue(p => p.Comments, post.Comments));
                collection.Update(new { _id = post.Id }, x => x.SetValue(p => p.CommentCount, post.Comments.Count));

            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
            finally
            {
                DisconnectFromDatabase();
            }
        }
Exemplo n.º 2
0
        public void Is_Comment_Adds_To_Photo()
        {
            // Arrage
            Photo photo = new Photo();
            Comment comment = new Comment
            {
                Author = "Mike",
                Text = "Hello world"
            };

            // Act
            photo.AddComment(comment);

            // Assert
            Assert.IsNotNull(photo.Comments[0]);
            Assert.AreEqual(photo.Comments[0].Author, comment.Author);
            Assert.AreEqual(photo.Comments[0].Text, comment.Text);
        }
 public void EditComment(string PostId, Comment comment)
 {
     //TODO: mongodb-csharp driver edit comment
 }
 // comments
 public void CreateComment(string PostId, Comment comment)
 {
     //TODO: mongodb-csharp driver add comment
 }
 public void EditComment(string Id, Comment comment)
 {
     //TODO: edit comment
 }
        public ActionResult PostView(Comment comment)
        {
            //if (!captchaValid)
            //    ModelState.AddModelError("Captcha", "reCAPTCHA response was incorrect.");

            Post post = postRepository.GetPostById(Request.Params["PostId"]);

            if (ModelState.IsValid)
            {
                comment.TimePosted = DateTime.Now;

                postRepository.CreateComment(post.Id, comment);

                return RedirectToAction("PostView", new { Id = Request.Params["PostId"] });
            }
            else
            {
                ViewData["Post"] = post;

                ViewData["Id"] = post.Id;

                return View(comment);
            }
        }
Exemplo n.º 7
0
 public void RemoveComment(Comment comment)
 {
     _comments.Remove(comment);
 }
Exemplo n.º 8
0
 public void AddComment(Comment comment)
 {
     _comments.Add(comment);
 }