Exemple #1
0
        public async Task <PostItem> SaveItem(PostItem item)
        {
            BlogPost post;
            var      field = _db.CustomFields.Where(f => f.AuthorId == 0 && f.Name == Constants.BlogCover).FirstOrDefault();
            var      cover = field == null ? "" : field.Content;

            if (item.Id == 0)
            {
                post = new BlogPost
                {
                    Title              = item.Title,
                    Slug               = item.Slugtitle,
                    Content            = item.Content,
                    Description        = item.Description ?? item.Title,
                    Categories         = item.Categories,
                    Cover              = item.Cover ?? cover,
                    AuthorId           = item.Author.Id,
                    IsFeatured         = item.Featured,
                    Published          = item.Published,
                    Lang               = item.Lang,
                    TopRightWidgetHtml = item.Toprightwidget,
                };

                _db.BlogPosts.Add(post);
                await _db.SaveChangesAsync();

                post = _db.BlogPosts.Single(p => p.Slug == post.Slug);
                item = PostToItem(post);
            }
            else
            {
                post = _db.BlogPosts.Single(p => p.Id == item.Id);

                post.Slug               = item.Slugtitle;
                post.Title              = item.Title;
                post.Content            = item.Content;
                post.Description        = item.Description ?? item.Title;
                post.Categories         = item.Categories;
                post.AuthorId           = item.Author.Id;
                post.Published          = item.Published;
                post.IsFeatured         = item.Featured;
                post.Lang               = item.Lang;
                post.TopRightWidgetHtml = item.Toprightwidget;

                await _db.SaveChangesAsync();
            }
            return(await Task.FromResult(item));
        }
Exemple #2
0
        public async Task <PostItem> SaveItem(PostItem item)
        {
            BlogPost post;

            if (item.Id == 0)
            {
                post = new BlogPost
                {
                    Title       = item.Title,
                    Slug        = item.Slug,
                    Content     = item.Content,
                    Description = item.Description ?? item.Title,
                    Categories  = item.Categories,
                    Cover       = item.Cover ?? AppSettings.Cover,
                    AuthorId    = item.Author.Id,
                    IsFeatured  = item.Featured,
                    Published   = item.Published
                };
                _db.BlogPosts.Add(post);
                await _db.SaveChangesAsync();

                post = _db.BlogPosts.Single(p => p.Slug == post.Slug);
                item = PostToItem(post);
            }
            else
            {
                post = _db.BlogPosts.Single(p => p.Id == item.Id);

                post.Title       = item.Title;
                post.Slug        = item.Slug;
                post.Content     = item.Content;
                post.Description = item.Description ?? item.Title;
                post.Categories  = item.Categories;
                post.AuthorId    = item.Author.Id;
                post.Published   = item.Published;
                post.IsFeatured  = item.Featured;
                await _db.SaveChangesAsync();

                item.Slug = post.Slug;
            }
            return(await Task.FromResult(item));
        }