This commit is contained in:
2020-01-20 23:26:31 +00:00
parent a6156d09aa
commit deb5141feb

View File

@@ -416,6 +416,26 @@ namespace AyaNova.Biz
var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY); var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY);
//TODO: PUt this in the template biz class ultimately and modify sqlselectbuilder to use it
//PARSE THE TEMPLATE INTO A STRING ARRAY
//SO WE KNOW WHICH FIELDS TO RETURN FROM QUERY
var jtemplate = JObject.Parse(MOCK_WIDGET_USER_EMAIL_DISPLAY_TEMPLATE_JSON);
//convert to strings array (https://stackoverflow.com/a/33836599/8939)
string[] templateFieldList;
if (listOptions.Mini)
{
templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
}
else
{
templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
}
//manually add the default field
templateFieldList.Prepend("df");
//BUILD THE QUERY //BUILD THE QUERY
/* /*
Select awidget.id, awidget.name, auser.name, auser.id, auseroptions.emailaddress Select awidget.id, awidget.name, auser.name, auser.id, auseroptions.emailaddress
@@ -468,10 +488,10 @@ namespace AyaNova.Biz
//RETURN OBJECTS //RETURN OBJECTS
int returnRowCount = AyaObjectFields.Count(); int returnRowColumnCount = templateFieldList.Count();//AyaObjectFields.Count();
List<List<AyaFieldData>> rows = new List<List<AyaFieldData>>(); List<List<AyaFieldData>> rows = new List<List<AyaFieldData>>();
long totalRecordCount = 0; long totalRecordCount = 0;
//RUN THE QUERY //RUN THE QUERY
using (var command = ct.Database.GetDbConnection().CreateCommand()) using (var command = ct.Database.GetDbConnection().CreateCommand())
@@ -485,11 +505,11 @@ namespace AyaNova.Biz
{ {
while (dr.Read()) while (dr.Read())
{ {
List<AyaFieldData> row = new List<AyaFieldData>(returnRowCount); List<AyaFieldData> row = new List<AyaFieldData>(returnRowColumnCount);
//GetOrdinal is flakey in npgsql so just going by field definition and ordinal numerically //GetOrdinal is flakey in npgsql so just going by field definition and ordinal numerically
int nCurrentColumnPointer=0; int nCurrentColumnPointer = 0;
//flag to handle first column which has no display value, just an id instead //flag to handle first column which has no display value, just an id instead
bool isFirstDFColumn=true; bool isFirstDFColumn = true;
//Iterate object fields, build return row list as required //Iterate object fields, build return row list as required
//WAIT A SECOND, this is not correct, we are meant to return the template fields only, not all the fields in the objectfieldefinition which is a superset of the template //WAIT A SECOND, this is not correct, we are meant to return the template fields only, not all the fields in the objectfieldefinition which is a superset of the template
@@ -498,11 +518,14 @@ namespace AyaNova.Biz
//See the select builder, IIRC it already does select only the fields required, it's probably just this block of code below that needs adapting //See the select builder, IIRC it already does select only the fields required, it's probably just this block of code below that needs adapting
//INSERT INTO THE RETURN ROWS LIST //INSERT INTO THE RETURN ROWS LIST
foreach (AyaObjectFieldDefinition f in AyaObjectFields) foreach (string TemplateField in templateFieldList)
{ {
//get the AyaObjectFieldDefinition
AyaObjectFieldDefinition f = AyaObjectFields.FirstOrDefault(x => x.FieldKey == TemplateField);
AyaFieldData AyaField = new AyaFieldData(); AyaFieldData AyaField = new AyaFieldData();
AyaField.v = dr.GetValue(nCurrentColumnPointer); AyaField.v = dr.GetValue(nCurrentColumnPointer);
nCurrentColumnPointer++; nCurrentColumnPointer++;
if (!isFirstDFColumn && f.SqlIdColumnName != null)//skip over df column id, it's not there if (!isFirstDFColumn && f.SqlIdColumnName != null)//skip over df column id, it's not there
{ {
@@ -510,7 +533,7 @@ namespace AyaNova.Biz
nCurrentColumnPointer++; nCurrentColumnPointer++;
} }
isFirstDFColumn=false; isFirstDFColumn = false;
row.Add(AyaField); row.Add(AyaField);
} }
rows.Add(row); rows.Add(row);