예제 #1
0
        /// <summary>
        /// Ajax POST to publish a post.
        /// </summary>
        /// <returns>
        /// Absolute URL to the post.
        /// </returns>
        /// <remarks>
        /// The post could be new or previously published.
        /// </remarks>
        public async Task <JsonResult> OnPostPublishAsync([FromBody] PostVM post)
        {
            var blogPost = new BlogPost
            {
                UserId     = Convert.ToInt32(_userManager.GetUserId(HttpContext.User)),
                CategoryId = post.CategoryId,
                CreatedOn  = GetCreatedOn(post.PostDate),
                TagTitles  = post.Tags,
                Slug       = post.Slug,
                Excerpt    = post.Excerpt,
                Title      = post.Title,
                Body       = post.Body,
                Status     = EPostStatus.Published,
            };

            if (post.Id <= 0)
            {
                blogPost = await _blogSvc.CreateAsync(blogPost);
            }
            else
            {
                blogPost.Id = post.Id;
                blogPost    = await _blogSvc.UpdateAsync(blogPost);
            }

            return(new JsonResult(GetPostAbsoluteUrl(blogPost)));
        }
예제 #2
0
        // -------------------------------------------------------------------- Posts

        public async Task <string> NewPostAsync(string blogid, string userName, string password, MetaPost post, bool publish)
        {
            var user = await ValidUserAsync(userName, password);

            try
            {
                var blogPost = new BlogPost
                {
                    UserId        = user.Id,
                    Title         = post.Title,
                    Slug          = post.Slug,
                    Body          = post.Description,
                    Excerpt       = post.Excerpt,
                    CreatedOn     = post.PostDate,
                    CategoryTitle = (post.Categories == null || post.Categories.Count <= 0) ? null : post.Categories[0],
                    TagTitles     = post.Tags,
                    Status        = publish ? EPostStatus.Published : EPostStatus.Draft,
                    CommentStatus = await GetPostCommentStatusAsync(post.CommentPolicy),
                };

                blogPost = await _blogSvc.CreateAsync(blogPost);

                return(blogPost.Id.ToString());
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException(EMetaWeblogCode.NewPost, ex.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates the welcome blog post, settings, tags and the default category.
        /// </summary>
        /// <returns></returns>
        private async Task SetupBlogAsync()
        {
            const string DEFAULT_CATEGORY     = "Uncategorized";
            const string WELCOME_POST_TITLE   = "Welcome to Fanray Blog";
            const string WELCOME_POST_BODY    = @"<p>A few tips to get you started.&nbsp;</p><ul><li>Go to <a href=""/admin/settings"">Settings</a> and enter your Disqus and Google Analytics information.</li><li>Go to <a href=""/admin/widgets"">Widgets</a> and update Social Icons to your own media links.</li><li>Spend a few minutes to get familiar with the <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Composer"">Composer</a>, knowing how to effectively input different contents in the <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Composer#editor"">Editor</a> will help you become more productive blogging.</li><li>Check out <code>appsettings.json</code> to update database, storage, preferred domain, logging and diagnostic settings for local and production.</li><li>When you are ready to run this app on Azure, refer to <a href=""https://github.com/FanrayMedia/Fanray/wiki/Deploying-to-Azure"">Deploying to Azure</a>.</li><li>Feel like contributing? See the <a href=""https://github.com/FanrayMedia/Fanray/blob/master/CONTRIBUTING.md"">Contributing Guide</a>.</li></ul><p>Thank you and happy coding :)</p>";
            const string WELCOME_POST_EXCERPT = "Welcome to Fanray Blog. Here are a few tips to get you started using the blog.";

            // create blog setting
            var blogSettings = await _settingSvc.GetSettingsAsync <BlogSettings>(); // could be initial or an existing blogsettings

            await _settingSvc.UpsertSettingsAsync(blogSettings);

            // get default cat
            Category defaultCat = null;

            try
            {
                defaultCat = await _catSvc.GetAsync(blogSettings.DefaultCategoryId);
            }
            catch (FanException)
            {
                defaultCat = await _catSvc.CreateAsync(DEFAULT_CATEGORY);
            }

            // TODO should I make create welcome post a option on setup
            // create welcome post and default category
            await _blogSvc.CreateAsync(new BlogPost
            {
                CategoryTitle = defaultCat.Title,
                TagTitles     = new List <string> {
                    "announcement", "blogging"
                },
                Title         = WELCOME_POST_TITLE,
                Body          = WELCOME_POST_BODY,
                Excerpt       = WELCOME_POST_EXCERPT,
                UserId        = 1,
                Status        = EPostStatus.Published,
                CommentStatus = ECommentStatus.AllowComments,
                CreatedOn     = DateTimeOffset.Now,
            });

            _logger.LogInformation("Welcome post and default category created.");
            _logger.LogInformation("Blog Setup completes.");
        }
예제 #4
0
        /// <summary>
        /// Creates the welcome blog post, settings, tags and the default category.
        /// </summary>
        /// <returns></returns>
        private async Task SetupBlogAsync()
        {
            const string DEFAULT_CATEGORY   = "Uncategorized";
            const string WELCOME_POST_TITLE = "Welcome to Fanray v2.0";
            const string WELCOME_POST_BODY  = @"<p>Welcome and congrats on getting your blog up and running! &nbsp;Fanray v1.0 was a minimal viable blog, you could only post through a client like the Open Live Writer. Fanray v2 builds on v1 and introduces a brand new Admin Panel, you can now do more! &nbsp;Here are a few tips to get you started and please check out the <a href=""https://github.com/FanrayMedia/Fanray/wiki"">Wiki</a> for more details.</p><h2>Getting Started</h2><p>First I recommend complete the setup by going to the <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Settings"">Settings</a> page and enter your Disqus and Google Analytics information.</p><p>Bloggers probably spend most of their time writing posts. To help you be productive, I highly recommend spending a few minutes to get familiar with the <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Composer"">Composer</a>, particularly the <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Composer#editor"">Editor</a>.</p><p>The <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Media-Gallery"">Media Gallery</a> gives you a grand view of all your blog images. &nbsp;Here you can upload more images or edit image info etc. The uploaded images are resized and stored on either the file system or Azure Blob Storage, you can configure which <a href=""https://github.com/FanrayMedia/Fanray/wiki/Storage"">Storage</a> in the <code>appsettings.json</code>.</p><p>The <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Categories"">Categories </a>and <a href=""https://github.com/FanrayMedia/Fanray/wiki/Admin---Tags"">Tags</a> pages allow you to easily manage your blog's classifications. &nbsp;For categories there is a default category out of box named <i>Uncategorized</i>, go rename it to something you write about.&nbsp;</p><p>When you are ready to run this app on Azure, please refer to <a href=""https://github.com/FanrayMedia/Fanray/wiki/Deploying-to-Azure"">Deploying to Azure</a>.</p><h2>Contribute</h2><p>Fanray is in its early stages and requires support to move ahead. You can contribute in many ways - ideas, bugs, testing and docs etc. please read the <a href=""https://github.com/FanrayMedia/Fanray/blob/master/CONTRIBUTING.md"">Contributing Guide</a>.&nbsp;</p><p>Finally, follow me <a href=""https://twitter.com/FanrayMedia"">@fanraymedia</a> and let me know what you think. Thank you and happy coding :)</p>";

            // create blog setting
            var blogSettings = await _settingSvc.GetSettingsAsync <BlogSettings>(); // could be initial or an existing blogsettings

            await _settingSvc.UpsertSettingsAsync(blogSettings);

            // get default cat
            Category defaultCat = null;

            try
            {
                defaultCat = await _catSvc.GetAsync(blogSettings.DefaultCategoryId);
            }
            catch (FanException)
            {
                defaultCat = await _catSvc.CreateAsync(DEFAULT_CATEGORY);
            }

            // TODO should I make create welcome post a option on setup
            // create welcome post and default category
            await _blogSvc.CreateAsync(new BlogPost
            {
                CategoryTitle = defaultCat.Title,
                TagTitles     = new List <string> {
                    "announcement", "blogging"
                },
                //Tags = await _tagSvc.GetTagsAsync(),
                Title         = WELCOME_POST_TITLE,
                Body          = WELCOME_POST_BODY,
                UserId        = 1,
                Status        = EPostStatus.Published,
                CommentStatus = ECommentStatus.AllowComments,
                CreatedOn     = DateTimeOffset.Now,
            });

            _logger.LogInformation("Welcome post and default category created.");
            _logger.LogInformation("Blog Setup completes.");
        }
예제 #5
0
        /// <summary>
        /// Ajax POST to save a post as draft.
        /// </summary>
        /// <returns>
        /// The updated <see cref="BlogPost"/>.
        /// </returns>
        /// <remarks>
        /// This is called by either auto save or user clicking on Save.
        /// </remarks>
        public async Task <JsonResult> OnPostSaveAsync([FromBody] BlogPostIM postIM)
        {
            var blogPost = new BlogPost
            {
                CategoryId = postIM.CategoryId,
                CreatedOn  = BlogUtil.GetCreatedOn(postIM.PostDate),
                TagTitles  = postIM.Tags,
                Slug       = postIM.Slug,
                Excerpt    = postIM.Excerpt,
                Title      = postIM.Title,
                Body       = postIM.Body,
                Status     = EPostStatus.Draft,
            };

            if (postIM.Id <= 0)
            {
                blogPost = await _blogSvc.CreateAsync(blogPost);
            }
            else
            {
                blogPost.Id = postIM.Id;
                blogPost    = await _blogSvc.UpdateAsync(blogPost);
            }

            var coreSettings = await _settingSvc.GetSettingsAsync <CoreSettings>();

            var postVM = new BlogPostIM
            {
                Id         = blogPost.Id,
                Title      = blogPost.Title,
                Body       = blogPost.Body,
                PostDate   = blogPost.CreatedOn.ToString(DATE_FORMAT),
                Slug       = blogPost.Slug,
                Excerpt    = blogPost.Excerpt,
                CategoryId = blogPost.CategoryId ?? 1,
                Tags       = blogPost.TagTitles,
                Published  = blogPost.Status == EPostStatus.Published,
                IsDraft    = blogPost.Status == EPostStatus.Draft,
                DraftDate  = blogPost.UpdatedOn.HasValue ? blogPost.UpdatedOn.Value.ToDisplayString(coreSettings.TimeZoneId) : "",
            };

            return(new JsonResult(postVM));
        }
예제 #6
0
        /// <summary>
        /// Creates the welcome blog post, settings, tags and the default category.
        /// </summary>
        /// <returns></returns>
        private async Task SetupBlogSettingsAndPostsAsync()
        {
            // -------------------------------------------- blog settings

            var blogSettings = await settingService.GetSettingsAsync <BlogSettings>(); // could be initial or an existing blogsettings

            await settingService.UpsertSettingsAsync(blogSettings);

            _logger.LogInformation("Blog settings created");

            // -------------------------------------------- categories

            const string DEFAULT_CATEGORY = "Software Development";
            const string SECOND_CATEGORY  = "Life Musings";

            // get default cat
            Category defaultCat;

            try
            {
                defaultCat = await _catSvc.GetAsync(blogSettings.DefaultCategoryId);
            }
            catch (FanException)
            {
                defaultCat = await _catSvc.CreateAsync(DEFAULT_CATEGORY);
            }

            Category secondCat;

            try
            {
                secondCat = await _catSvc.GetAsync(blogSettings.DefaultCategoryId + 1);
            }
            catch (FanException)
            {
                secondCat = await _catSvc.CreateAsync(SECOND_CATEGORY);
            }

            _logger.LogInformation("Blog categories created");

            // -------------------------------------------- posts

            // Hello World (life musing)
            await _blogSvc.CreateAsync(new BlogPost
            {
                UserId        = 1,
                Status        = EPostStatus.Published,
                CommentStatus = ECommentStatus.AllowComments,
                CreatedOn     = DateTimeOffset.Now,
                Title         = "Hello World",
                Body          = await GetSetupFileContent("post-hello.html"),
                Excerpt       = "A blogging joke to break ice :)",
                CategoryTitle = secondCat.Title,
                TagTitles     = new List <string> {
                    "blogging", "jokes"
                },
            });

            // Welcome to Fanray (software dev)
            await _blogSvc.CreateAsync(new BlogPost
            {
                UserId        = 1,
                Status        = EPostStatus.Published,
                CommentStatus = ECommentStatus.AllowComments,
                CreatedOn     = DateTimeOffset.Now,
                Title         = "Welcome to Fanray",
                Body          = await GetSetupFileContent("post-welcome.html"),
                Excerpt       = "Some tips to get you started blogging!",
                CategoryTitle = defaultCat.Title,
                TagTitles     = new List <string> {
                    "blogging", "tips"
                },
            });

            _logger.LogInformation("Default posts created");
        }