private async Task AddTags(Article article, IEnumerable <string> titles, bool setUpdated = false) { foreach (string title in titles) { var tagId = _tagFactory.GetId(title); var tag = await _context.Tag.Where(x => x.Id == tagId).FirstOrDefaultAsync().ConfigureAwait(false); if (tag is null) { tag = _tagFactory.CreateTag(title); await _context.Tag.AddAsync(tag).ConfigureAwait(false); } else if (setUpdated) { _tagFactory.UpdateTag(tag); } await _context.TagArticle.AddAsync(new TagArticle(tag, article)).ConfigureAwait(false); } }
private async Task AddTags(Article article, IEnumerable <string> titles, bool setUpdated = false) { article.TagsIds ??= new List <string>(); foreach (string title in titles) { var tagId = _tagFactory.GetId(title); var tag = await(await _client.Tag().FindAsync(x => x.Id == tagId).CAF()).FirstOrDefaultAsync().CAF(); if (tag is null) { tag = _tagFactory.CreateTag(title); await _client.Tag().InsertOneAsync(tag).CAF(); } else if (setUpdated) { _tagFactory.UpdateTag(tag); } article.TagsIds.Add(tagId); } }