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);
        }
        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);
        }
        private async Task <EntryContent> CreateNewEntryFor(Article article, ArticleEntry entry)
        {
            var entryContent = new EntryContent
            {
                ArticleId = article.Id,
                Created   = _clock.Now,
            };

            await _context.Add(entryContent);

            await _context.SaveChanges();

            return(entryContent);
        }
        private async Task <EntryMedia> CreateNewEntryMediaFor(EntryContent entryContent, ArticleEntryMediaRequest entryMediaRequest)
        {
            var entryMedia = new EntryMedia();

            entryMedia.FileName       = entryMediaRequest.FileName;
            entryMedia.ContentType    = entryMediaRequest.ContentType;
            entryMedia.BlobFileName   = Guid.NewGuid();
            entryMedia.EntryContentId = entryContent.Id;
            entryMedia.MD5Base64Hash  = entryMediaRequest.MD5Base64Hash;
            entryMedia.Created        = _clock.Now;

            await _context.Add(entryMedia);

            await _context.SaveChanges();

            return(entryMedia);
        }