예제 #1
0
        /// <summary>
        /// Gets the post.
        /// </summary>
        /// <param name="postid">The postid.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>System.Object.</returns>
        /// <exception cref="BlogSystemException">error getting post</exception>
        object IMetaWeblog.GetPost(string postid, string username, string password)
        {
            ValidateUser(username, password);
            try
            {
                TraceUtility.LogInformation("Get post invoked for {0}", postid);
                var blogPost = this.metaweblogTable.GetById(ApplicationConstants.BlogKey, postid);
                var blog     = TableBlogEntity.GetBlogPost(blogPost);
                if (null == blog)
                {
                    return(null);
                }

                return
                    (new
                {
                    description = blog.Body,
                    title = blog.Title,
                    dateCreated = blog.PostedDate,
                    wp_slug = string.Empty,
                    categories =
                        string.IsNullOrWhiteSpace(blogPost.CategoriesCsv)
                                    ? new[] { string.Empty }
                                    : blogPost.CategoriesCsv.ToCollection().ToArray(),
                    postid = blog.BlogId
                });
            }
            catch (Exception exception)
            {
                TraceUtility.LogError(exception);
                throw new BlogSystemException("error getting post");
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the blog post.
        /// </summary>
        /// <param name="postId">The post identifier.</param>
        /// <returns>BlogPost.</returns>
        public BlogPost GetBlogPost(string postId)
        {
            var activeTable = this.blogContext.CustomOperation();
            var query       = (from record in activeTable.CreateQuery <DynamicTableEntity>()
                               where
                               record.PartitionKey == ApplicationConstants.BlogKey &&
                               record.Properties["IsDeleted"].BooleanValue == false &&
                               record.Properties["FormattedUri"].StringValue.Equals(
                                   postId,
                                   StringComparison.OrdinalIgnoreCase)
                               select record).Take(this.pageSize);
            var result = query.AsTableQuery().ExecuteSegmented(null, this.blogContext.TableRequestOptions);

            if (!result.Any())
            {
                return(null);
            }

            return
                (TableBlogEntity.GetBlogPost(
                     result.Select(element => element.ConvertDynamicEntityToEntity <TableBlogEntity>()).FirstOrDefault()));
        }