diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index 7be6c99e..7857823b 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -211,39 +211,21 @@ namespace AyaNova.Util await LogStatusAsync(JobId, LogJob, log, $"Seeding SMALL sample data...."); var watch = new Stopwatch(); watch.Start(); - - //USERS + //Generate owner and lead tech await SeedUserAsync(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull, UserType.Service); - //Generate one office person / secretary await SeedUserAsync(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NotService); - - //WIDGET await SeedWidgetAsync(log, 100); - - //CUSTOMERS await SeedCustomerAsync(log, 100); - - //HEAD-OFFICES await SeedHeadOfficeAsync(log, 10); - - //VENDORS await SeedVendorAsync(log, 25); - - //PROJECTS await SeedProjectAsync(log, 25); - - //RATES await SeedServiceRateAsync(log, 5); await SeedTravelRateAsync(log, 3); - - //UNITMODELS await SeedUnitModelAsync(log, 10); - - //UNITS await SeedUnitAsync(log, 500);//5 times the customers or 5 units per customer - + await SeedLoanLoanUnitAsync(log,5); //PERF watch.Stop(); @@ -262,63 +244,37 @@ namespace AyaNova.Util var watch = new Stopwatch(); watch.Start(); - //USERS //One IT administrator, can change ops but nothing else await SeedUserAsync(log, 1, AuthorizationRoles.OpsAdminFull, UserType.NotService); - //One business administrator, can view ops issues await SeedUserAsync(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NotService); - //One owner who doesn't control anything but views stuff await SeedUserAsync(log, 1, AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited | AuthorizationRoles.SalesLimited, UserType.NotService); - //20 techs await SeedUserAsync(log, 20, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Service); - //2 subcontractors await SeedUserAsync(log, 2, AuthorizationRoles.SubContractorFull, UserType.ServiceContractor); - //3 generic office people people await SeedUserAsync(log, 3, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NotService); - //2 Full sales people await SeedUserAsync(log, 2, AuthorizationRoles.SalesFull, UserType.NotService); - //1 dispatch manager await SeedUserAsync(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NotService); - //1 Inventory manager await SeedUserAsync(log, 1, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NotService); - //1 accountant / bookkeeper await SeedUserAsync(log, 1, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NotService); - - //WIDGETS await SeedWidgetAsync(log, 100); - - //CUSTOMERS await SeedCustomerAsync(log, 500); - - //HEAD-OFFICES await SeedHeadOfficeAsync(log, 20); - - //VENDORS await SeedVendorAsync(log, 50); - - //PROJECTS await SeedProjectAsync(log, 50); - - //RATES await SeedServiceRateAsync(log, 10); await SeedTravelRateAsync(log, 5); - - //UNITMODELS await SeedUnitModelAsync(log, 25); - - - //UNITS - await SeedUnitAsync(log, 2500);//5 times the customers or 5 units per customer + await SeedUnitAsync(log, 2500);//5 times the customers or 5 units per customer + await SeedLoanLoanUnitAsync(log,10); //PERF watch.Stop(); @@ -338,75 +294,46 @@ namespace AyaNova.Util var watch = new Stopwatch(); watch.Start(); - //USERS //IT administrator, can change ops but nothing else await SeedUserAsync(log, 2, AuthorizationRoles.OpsAdminFull, UserType.NotService); - //business administrator, can view ops issues await SeedUserAsync(log, 2, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NotService); - //owner / upper management who doesn't control anything but views stuff await SeedUserAsync(log, 5, AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NotService); - //100 techs await SeedUserAsync(log, 100, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Service); - //limited techs await SeedUserAsync(log, 50, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited, UserType.Service); - //20 subcontractors await SeedUserAsync(log, 20, AuthorizationRoles.SubContractorFull, UserType.ServiceContractor); - //10 limited subcontractors await SeedUserAsync(log, 10, AuthorizationRoles.SubContractorLimited, UserType.ServiceContractor); - //30 generic office people people await SeedUserAsync(log, 30, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NotService); - //10 Full sales people await SeedUserAsync(log, 10, AuthorizationRoles.SalesFull, UserType.NotService); - //5 Limited sales people await SeedUserAsync(log, 5, AuthorizationRoles.SalesLimited, UserType.NotService); - //5 dispatch manager await SeedUserAsync(log, 5, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NotService); - //5 Inventory manager - await SeedUserAsync(log, 5, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NotService); - + await SeedUserAsync(log, 5, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NotService); //10 Inventory manager assistants await SeedUserAsync(log, 5, AuthorizationRoles.InventoryLimited, UserType.NotService); - //5 accountant / bookkeeper await SeedUserAsync(log, 5, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NotService); - //WIDGETS await SeedWidgetAsync(log, 100); - - //CUSTOMERS await SeedCustomerAsync(log, 5000); - - //HEAD-OFFICES await SeedHeadOfficeAsync(log, 30); - - //VENDORS await SeedVendorAsync(log, 75); - - //PROJECTS await SeedProjectAsync(log, 75); - - //RATES await SeedServiceRateAsync(log, 20); await SeedTravelRateAsync(log, 10); - - //UNITMODELS await SeedUnitModelAsync(log, 30); - - - //UNITS - await SeedUnitAsync(log, 25000);//5 times the customers or 5 units per customer + await SeedUnitAsync(log, 25000);//5 times the customers or 5 units per customer + await SeedLoanLoanUnitAsync(log,15); //PERF watch.Stop(); @@ -430,70 +357,43 @@ namespace AyaNova.Util //USERS //IT administrator, can change ops but nothing else await SeedUserAsync(log, 10, AuthorizationRoles.OpsAdminFull, UserType.NotService); - //business administrator, can view ops issues await SeedUserAsync(log, 10, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NotService); - //owner / upper management who doesn't control anything but views stuff await SeedUserAsync(log, 20, AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NotService); - //regular techs await SeedUserAsync(log, 500, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Service); - //limited techs await SeedUserAsync(log, 200, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited, UserType.Service); - //subcontractors await SeedUserAsync(log, 80, AuthorizationRoles.SubContractorFull, UserType.ServiceContractor); - //limited subcontractors await SeedUserAsync(log, 40, AuthorizationRoles.SubContractorLimited, UserType.ServiceContractor); - //generic office people people await SeedUserAsync(log, 200, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NotService); - //20 Full sales people await SeedUserAsync(log, 20, AuthorizationRoles.SalesFull, UserType.NotService); - //10 Limited sales people await SeedUserAsync(log, 10, AuthorizationRoles.SalesLimited, UserType.NotService); - //dispatch manager await SeedUserAsync(log, 20, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NotService); - //Inventory manager await SeedUserAsync(log, 40, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NotService); - //Inventory manager assistants await SeedUserAsync(log, 20, AuthorizationRoles.InventoryLimited, UserType.NotService); - //accountant / bookkeeper await SeedUserAsync(log, 20, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NotService); - //WIDGETS await SeedWidgetAsync(log, 100); - - //CUSTOMERS await SeedCustomerAsync(log, 20000); - - //HEAD-OFFICES await SeedHeadOfficeAsync(log, 40); - - //VENDORS await SeedVendorAsync(log, 100); - - //PROJECTS await SeedProjectAsync(log, 500); - - //RATES await SeedServiceRateAsync(log, 30); await SeedTravelRateAsync(log, 15); - - //UNITMODELS await SeedUnitModelAsync(log, 40); - - //UNITS - await SeedUnitAsync(log, 100000);//5 times the customers or 5 units per customer + await SeedUnitAsync(log, 100000);//5 times the customers or 5 units per customer + await SeedLoanLoanUnitAsync(log, 20); //PERF watch.Stop(); @@ -1435,17 +1335,17 @@ namespace AyaNova.Util o.PurchasedFromVendorId = Fake.Random.Long(1, TotalSeededVendors); } - o.Receipt=Fake.Finance.Account(6); - o.PurchasedDate=Fake.Date.Between(seedStartWindow, DateTime.Now).ToUniversalTime(); - o.Description=Fake.Commerce.ProductName(); - o.ReplacedByUnitId=null; + o.Receipt = Fake.Finance.Account(6); + o.PurchasedDate = Fake.Date.Between(seedStartWindow, DateTime.Now).ToUniversalTime(); + o.Description = Fake.Commerce.ProductName(); + o.ReplacedByUnitId = null; //for now no banked units in seeds - o.UsesBanking=false; - o.Metered=false;//for now no meters either - o.Text1=null; - o.Text2=null; - o.Text3=null; - o.Text4=null; + o.UsesBanking = false; + o.Metered = false;//for now no meters either + o.Text1 = null; + o.Text2 = null; + o.Text3 = null; + o.Text4 = null; //Unit has own address 5% chance (1/20) if (Fake.Random.Number(1, 20) == 5) @@ -1480,6 +1380,60 @@ namespace AyaNova.Util } + + + + private int TotalSeededLoanUnits = 0; + ////////////////////////////////////////////////////// + //LOANUNIT + // + public async Task SeedLoanLoanUnitAsync(ILogger log, int count) + { + + for (int x = 0; x < count; x++) + { + LoanUnit o = new LoanUnit(); + + do + { + o.Serial = Fake.Finance.Account(); + } while (!HashUnitNames.Add(o.Serial)); + + do + { + o.Name = Fake.Commerce.ProductName(); + } while (!HashUnitNames.Add(o.Name)); + + + o.Active = true; + o.Notes = Fake.Lorem.Sentence(); + o.Tags = RandomTags(); + + o.RateHour = Fake.Random.Decimal(1, 25); + o.RateHalfDay = o.RateHour * 4; + o.RateDay = o.RateHour * 8; + o.RateWeek = o.RateHour * 36.8m; + o.RateMonth = o.RateHour * 21 * 8; + o.RateYear = o.RateHour * 36.8m * 52; + o.DefaultRate=Fake.Random.Enum(); + + + using (AyContext ct = ServiceProviderProvider.DBContext) + { + LoanUnitBiz biz = LoanUnitBiz.GetBiz(ct); + var NewObject = await biz.CreateAsync(o); + TotalSeededLoanUnits++; + if (NewObject == null) + { + var err = $"Seeder::SeedLoanUnit error creating {o.Serial}\r\n{biz.GetErrorsAsString()}"; + log.LogError(err); + throw new System.Exception(err); + } + } + } + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// }//eoc