This commit is contained in:
57
server/AyaNova/PickList/PartAssemblyPickList.cs
Normal file
57
server/AyaNova/PickList/PartAssemblyPickList.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Biz;
|
||||
namespace AyaNova.PickList
|
||||
{
|
||||
internal class PartAssemblyPickList : AyaPickList
|
||||
{
|
||||
public PartAssemblyPickList()
|
||||
{
|
||||
|
||||
DefaultListObjectType = AyaType.PartAssembly;
|
||||
SQLFrom = "from apartassembly";
|
||||
AllowedRoles = BizRoles.GetRoleSet(DefaultListObjectType).Select;
|
||||
dynamic dTemplate = new JArray();
|
||||
dynamic cm = null;
|
||||
|
||||
cm = new JObject();
|
||||
cm.fld = "partassemblyname";
|
||||
dTemplate.Add(cm);
|
||||
|
||||
cm = new JObject();
|
||||
cm.fld = "partassemblytags";
|
||||
dTemplate.Add(cm);
|
||||
|
||||
base.DefaultTemplate = dTemplate.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
//NOTE: Due to the join, all the sql id and name fields that can conflict with the joined table need to be specified completely
|
||||
ColumnDefinitions = new List<AyaPickListFieldDefinition>();
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "Active",
|
||||
FieldKey = "partassemblyactive",
|
||||
ColumnDataType = UiFieldDataType.Bool,
|
||||
SqlValueColumnName = "apartassembly.active",
|
||||
IsActiveColumn = true
|
||||
});
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "Name",
|
||||
FieldKey = "partassemblyname",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlIdColumnName = "apartassembly.id",
|
||||
SqlValueColumnName = "apartassembly.name",
|
||||
IsRowId = true
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "Tags",
|
||||
FieldKey = "partassemblytags",
|
||||
ColumnDataType = UiFieldDataType.Tags,
|
||||
SqlValueColumnName = "apartassembly.tags"
|
||||
});
|
||||
|
||||
}
|
||||
}//eoc
|
||||
}//eons
|
||||
150
server/AyaNova/PickList/PartPickList.cs
Normal file
150
server/AyaNova/PickList/PartPickList.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Biz;
|
||||
namespace AyaNova.PickList
|
||||
{
|
||||
internal class PartPickList : AyaPickList
|
||||
{
|
||||
public PartPickList()
|
||||
{
|
||||
|
||||
DefaultListObjectType = AyaType.Part;
|
||||
SQLFrom = "from apart "
|
||||
+ "left join avendor as amanufacturer on (apart.manufacturerid = amanufacturer.id) "
|
||||
+ "left join avendor as awholesaler on (apart.wholesalerid = awholesaler.id) "
|
||||
+ "left join avendor as aalternativewholesaler on (apart.wholesalerid = aalternativewholesaler.id) ";
|
||||
AllowedRoles = BizRoles.GetRoleSet(DefaultListObjectType).Select;
|
||||
dynamic dTemplate = new JArray();
|
||||
dynamic cm = null;
|
||||
|
||||
cm = new JObject();
|
||||
cm.fld = "PartPartNumber";
|
||||
dTemplate.Add(cm);
|
||||
|
||||
cm = new JObject();
|
||||
cm.fld = "PartName";
|
||||
dTemplate.Add(cm);
|
||||
|
||||
cm = new JObject();
|
||||
cm.fld = "PartManufacturerID";
|
||||
dTemplate.Add(cm);
|
||||
|
||||
cm = new JObject();
|
||||
cm.fld = "parttags";
|
||||
dTemplate.Add(cm);
|
||||
|
||||
base.DefaultTemplate = dTemplate.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
//NOTE: Due to the join, all the sql id and name fields that can conflict with the joined table need to be specified completely
|
||||
ColumnDefinitions = new List<AyaPickListFieldDefinition>();
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "Active",
|
||||
FieldKey = "partactive",
|
||||
ColumnDataType = UiFieldDataType.Bool,
|
||||
SqlValueColumnName = "apart.active",
|
||||
IsActiveColumn = true
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "PartPartNumber",
|
||||
FieldKey = "PartPartNumber",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlIdColumnName = "apart.id",
|
||||
SqlValueColumnName = "apart.partnumber",
|
||||
IsRowId = true
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "PartName",
|
||||
FieldKey = "PartName",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlValueColumnName = "apart.name"
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "PartManufacturerNumber",
|
||||
FieldKey = "PartManufacturerNumber",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlValueColumnName = "apart.manufacturernumber"
|
||||
});
|
||||
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "PartWholesalerNumber",
|
||||
FieldKey = "PartWholesalerNumber",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlValueColumnName = "apart.wholesalernumber"
|
||||
});
|
||||
|
||||
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "PartAlternativeWholesalerNumber",
|
||||
FieldKey = "PartAlternativeWholesalerNumber",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlValueColumnName = "apart.alternativewholesalernumber"
|
||||
});
|
||||
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "UnitOfMeasure",
|
||||
FieldKey = "UnitOfMeasure",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlValueColumnName = "apart.unitofmeasure"
|
||||
});
|
||||
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "PartUPC",
|
||||
FieldKey = "PartUPC",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlValueColumnName = "apart.upc"
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
FieldKey = "PartManufacturerID",
|
||||
TKey = "PartManufacturerID",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlIdColumnName = "amanufacturer.id",
|
||||
SqlValueColumnName = "amanufacturer.name"
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
FieldKey = "PartWholesalerID",
|
||||
TKey = "PartWholesalerID",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlIdColumnName = "awholesaler.id",
|
||||
SqlValueColumnName = "awholesaler.name"
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
FieldKey = "PartAlternativeWholesalerID",
|
||||
TKey = "PartAlternativeWholesalerID",
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlIdColumnName = "aalternativewholesaler.id",
|
||||
SqlValueColumnName = "aalternativewholesaler.name"
|
||||
});
|
||||
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "Tags",
|
||||
FieldKey = "parttags",
|
||||
ColumnDataType = UiFieldDataType.Tags,
|
||||
SqlValueColumnName = "apart.tags"
|
||||
});
|
||||
|
||||
}
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user