public HttpResponseMessage GetPosts(HttpRequestMessage request)
        {
            string baseUrl = request.BaseUrl("posts");

            List<Post> posts = _postManager.GetAllPosts();
            if (posts == null || posts.Count == 0)
            {
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.NotFound
                };
            }
            else
            {
                if (request.AcceptsHtml())
                {
                    return new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK,
                        Content = new ObjectContent(typeof(List<Post>), posts, new List<MediaTypeFormatter>() { new PostListHtmlMediaTypeFormatter() })
                    };
                }
                else
                {
                    var postsFeed = new SyndicationFeed()
                    {
                        Id = baseUrl,
                        Title = new TextSyndicationContent("List of posts"),
                        LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                    };
                    postsFeed.Links.Add(new SyndicationLink() 
                    {
                        Uri = request.RequestUri,
                        RelationshipType = "self"
                    });
                    postsFeed.Items = posts.Select(p => new SyndicationItem()
                    {
                        Id = p.Id,
                        Title = new TextSyndicationContent(p.Title),
                        LastUpdatedTime = p.LastUpdatedTime,
                        Content =  new TextSyndicationContent(p.Content)
                    });

                    if (request.AcceptsAtom() || request.AcceptsAll())
                    {
                        return new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.OK,
                            Content = new ObjectContent(typeof(Atom10FeedFormatter), postsFeed.GetAtom10Formatter())
                        };
                    }

                    return new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.InternalServerError
                    };
                }
            }
        }
        public HttpResponseMessage GetServiceDoc(HttpRequestMessage request)
        {
            string baseUrl = request.BaseUrl("servicedoc");

            ServiceDocument doc = new ServiceDocument();
            var postCollection = new ResourceCollectionInfo()
            {
                Title = new TextSyndicationContent("Posts"),
                Link = new Uri(string.Format("{0}/posts", baseUrl))
            };
            postCollection.Accepts.Add("application/atom+xml;type=entry");

            var wspace = new Workspace() { Title = new TextSyndicationContent("The Blog") };
            wspace.Collections.Add(postCollection);

            doc.Workspaces.Add(wspace);

            return new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new ObjectContent(typeof(AtomPub10ServiceDocumentFormatter), doc.GetFormatter())
            };
        }
        public HttpResponseMessage CreatePost(HttpRequestMessage request)
        {
            var reader = XmlReader.Create(request.Content.ReadAsStreamAsync().Result);
            var item = SyndicationItem.Load(reader);

            var post = new Post()
            {
                Title = item.Title.Text,
                Content = item.Content is TextSyndicationContent? ((TextSyndicationContent)item.Content).Text : string.Empty,
                LastUpdatedTime = new DateTimeOffset(DateTime.Now)
            };

            try
            {
                _postManager.Create(post);
                HttpResponseMessage response = new HttpResponseMessage() { StatusCode = HttpStatusCode.Created };
                response.Headers.Location = new Uri(string.Format("{0}/{1}", request.BaseUrl("posts"), post.Id));
                return response;
            }
            catch
            {
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
            }
        }