Esempio n. 1
0
        public void SeedUsers(LanguagerContext context)
        {
            var user = new User("Oleksandr Kalashnykov", "okalashnykov");

            context.Users.Add(user);

            context.SaveChanges();
        }
Esempio n. 2
0
        public void SeedLanguages(LanguagerContext context)
        {
            var languages = new[]
            {
                new Language("english")
            };

            context.Languages.AddRange(languages);
            context.SaveChanges();
        }
Esempio n. 3
0
        public static void Initialize(LanguagerContext context)
        {
            var initializer = new DatabaseInitializer();

            try
            {
                initializer.SeedEverything(context);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
        public void SeedEverything(LanguagerContext context)
        {
            context.Database.EnsureCreated();

            if (!context.Languages.Any())
            {
                SeedLanguages(context);
            }

            SeedSyllables(context);

            if (!context.Users.Any())
            {
                SeedUsers(context);
            }
        }
Esempio n. 5
0
        public void SeedSyllables(LanguagerContext context)
        {
            var syllables = new List <Syllable>();

            syllables.AddRange(Syllabary.Hiragana);
            syllables.AddRange(Syllabary.Katakana);

            foreach (var syllable in syllables)
            {
                if (!context.Syllables.Any(s => s.Value == syllable.Value))
                {
                    context.Syllables.Add(syllable);
                }
            }

            context.SaveChanges();
        }