Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PostModel"/> class.
        /// </summary>
        /// <param name="post">The post.</param>
        public PostModel(SuluczPost post)
        {
            this.MetaData = new PostMetaData(post.MetaData);

            this.Content = ContentConverter.ConvertContent(post.Contents);

            this.RawContent = post.Contents.Select(s => new PostContent(s)).ToArray();

            this.Tags = post.Tags.ToArray();
        }
        /// <summary>
        /// Creates a post, or updates an old one.
        /// </summary>
        /// <param name="post">The post.</param>
        /// <returns>An async task.</returns>
        public Task SetPost(SuluczPost post)
        {
            return(this.sqlClient.ExecuteAsync(
                       "su.setpost",
                       parameters =>
            {
                parameters.AddWithValue("id", post.MetaData.Id);
                parameters.AddWithValue("slug", post.MetaData.Slug);
                parameters.AddWithValue("title", post.MetaData.Title);
                parameters.AddWithValue("description", post.MetaData.Description);
                parameters.AddWithValue("whenpublished", post.MetaData.WhenPublished);
                parameters.AddWithValue("revision", post.MetaData.Revision);
                parameters.Add(ModelFactory.GenerateContentList(post.Contents));

                // Add the tags if there are any.
                if (post.Tags.Any())
                {
                    parameters.Add(ModelFactory.GenerateTagList(post.Tags));
                }
            }));
        }