예제 #1
0
        /// <summary>
        /// Додавання данних
        /// </summary>
        /// <param name="dbContext">Контекст БД</param>
        /// <param name="isDevelopment">Режим роботи</param>
        /// <returns></returns>
        public static async Task EnsureSeededAsync(this ApplicationDbContext dbContext, bool isDevelopment)
        {
            dbContext.LoggingDisable = true;

            try
            {
                if (!dbContext.TournamentTypes.IgnoreQueryFilters().Any())
                {
                    await TournamentTypeData.Seed(dbContext);
                }
                if (!dbContext.Countries.IgnoreQueryFilters().Any())
                {
                    await CountryData.Seed(dbContext);
                }
                if (!dbContext.Configurations.Any())
                {
                    await ConfigurationData.Seed(dbContext);
                }
                if (!dbContext.Players.Any())
                {
                    await PlayerData.Seed(dbContext);
                }

                if (isDevelopment)
                {
                    if (!dbContext.Trainings.IgnoreQueryFilters().Any())
                    {
                        await TrainingData.Seed(dbContext);
                    }
                    if (!dbContext.Matches.IgnoreQueryFilters().Any())
                    {
                        await MatchData.Seed(dbContext);
                    }
                    if (!dbContext.MatchToPlayers.IgnoreQueryFilters().Any())
                    {
                        await MatchToPlayerData.Seed(dbContext);
                    }
                    if (!dbContext.Stages.IgnoreQueryFilters().Any())
                    {
                        await StageData.Seed(dbContext);
                    }
                    if (!dbContext.StageToPlayers.IgnoreQueryFilters().Any())
                    {
                        await StageToPlayerData.Seed(dbContext);
                    }
                    if (!dbContext.Balls.IgnoreQueryFilters().Any())
                    {
                        await BallData.Seed(dbContext);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("{SeedError}", ex.Message);
            }

            dbContext.LoggingDisable = false;
        }