DeWidgetification round 1

This commit is contained in:
2021-07-09 17:40:02 +00:00
parent 608f34263d
commit b162ecd6e5

View File

@@ -114,59 +114,59 @@ namespace AyaNova.Util
apiServerState.SetOpsOnly("Seeding database with sample data"); apiServerState.SetOpsOnly("Seeding database with sample data");
//WIDGET sample form customization // //WIDGET sample form customization
{ // {
var fc = new FormCustom() // var fc = new FormCustom()
{ // {
FormKey = AyaType.Widget.ToString(), // FormKey = AyaType.Widget.ToString(),
Template = @"[ // Template = @"[
{ // {
""fld"": ""Notes"", // ""fld"": ""Notes"",
""required"": true // ""required"": true
}, // },
{ // {
""fld"": ""WidgetCustom1"", // ""fld"": ""WidgetCustom1"",
""required"": false, // ""required"": false,
""type"": 1 // ""type"": 1
}, // },
{ // {
""fld"": ""WidgetCustom2"", // ""fld"": ""WidgetCustom2"",
""required"": true, // ""required"": true,
""type"": 4 // ""type"": 4
}, // },
{ // {
""fld"": ""WidgetCustom3"", // ""fld"": ""WidgetCustom3"",
""required"": false, // ""required"": false,
""type"": 5 // ""type"": 5
}, // },
{ // {
""fld"": ""WidgetCustom4"", // ""fld"": ""WidgetCustom4"",
""required"": false, // ""required"": false,
""type"": 6 // ""type"": 6
}, // },
{ // {
""fld"": ""WidgetCustom5"", // ""fld"": ""WidgetCustom5"",
""required"": false, // ""required"": false,
""type"": 8 // ""type"": 8
}, // },
{ // {
""fld"": ""WidgetCustom6"", // ""fld"": ""WidgetCustom6"",
""required"": false, // ""required"": false,
""type"": 2 // ""type"": 2
}, // },
{ // {
""fld"": ""WidgetCustom7"", // ""fld"": ""WidgetCustom7"",
""required"": false, // ""required"": false,
""type"": 3 // ""type"": 3
} // }
]" // ]"
}; // };
//Create and save to db // //Create and save to db
using (var ct = ServiceProviderProvider.DBContext) // using (var ct = ServiceProviderProvider.DBContext)
await FormCustomBiz.GetBiz(ct).CreateAsync(fc); // await FormCustomBiz.GetBiz(ct).CreateAsync(fc);
} // }
//TODO: Add this back in or...fuck it? //TODO: Add this back in or...fuck it?
// //Create a couple of DataListView's for development and testing // //Create a couple of DataListView's for development and testing
@@ -228,7 +228,7 @@ namespace AyaNova.Util
await SeedUserAsync(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull, UserType.Service); await SeedUserAsync(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull, UserType.Service);
//Generate one office person / secretary //Generate one office person / secretary
await SeedUserAsync(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NotService); await SeedUserAsync(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NotService);
await SeedWidgetAsync(log, 3);//keeping this here for now but must remove later // await SeedWidgetAsync(log, 3);//keeping this here for now but must remove later
await SeedCustomerAsync(log, 25); await SeedCustomerAsync(log, 25);
await SeedHeadOfficeAsync(log, 10); await SeedHeadOfficeAsync(log, 10);
await SeedVendorAsync(log, 10); await SeedVendorAsync(log, 10);
@@ -1563,58 +1563,58 @@ namespace AyaNova.Util
} }
#region WIDGET #region WIDGET
////////////////////////////////////////////////////// // //////////////////////////////////////////////////////
//Seed widget for testing // //Seed widget for testing
// // //
public async Task SeedWidgetAsync(ILogger log, int count) // public async Task SeedWidgetAsync(ILogger log, int count)
{ // {
//this is 4 times slower than doing it inside the loop below // //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? // //seems counterintuitive but maybe it's to do with the db context not being refreshed?
//RANDOM ROLES // //RANDOM ROLES
Array values = Enum.GetValues(typeof(UserType)); // Array values = Enum.GetValues(typeof(UserType));
Random random = new Random(); // Random random = new Random();
DateTime seedStartWindow = DateTime.Now.AddYears(-1).AddMonths(-6); // DateTime seedStartWindow = DateTime.Now.AddYears(-1).AddMonths(-6);
DateTime seedEndWindow = DateTime.Now.AddYears(1).AddMonths(6); // DateTime seedEndWindow = DateTime.Now.AddYears(1).AddMonths(6);
for (int x = 0; x < count; x++) // for (int x = 0; x < count; x++)
{ // {
Widget o = new Widget(); // Widget o = new Widget();
o.Name = Uniquify(Fake.Commerce.ProductName()); // o.Name = Uniquify(Fake.Commerce.ProductName());
o.Active = true; // o.Active = true;
DateTime dtSeed = Fake.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime(); // DateTime dtSeed = Fake.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime();
o.StartDate = dtSeed; // o.StartDate = dtSeed;
o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime(); // o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime();
o.DollarAmount = Convert.ToDecimal(Fake.Commerce.Price()); // o.DollarAmount = Convert.ToDecimal(Fake.Commerce.Price());
//Random but valid enum // //Random but valid enum
UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length)); // UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length));
o.UserType = randomUserType; // o.UserType = randomUserType;
o.Notes = Fake.Lorem.Sentence(null, 5); // o.Notes = Fake.Lorem.Sentence(null, 5);
o.Tags = RandomTags(); // o.Tags = RandomTags();
o.UserId = Fake.Random.Int(1, TotalSeededUsers); // o.UserId = Fake.Random.Int(1, TotalSeededUsers);
//RANDOM CUSTOM FIELD DATA // //RANDOM CUSTOM FIELD DATA
var c1 = DateUtil.UniversalISO8661Format(Fake.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1))); // var c1 = DateUtil.UniversalISO8661Format(Fake.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)));
var c2 = Fake.Lorem.Sentence(null, 5); // var c2 = Fake.Lorem.Sentence(null, 5);
var c3 = Fake.Random.Int(1, 99999999); // var c3 = Fake.Random.Int(1, 99999999);
var c4 = Fake.Random.Bool().ToString().ToLowerInvariant(); // var c4 = Fake.Random.Bool().ToString().ToLowerInvariant();
var c5 = Fake.Random.Decimal(); // var c5 = Fake.Random.Decimal();
o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}"; // 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 ?!? // //This seems wrong to do in a loop but is 4 times faster this way ?!?
using (AyContext ct = ServiceProviderProvider.DBContext) // using (AyContext ct = ServiceProviderProvider.DBContext)
{ // {
WidgetBiz biz = WidgetBiz.GetBiz(ct); // WidgetBiz biz = WidgetBiz.GetBiz(ct);
var NewObject = await biz.CreateAsync(o); // var NewObject = await biz.CreateAsync(o);
if (NewObject == null) // if (NewObject == null)
{ // {
log.LogError($"Seeder::SeedWidget error creating {o.Name}\r\n" + biz.GetErrorsAsString()); // 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()); // throw new System.Exception("Seeder::SeedWidget error creating widget\r\n" + biz.GetErrorsAsString());
} // }
} // }
} // }
} // }
#endregion #endregion