Beispiel #1
0
 public static ThemeModel TryAddTheme(ThemeModel model)
 {
     AllThemes.Add(model);
     if (ThemeDic.TryAdd(model.NormalizedName, model))
         return model;
     return ThemeDic[model.NormalizedName];
 }
        public async Task AddThemeToArticleAsync(ArticleModel article, string theme)
        {
            await Initialize();

            await ExecuteSafe(async () =>
            {
                var normalizedTheme = NormalizeThemeName(theme);
                var themeModel = ThemeManager.TryGetSimilarTheme(normalizedTheme);
                if (themeModel == null)
                {
                    themeModel = new ThemeModel()
                    {
                        NormalizedName = normalizedTheme,
                        Name = theme
                    };
                    //concurrency: soem other thread may have added the same theme
                    var tm = ThemeManager.TryAddTheme(themeModel);
                    if (tm == themeModel)
                        await _themeGenericRepository.AddAsync(themeModel);
                }
                if (article.Themes.Contains(themeModel))
                    return;

                article.Themes.Add(themeModel);
                await _sqliteService.Add(new ThemeArticleRelations()
                {
                    ArticleId = article.GetId(),
                    ThemeId = themeModel.GetId()
                });
            });
        }
Beispiel #3
0
 public static void AddTheme(ThemeModel model)
 {
     AllThemes.Add(model);
     ThemeDic.TryAdd(model.NormalizedName, model);
 }