From 0be80ba8396ff4fcae0d4175df978accf724a3a7 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 7 Dec 2020 23:54:09 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- server/AyaNova/util/Seeder.cs | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0e2049e9..8fd97968 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,7 +53,7 @@ "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", - "AYANOVA_SERVER_TEST_MODE": "false", + "AYANOVA_SERVER_TEST_MODE": "true", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index 69e6ce00..96b2237b 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -575,12 +575,54 @@ namespace AyaNova.Util await SeedUserAsync(log, 1, AuthorizationRoles.All, UserType.NotService, true, "fr", "fr", await TranslationBiz.TranslationNameToIdStaticAsync("fr"), KnownUserTags); { + + long HeadOfficeIdForCustomer=0; + //seed a HO + HeadOffice ho = new HeadOffice(); + ho.Name = "XYZ Head Office"; + + + ho.Active = true; + ho.Notes = Fake.Company.CatchPhrase(); + ho.Tags = RandomTags(); + + ho.AccountNumber = Fake.Finance.Account(); + ho.Latitude = (decimal)Fake.Address.Latitude(); + ho.Longitude = (decimal)Fake.Address.Longitude(); + ho.Address = Fake.Address.StreetAddress(); + ho.City = Fake.Address.City(); + ho.Region = Fake.Address.State(); + ho.Country = Fake.Address.Country(); + + ho.Phone1 = Fake.Phone.PhoneNumber(); + ho.Phone2 = Fake.Phone.PhoneNumber(); + ho.Phone3 = Fake.Phone.PhoneNumber(); + ho.WebAddress = Fake.Internet.Url(); + ho.EmailAddress = Fake.Internet.ExampleEmail(); + + using (AyContext ct = ServiceProviderProvider.DBContext) + { + HeadOfficeBiz biz = HeadOfficeBiz.GetBiz(ct); + var NewObject = await biz.CreateAsync(ho); + + if (NewObject == null) + { + var err = $"Seeder::SeedHeadOffice error creating {ho.Name}\r\n{biz.GetErrorsAsString()}"; + log.LogError(err); + throw new System.Exception(err); + } + //Known HO type user + await SeedUserAsync(log, 1, AuthorizationRoles.CustomerFull, UserType.HeadOffice, true, "HeadOffice", "HeadOffice", 0, KnownUserTags, null, NewObject.Id, null); + HeadOfficeIdForCustomer=NewObject.Id; + } + + //CUSTOMER / HO Users //seed a customer Customer o = new Customer(); o.Name = "XYZ Accounting"; - + o.HeadOfficeId=HeadOfficeIdForCustomer; o.Active = true; o.Notes = Fake.Company.CatchPhrase(); o.Tags = RandomTags(); @@ -599,6 +641,7 @@ namespace AyaNova.Util o.WebAddress = Fake.Internet.Url(); o.EmailAddress = Fake.Internet.ExampleEmail(); + using (AyContext ct = ServiceProviderProvider.DBContext) { CustomerBiz biz = CustomerBiz.GetBiz(ct); @@ -610,12 +653,13 @@ namespace AyaNova.Util log.LogError(err); throw new System.Exception(err); } - //Known customer type users - + //Known customer type users await SeedUserAsync(log, 1, AuthorizationRoles.CustomerFull, UserType.Customer, true, "CustomerFull", "CustomerFull", 0, KnownUserTags, null, NewObject.Id, null); await SeedUserAsync(log, 1, AuthorizationRoles.CustomerFull, UserType.Customer, true, "CustomerLimited", "CustomerLimited", 0, KnownUserTags, null, NewObject.Id, null); } + + } }