public IHttpActionResult PutComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != comment.Id)
            {
                return BadRequest();
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public void Add_ValidComment_ShouldCommentIdBiggerThanNull()
 {
     var comment = new Comment
     {
         PictureUrl = "http://www.test.com/",
         Text = "Testss",
         Date = DateTime.Now
     };
     this.dbContext.Set<Comment>().Add(comment);
     this.dbContext.SaveChanges();
     Assert.IsTrue(comment.Id > 0);
 }
        public void Add_WhenCommentIsValid_ShouldReturnNotZeroId()
        {
            int commentId;
            using (TransactionScope scope = new TransactionScope())
            {
                var comment = new Comment
                {
                    PictureUrl = "http://www.test.com/",
                    Text = "Testss",
                    Date = DateTime.Now
                };
                this.dbContext.Set<Comment>().Add(comment);
                this.dbContext.SaveChanges();
                scope.Complete();
                commentId = comment.Id;
            }

            Assert.IsTrue(commentId != 0);

            var commentEntity = this.dbContext.Set<Comment>().Find(commentId);
            Assert.IsNotNull(commentEntity);
        }
        public IHttpActionResult PostComment(CommentModel comment)
        {
            if (comment == null || !ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newComment = new Comment
            {
                Date = DateTime.Now,
                Author = comment.Author,
                ArticleId = comment.ArticleId,
                Text = comment.Text
            };

            db.Comments.Add(newComment);
            db.SaveChanges();

            return Ok(newComment);
        }