This commit is contained in:
2021-01-14 21:22:12 +00:00
parent 9d64ab9560
commit 2556309241
3 changed files with 270 additions and 0 deletions

View File

@@ -1479,6 +1479,69 @@ namespace AyaNova.Util
}
public HashSet<string> HashPartNumbers = new HashSet<string>();
private int TotalSeededParts = 0;
//////////////////////////////////////////////////////
//PART
//
public async Task SeedPartAsync(ILogger log, int count)
{
for (int x = 0; x < count; x++)
{
Part o = new Part();
do
{
o.PartNumber = Fake.Finance.Account(6);
} while (!HashPartNumbers.Add(o.PartNumber));
o.Active = true;
o.Notes = Fake.Lorem.Sentence();
o.Tags = RandomTags();
o.ManufacturerId = Fake.Random.Long(1, TotalSeededVendors);//random picks in range Inclusive but sql id's start at 1 so this is kosher (not zero based)
o.ManufacturerNumber = "man-" + o.PartNumber;
o.UPC = Fake.Commerce.Ean13();
o.WholeSalerId = Fake.Random.Long(1, TotalSeededVendors);//random picks in range Inclusive but sql id's start at 1 so this is kosher (not zero based)
o.WholeSalerNumber = "ws-" + o.PartNumber;
o.Cost = Fake.Random.Decimal(1, 25);
o.Retail = o.Cost * 1.2m;
o.UnitOfMeasure = "each";
o.TrackSerialNumber = false;
//This seems wrong to do in a loop but is 4 times faster this way ?!?
using (AyContext ct = ServiceProviderProvider.DBContext)
{
PartBiz biz = PartBiz.GetBiz(ct);
var NewObject = await biz.CreateAsync(o);
TotalSeededParts++;
if (NewObject == null)
{
var err = $"Seeder::SeedPart error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
log.LogError(err);
throw new System.Exception(err);
}
}
}
}
//SEED PARTASSEMBLY
//////////////////////////////////////////////////////////////////////////////////////////////////
}//eoc