private static Topic GenerateLinksForTopic(Topic topic, HttpRequestMessage request)
        {
            var routeData = request.GetRouteData();
            var controller = routeData.Values["controller"];
            var urlHelper = request.GetUrlHelper();

            topic.SelfLink = new Uri(urlHelper.Route("DefaultApi", new { controller = controller, id = topic.Id }), UriKind.Relative);

            if (topic.Comments != null && topic.Comments.Count > 0)
            {
                topic.Comments = new List<Comment>(topic.Comments.Select((cmt) =>
                {
                    cmt.SelfLink = new Uri(urlHelper.Route("DefaultApi", new { controller = controller, id = cmt.Id }), UriKind.Relative);
                    cmt.TopicLink = new Uri(urlHelper.Route("DefaultApi", new { controller = "topics", id = cmt.TopicId }), UriKind.Relative);

                    return cmt;
                }));
            }

            if (topic.Tags != null && topic.Tags.Count > 0)
            {
                topic.Tags = new List<Tag>(topic.Tags.Select((tag) =>
                {
                    tag.SelfLink = new Uri(urlHelper.Route("DefaultApi", new { controller = controller, tags = tag.Name }), UriKind.Relative);
                    return tag;
                }));
            }

            return topic;
        }
        public HttpResponseMessage PostTopic(Topic topic)
        {
            if (ModelState.IsValid)
            {
                db.Topics.Add(topic);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, topic);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = topic.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }