public async Task <IActionResult> AddEditBlogPost(BlogGem blog)
        {
            var svc = new BlogService();

            if (string.IsNullOrEmpty(blog.Id))
            {
                svc.AddNewBlogPost(blog, _context, await _userManager.GetUserAsync(User));
            }
            else
            {
                svc.EditBlogPost(blog, _context);
            }
            return(RedirectToAction("BlogGemManager"));
        }
Exemplo n.º 2
0
        public void EditBlogPost(BlogGem blog, ChilledDbContext context)
        {
            var oldData = context.BlogPosts.FirstOrDefault(b => b.Id == int.Parse(blog.Id));

            if (oldData != null)
            {
                var rss = context.RSSHeaders.FirstOrDefault(r => r.RSSNumber == blog.FeedId);
                oldData.Hashtags        = GetHashTags(blog.Hashtags);
                oldData.MarkdownContent = blog.MarkdownContent;
                oldData.Published       = blog.Published;
                oldData.RSSHeaderId     = rss.Id;
                oldData.SubTitle        = blog.Subtitle;
                oldData.Title           = blog.Title;
                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void AddNewBlogPost(BlogGem blog, ChilledDbContext context, ChilledUser user)
        {
            var rss = context.RSSHeaders.FirstOrDefault(r => r.RSSNumber == blog.FeedId);

            context.BlogPosts.Add(new BlogPost()
            {
                Hashtags        = GetHashTags(blog.Hashtags),
                MarkdownContent = blog.MarkdownContent,
                Published       = blog.Published,
                RSSHeaderId     = rss.Id,
                SubTitle        = blog.Subtitle,
                Title           = blog.Title,
                Author          = user
            });
            context.SaveChanges();
        }