public async Task AddSingleNews(FinWireData finwireData) { var finwireXmlNewsAdded = await _dbContext.FinwireXmlNews.AddAsync(new FinwireXmlNews { DateTime = DateTime.Now, FileContent = finwireData.RoughXml, FileName = finwireData.Guid, }); if (!_dbContext.FinwireNews.Any(x => finwireData.Guid == x.Guid)) { var newsEntity = finwireData.ToFinwireNews(); newsEntity.FinautoPassed = _finwireFilterService.IsFilterPassed(finwireData); newsEntity.FinwireAgency = _dbContext.FinwireAgencies.FirstOrDefault(x => x.Agency == finwireData.Agency) ?? (await _dbContext.AddAsync(new FinwireAgency { Agency = finwireData.Agency })).Entity; newsEntity.FinwireXmlNews = finwireXmlNewsAdded.Entity; var newsEntityAdded = (await _dbContext.AddAsync(newsEntity)).Entity; //todo make generic method in helper etc, find better solution using EF Core finwireData.SocialTags?.ForEach(async x => await _dbContext.AddAsync(new FinwireNew2FirnwireSocialTag { FinwireNew = newsEntityAdded, FinwireSocialTag = _dbContext.FinwireSocialTags.FirstOrDefault(y => y.Tag == x) ?? (await _dbContext.AddAsync(new FinwireSocialTag { Tag = x })).Entity }) ); finwireData.Companies?.ForEach(async x => { await _dbContext.AddAsync(new FinwireNew2FinwireCompany { FinwireNew = newsEntityAdded, FinwireCompany = _dbContext.FinwireCompanies.FirstOrDefault(y => y.Company == x) ?? (await _dbContext.AddAsync(new FinwireCompany { Company = x, Slug = x.ToSlug() })).Entity }); }); } await _dbContext.SaveChangesAsync(); }