From 8c1d448ade5e2dcad810ab3b9b183df35b54d73c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 29 Aug 2018 15:07:17 +0000 Subject: [PATCH] --- server/AyaNova/util/Seeder.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index c3b8d57b..2c7a3295 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -60,10 +60,8 @@ namespace AyaNova.Util //Erase all the data except for the license, schema and the manager user DbUtil.PrepareDatabaseForSeeding(log); - var f = new Faker("en"); - //Seed special test data for integration testing - SeedTestData(); + SeedKnownUsers(); switch (slevel) @@ -192,7 +190,7 @@ namespace AyaNova.Util ////////////////////////////////////////////////////// //Seed test data for integration tests // - public static void SeedTestData() + public static void SeedKnownUsers() { //TEST USERS @@ -251,6 +249,25 @@ namespace AyaNova.Util u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID; ct.User.Add(u); } + //save to get id values + ct.SaveChanges(); + + //Now that we have the ID values bulk add the event log entries + //To save a db call iterate the local collection in the context, but... + //can't modify the context in the foreach, even if it's another collection entirely, so need to save the id's in a temporary list + List ItemsAdded = new List(); + foreach (User o in ct.User.Local) + { + ItemsAdded.Add(o.Id); + } + + //Now we have all the id's can actually add them to the context + foreach (long l in ItemsAdded) + { + EventLogProcessor.AddEntry(new Event(1, l, AyaType.User, AyaEvent.Created), ct); + } + + //Now save the Event Log entries ct.SaveChanges(); }