public async Task RemoveArticleMetaTags(Guid articleId, params MetaTagRequest[] metaTagRequests) { if (metaTagRequests == null || !metaTagRequests.Any()) { throw new ArgumentNullException(nameof(metaTagRequests)); } var existingArticle = GetExistingArticle(articleId); if (existingArticle == null) { return; } var tagsToDelete = existingArticle.MetaTags .Where(mt => metaTagRequests.Any(mtr => string.Equals(mtr.Name, mt.Name))) .ToArray(); foreach (var tagToDelete in tagsToDelete) { _context.Delete(tagToDelete); } await _context.SaveChanges(); }
private async Task <Article> AttemptCreateNewBlogArticle(ArticleRequest request) { var blog = await GetBlogForEntry(request.BlogId); if (blog == null || string.IsNullOrWhiteSpace(request.Author) || string.IsNullOrWhiteSpace(request.Title)) { return(null); } var newBlogArticle = new Article() { BlogId = blog.Id, Author = request.Author, Title = request.Title, Description = request.Description, Created = _clock.Now }; await _context.Add(newBlogArticle); await _context.SaveChanges(); return(newBlogArticle); }
public async Task <MetaTag[]> AddArticleMetaTags(Guid articleId, params MetaTagRequest[] metaTagRequests) { if (metaTagRequests == null || !metaTagRequests.Any()) { throw new ArgumentNullException(nameof(metaTagRequests)); } var existingArticle = GetExistingArticle(articleId); if (existingArticle == null) { return(null); } var tagsToCreate = metaTagRequests .Where(mtr => existingArticle.MetaTags.All(mt => mt.Name != mtr.Name)) .ToArray(); if (!tagsToCreate.Any()) { return(null); } var newMetaTagsForArticle = tagsToCreate.Select(nt => new MetaTag { ArticleId = existingArticle.Id, Article = existingArticle, Name = nt.Name }).ToArray(); await _context.Add(newMetaTagsForArticle); await _context.SaveChanges(); return(newMetaTagsForArticle); }
public async Task <EntryContent> MarkUploadSuccess(EntryContent entryContent, string uploadUrl) { if (entryContent == null) { throw new ArgumentNullException(nameof(entryContent)); } if (string.IsNullOrWhiteSpace(uploadUrl)) { throw new ArgumentNullException(nameof(uploadUrl)); } _context.Attach(entryContent); entryContent.Persisted = _clock.Now; entryContent.BlobUrl = StringUtilities.ToBase64(uploadUrl); await _context.SaveChanges(); return(entryContent); }
public async Task <EntryMedia> MarkUploadedSuccess(EntryMedia articleEntryMedia, string uploadUri) { if (articleEntryMedia == null) { throw new ArgumentNullException(nameof(articleEntryMedia)); } if (string.IsNullOrWhiteSpace(uploadUri)) { throw new ArgumentNullException(nameof(uploadUri)); } _context.Attach(articleEntryMedia); articleEntryMedia.BlobUrl = StringUtilities.ToBase64(uploadUri); articleEntryMedia.Persisted = _clock.Now; await _context.SaveChanges(); return(articleEntryMedia); }
public async Task <bool> TryUpdateArticle(Guid articleId, ArticleRequest updatedArticle) { if (updatedArticle == null) { throw new ArgumentNullException(nameof(updatedArticle)); } var existingArticle = await _context.Find <Article>(articleId); if (existingArticle == null) { return(false); } UpdateValues(existingArticle, updatedArticle); await _context.SaveChanges(); return(true); }
public async Task <bool> TryDeleteArticle(Guid articleId) { var articleToDelete = await _context.Find <Article>(articleId); if (articleToDelete == null) { return(false); } if (articleToDelete.IsDeleted) { return(true); } articleToDelete.IsDeleted = true; articleToDelete.Deleted = _clock.Now; await _context.SaveChanges(); return(true); }
private async Task UpdateConvertedBlobUrl(EntryContent latestEntry, string storageUrl) { latestEntry.ConvertedBlobUrl = StringUtilities.ToBase64(storageUrl); _context.Attach(latestEntry); await _context.SaveChanges(); }