// POST api/comments/5
        public int Post(int postId, [FromBody] Comment comment)
        {
            comment.DateTime = clock.GetTime();
            comment.PostID   = postId;
            context.Add(comment);
            context.SaveChanges();

            return(comment.ID);
        }
예제 #2
0
        // PUT api/posts/5
        public void Put(int id, [FromBody] Post post)
        {
            var existing = this.Get(id);

            if (existing == null)
            {
                throw new KeyNotFoundException();
            }

            existing.Content = post.Content;
            existing.Title   = post.Title;

            context.Update(existing);
            context.SaveChanges();
        }