Final (?) de-widgetification

This commit is contained in:
2021-09-07 14:33:48 +00:00
parent 898daac02c
commit 316c8aa5bd
27 changed files with 45 additions and 1560 deletions

View File

@@ -114,49 +114,49 @@ namespace AyaNova.Util
apiServerState.SetOpsOnly("Seeding database with sample data");
// //WIDGET sample form customization
// //CUSTOMER sample form customization
// {
// var fc = new FormCustom()
// {
// FormKey = AyaType.Widget.ToString(),
// FormKey = AyaType.Customer.ToString(),
// Template = @"[
// {
// ""fld"": ""Notes"",
// ""required"": true
// },
// {
// ""fld"": ""WidgetCustom1"",
// ""fld"": ""CustomerCustom1"",
// ""required"": false,
// ""type"": 1
// },
// {
// ""fld"": ""WidgetCustom2"",
// ""fld"": ""CustomerCustom2"",
// ""required"": true,
// ""type"": 4
// },
// {
// ""fld"": ""WidgetCustom3"",
// ""fld"": ""CustomerCustom3"",
// ""required"": false,
// ""type"": 5
// },
// {
// ""fld"": ""WidgetCustom4"",
// ""fld"": ""CustomerCustom4"",
// ""required"": false,
// ""type"": 6
// },
// {
// ""fld"": ""WidgetCustom5"",
// ""fld"": ""CustomerCustom5"",
// ""required"": false,
// ""type"": 8
// },
// {
// ""fld"": ""WidgetCustom6"",
// ""fld"": ""CustomerCustom6"",
// ""required"": false,
// ""type"": 2
// },
// {
// ""fld"": ""WidgetCustom7"",
// ""fld"": ""CustomerCustom7"",
// ""required"": false,
// ""type"": 3
// }
@@ -175,9 +175,9 @@ namespace AyaNova.Util
// {
// Name = "Name starts with generic",
// UserId = 1,
// ListKey = "TestWidgetDataList",
// ListKey = "TestCustomerDataList",
// Public = true,
// ListView = @"[{""fld"": ""widgetname"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Generic""}]}}]"
// ListView = @"[{""fld"": ""customername"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Generic""}]}}]"
// };
// //Create and save to db
@@ -188,9 +188,9 @@ namespace AyaNova.Util
// {
// Name = "Awesome (lots of fields)",
// UserId = 1,
// ListKey = "TestWidgetDataList",
// ListKey = "TestCustomerDataList",
// Public = true,
// ListView = @"[{""fld"": ""widgetname"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Awesome""}]}},{""fld"":""widgetserial""},{""fld"":""widgetdollaramount""},{""fld"":""widgetusertype""},{""fld"":""widgetstartdate""},{""fld"":""widgetactive""},{""fld"":""username""},{""fld"":""widgettags""},{""fld"":""widgetcustom1""},{""fld"":""widgetcustom2""}]"
// ListView = @"[{""fld"": ""customername"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Awesome""}]}},{""fld"":""customerserial""},{""fld"":""customerdollaramount""},{""fld"":""customerusertype""},{""fld"":""customerstartdate""},{""fld"":""customeractive""},{""fld"":""username""},{""fld"":""customertags""},{""fld"":""customercustom1""},{""fld"":""customercustom2""}]"
// };
// //Create and save to db
@@ -227,8 +227,7 @@ namespace AyaNova.Util
//Generate owner and lead tech
await SeedUserAsync(log, 1, AuthorizationRoles.BizAdmin | AuthorizationRoles.Service | AuthorizationRoles.Inventory | AuthorizationRoles.OpsAdmin, UserType.Service);
//Generate one office person / secretary
await SeedUserAsync(log, 1, AuthorizationRoles.Service | AuthorizationRoles.Inventory | AuthorizationRoles.Accounting, UserType.NotService);
// await SeedWidgetAsync(log, 3);//keeping this here for now but must remove later
await SeedUserAsync(log, 1, AuthorizationRoles.Service | AuthorizationRoles.Inventory | AuthorizationRoles.Accounting, UserType.NotService);
await SeedVendorAsync(log, 10);
await SeedUnitModelAsync(log, 10);
await SeedCustomerAsync(log, 25);
@@ -287,7 +286,6 @@ namespace AyaNova.Util
//1 accountant / bookkeeper
await SeedUserAsync(log, 1, AuthorizationRoles.Accounting | AuthorizationRoles.BizAdminRestricted, UserType.NotService);
//await SeedWidgetAsync(log, 100);
await SeedVendorAsync(log, 50);
await SeedUnitModelAsync(log, 20);
await SeedCustomerAsync(log, 500);
@@ -356,7 +354,6 @@ namespace AyaNova.Util
//5 accountant / bookkeeper
await SeedUserAsync(log, 5, AuthorizationRoles.Accounting | AuthorizationRoles.BizAdminRestricted, UserType.NotService);
//await SeedWidgetAsync(log, 100);
await SeedVendorAsync(log, 100);
await SeedUnitModelAsync(log, 40);
await SeedCustomerAsync(log, 1000);
@@ -426,7 +423,6 @@ namespace AyaNova.Util
//accountant / bookkeeper
await SeedUserAsync(log, 20, AuthorizationRoles.Accounting | AuthorizationRoles.BizAdminRestricted, UserType.NotService);
//await SeedWidgetAsync(log, 100);
await SeedVendorAsync(log, 500);
await SeedUnitModelAsync(log, 200);
await SeedCustomerAsync(log, 10000);
@@ -1772,62 +1768,7 @@ namespace AyaNova.Util
}
#region WIDGET
// //////////////////////////////////////////////////////
// //Seed widget for testing
// //
// public async Task SeedWidgetAsync(ILogger log, int count)
// {
// //this is 4 times slower than doing it inside the loop below
// //seems counterintuitive but maybe it's to do with the db context not being refreshed?
// //RANDOM ROLES
// Array values = Enum.GetValues(typeof(UserType));
// Random random = new Random();
// DateTime seedStartWindow = DateTime.Now.AddYears(-1).AddMonths(-6);
// DateTime seedEndWindow = DateTime.Now.AddYears(1).AddMonths(6);
// for (int x = 0; x < count; x++)
// {
// Widget o = new Widget();
// o.Name = Uniquify(Fake.Commerce.ProductName());
// o.Active = true;
// DateTime dtSeed = Fake.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime();
// o.StartDate = dtSeed;
// o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime();
// o.DollarAmount = Convert.ToDecimal(Fake.Commerce.Price());
// //Random but valid enum
// UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length));
// o.UserType = randomUserType;
// o.Notes = Fake.Lorem.Sentence(null, 5);
// o.Tags = RandomTags();
// o.UserId = Fake.Random.Int(1, TotalSeededUsers);
// //RANDOM CUSTOM FIELD DATA
// var c1 = DateUtil.UniversalISO8661Format(Fake.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)));
// var c2 = Fake.Lorem.Sentence(null, 5);
// var c3 = Fake.Random.Int(1, 99999999);
// var c4 = Fake.Random.Bool().ToString().ToLowerInvariant();
// var c5 = Fake.Random.Decimal();
// o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}";
// //This seems wrong to do in a loop but is 4 times faster this way ?!?
// using (AyContext ct = ServiceProviderProvider.DBContext)
// {
// WidgetBiz biz = WidgetBiz.GetBiz(ct);
// var NewObject = await biz.CreateAsync(o);
// if (NewObject == null)
// {
// log.LogError($"Seeder::SeedWidget error creating {o.Name}\r\n" + biz.GetErrorsAsString());
// throw new System.Exception("Seeder::SeedWidget error creating widget\r\n" + biz.GetErrorsAsString());
// }
// }
// }
// }
#endregion
public HashSet<string> HashCompanyNames = new HashSet<string>();
private int TotalSeededCustomers = 0;