public async Task <bool> Retract(Guid PostId) { var articleService = new ArticleService(ctx, opts, logger); var post = new ClientArticle(await articleService.Get(PostId)); // post.Published = null; var updated = post.WithPublished(null); await articleService.Update(updated); return(true); }
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; } }