예제 #1
0
        public async Task <ICompletePost> Update(ICompletePost post)
        {
            try
            {
                logger.LogInformation($"Update blog article {post.Id}");

                (var article, var tags, var categories) = new CompleteBlogEntry(post);
                // Services
                var articleService  = new ArticleService(ctx, opts, logger);
                var tagService      = new TagService(ctx, opts, logger, opts[StorageList.TagTable], opts[StorageList.TagQueue]);
                var categoryService = new CategoryService(ctx, opts, logger, opts[StorageList.CategoryTable], opts[StorageList.CategoryQueue]);

                // Set up the main 'document'
                var updatedArticle = await articleService.Update(article);

                // We changed the primaryKey (Guid, Url) so the url.
                // so We have to delete the existing tags, and categories
                if (post.Id != updatedArticle.Id)
                {
                    // Delete the ones with the original keys
                    await tagService.Delete(tags);

                    await categoryService.Delete(categories);

                    // Create a complete blogpost correct keys
                    var recreatedEntry = new CompleteBlogEntry(updatedArticle, tags, categories);
                    (_, var updatedTags, var updatedCategories) = recreatedEntry;
                    // create them as if it were a new post....Which it is
                    await tagService.Create(tags);

                    await categoryService.Create(categories);

                    return(recreatedEntry);
                }
                else
                {
                    // normal updates of thins
                    var updatedTags = await tagService.Update(tags);

                    var updateCategories = await categoryService.Update(categories);

                    return(new CompleteBlogEntry(
                               updatedArticle,
                               updatedTags,
                               updateCategories));
                }
            }
            catch (StorageException ex)
            {
                logger.LogDebug(ex.Message, ex.StackTrace, "BlogArticleService.Update");
                throw;
            }
        }
예제 #2
0
 public BaseArticle(ICompletePost totalArticle)
 {
     this.Id        = totalArticle.Id;
     this.Url       = totalArticle.Url;
     this.Synopsis  = totalArticle.Synopsis;
     this.Published = totalArticle.Published;
     this.Created   = totalArticle.Created;
     this.Author    = totalArticle.Author;
     this.Article   = totalArticle.Article;
     this.Title     = totalArticle.Title;
     this.Updated   = totalArticle.Updated;
     this.Available = totalArticle.Available;
 }
예제 #3
0
 public ClientArticle(ICompletePost post)
 {
     Url       = post.Url;
     Title     = post.Title;
     Synopsis  = post.Synopsis;
     Author    = post.Author;
     Created   = post.Created;
     Published = post.Published;
     Article   = post.Article;
     Updated   = post.Updated;
     Available = post.Available;
     Id        = post.Id;
 }
예제 #4
0
 public ClientArticle(ICompletePost article, Guid id)
 {
     Url       = article.Url;
     Title     = article.Title;
     Synopsis  = article.Synopsis;
     Author    = article.Author;
     Created   = article.Created;
     Published = article.Published;
     Article   = article.Article;
     Updated   = article.Updated;
     Available = article.Available;
     Id        = id;
 }
예제 #5
0
        public async Task <ICompletePost> Add(ICompletePost post)
        {
            // In the we deconstruct the original message, to easier to manage parts
            logger.LogInformation($"Creating new blog article {post.Title}");
            (var article, var tags, var categories) = new CompleteBlogEntry(post);
            var articleService  = new ArticleService(ctx, opts, logger);
            var tagService      = new TagService(ctx, opts, logger, opts[StorageList.TagTable], opts[StorageList.TagQueue]);
            var categoryService = new CategoryService(ctx, opts, logger, opts[StorageList.CategoryTable], opts[StorageList.CategoryQueue]);

            // INsert and create a new Blog Article
            var entity = await articleService.Create(article);

            // Ditto the tsg, and categories
            var createdTags = await tagService.Create(tags.Tags.ToList(), entity.Id);

            var createdCats = await categoryService.Create(categories.Tags.ToList(), entity.Id);

            var addedEntry = new CompleteBlogEntry(
                await articleService.Get(entity.Id),
                createdTags,
                createdCats);

            return(addedEntry);
        }
예제 #6
0
 public ArticleCategories(ICompletePost article)
 {
     Id   = article.Id;
     Tags = new List <string>(article.Tags);
 }
예제 #7
0
 public ArticleTags(ICompletePost article)
 {
     Id   = article.Id;
     Tags = article.Tags;
 }
예제 #8
0
 private static async Task <ICompletePost> UpdatePost(BlogArticleService bas, ICompletePost blogPost)
 {
     return(await bas.Update(blogPost));
 }
예제 #9
0
 public CompleteBlogEntry(ICompletePost article) : this(article.Url, article.Title, article.Synopsis, article.Article, article.Author, article.Tags, article.Categories, article.Created, article.Published, article.Updated, article.Available)
 {
     Id = article.Id;
 }