示例#1
0
        public PostModel(Post post, string categoriesScheme) {

            Id = post.Id;
            Title = post.Title;
            Slug = post.Slug;
            Summary = post.Summary;
            ContentType = post.ContentType;
            Content = post.Content;
            Tags = post.Tags;
            PublishDate = post.PublishDate;
            LastUpdated = post.LastUpdated;
            CategoriesScheme = categoriesScheme;
        }
        // POST api/posts
        public HttpResponseMessage Post(AddPostCommand command) {

            var postContent = Request.Content.ReadAsStringAsync().Result;

            var post = new Post {
                Id = GetNextId(),
                Title = command.Title,
                Slug = command.Slug ?? command.Title.ToSlug(),
                Summary = command.Summary,
                ContentType = command.ContentType,
                Content = command.Content,
                Tags = command.Tags,
                PublishDate = command.PublishDate ?? DateTime.UtcNow
            };

            Posts.Add(post);

            var response = Request.CreateResponse(HttpStatusCode.Created, new PostModel(post, GetCategoryScheme()));
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "posts", id = post.Id }));

            return response;
        }