public async Task <IList <ArticleSeries> > GetSeries(string userId, ArticleSeriesType articleSeriesType) { Expression <Func <ArticleSeries, bool> > filter = (x) => articleSeriesType == ArticleSeriesType.Finished ? x.Finished : articleSeriesType == ArticleSeriesType.Unfinished ? !x.Finished : x.Finished || !x.Finished; return(await(await _client.ArticleSeries().FindAsync(filter).CAF()).ToListAsync()); }
private static async Task MigrateArticleSeries(Data originalDbContext, IMongoClient targetMongoClient, ILogger logger) { logger.LogCritical("Starting the article series collection"); var articleSeriesCollection = targetMongoClient.ArticleSeries(); await originalDbContext.ArticleSeries.AsNoTracking() .Include(x => x.Articles) .ForEachAsync(async(articleSeries) => { var targetArticleSeries = await(await articleSeriesCollection.FindAsync(x => x.SeriesId == articleSeries.Id.ToString()).CAF()).FirstOrDefaultAsync() .CAF(); if (targetArticleSeries is null) { articleSeries.SeriesId = articleSeries.Id.ToString(); articleSeries.ArticlesIds = articleSeries.Articles.Select(x => $"{x.CreatedYear.ToString()}-{x.TitleShrinked}").ToList(); await articleSeriesCollection.InsertOneAsync(articleSeries).CAF(); logger.LogCritical("Article Series with id: {id} was added to MongoDB", articleSeries.Id); } else { logger.LogCritical("Article Series with id: {id} already exists in MongoDB", articleSeries.Id); } }).CAF(); logger.LogCritical("Finished the article series collection"); }