This commit is contained in:
162
server/AyaNova/DataList/UnitModelDataList.cs
Normal file
162
server/AyaNova/DataList/UnitModelDataList.cs
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using AyaNova.Biz;
|
||||||
|
namespace AyaNova.DataList
|
||||||
|
{
|
||||||
|
internal class UnitModelDataList : AyaDataList
|
||||||
|
{
|
||||||
|
public UnitModelDataList()
|
||||||
|
{
|
||||||
|
DefaultListObjectType = AyaType.UnitModel;
|
||||||
|
SQLFrom = "from aunitmodel left outer join avendor on (aunitmodel.vendorid=avendor.id)";
|
||||||
|
var RoleSet = BizRoles.GetRoleSet(DefaultListObjectType);
|
||||||
|
AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
|
||||||
|
|
||||||
|
//######## DEFAULT VIEW WHEN NO VIEW CHOSEN ############
|
||||||
|
//Default ListView
|
||||||
|
dynamic dlistView = new JArray();
|
||||||
|
|
||||||
|
dynamic cm = new JObject();
|
||||||
|
cm.fld = "UnitModelModelNumber";
|
||||||
|
cm.sort = "+";
|
||||||
|
dlistView.Add(cm);
|
||||||
|
|
||||||
|
cm = new JObject();
|
||||||
|
cm.fld = "Name";
|
||||||
|
dlistView.Add(cm);
|
||||||
|
|
||||||
|
cm = new JObject();
|
||||||
|
cm.fld = "UnitModelVendorID";
|
||||||
|
dlistView.Add(cm);
|
||||||
|
|
||||||
|
cm = new JObject();
|
||||||
|
cm.fld = "Active";
|
||||||
|
dlistView.Add(cm);
|
||||||
|
|
||||||
|
DefaultListView = dlistView.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
|
||||||
|
FieldDefinitions = new List<AyaDataListFieldDefinition>();
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelModelNumber",
|
||||||
|
FieldKey = "UnitModelModelNumber",
|
||||||
|
AyaObjectType = (int)AyaType.UnitModel,
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||||
|
SqlIdColumnName = "aunitmodel.id",
|
||||||
|
SqlValueColumnName = "aunitmodel.number",
|
||||||
|
IsRowId = true
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "Name",
|
||||||
|
FieldKey = "Name",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||||
|
SqlValueColumnName = "aunitmodel.name"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "Active",
|
||||||
|
FieldKey = "Active",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
||||||
|
SqlValueColumnName = "aunitmodel.active"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "Tags",
|
||||||
|
FieldKey = "unitmodeltags",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Tags,
|
||||||
|
SqlValueColumnName = "aunitmodel.tags"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
FieldKey = "UnitModelVendorID",
|
||||||
|
TKey = "UnitModelVendorID",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||||
|
AyaObjectType = (int)AyaType.Vendor,
|
||||||
|
SqlIdColumnName = "avendor.id",
|
||||||
|
SqlValueColumnName = "avendor.name"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelUPC",
|
||||||
|
FieldKey = "UnitModelUPC",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||||
|
SqlValueColumnName = "aunitmodel.upc"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelLifeTimeWarranty",
|
||||||
|
FieldKey = "UnitModelLifeTimeWarranty",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
||||||
|
SqlValueColumnName = "aunitmodel.lifetimewarranty"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelIntroducedDate",
|
||||||
|
FieldKey = "UnitModelIntroducedDate",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.DateTime,
|
||||||
|
SqlValueColumnName = "aunitmodel.introduceddate"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelDiscontinued",
|
||||||
|
FieldKey = "UnitModelDiscontinued",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
||||||
|
SqlValueColumnName = "aunitmodel.discontinued"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelDiscontinuedDate",
|
||||||
|
FieldKey = "UnitModelDiscontinuedDate",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.DateTime,
|
||||||
|
SqlValueColumnName = "aunitmodel.discontinueddate"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelWarrantyLength",
|
||||||
|
FieldKey = "UnitModelWarrantyLength",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Integer,
|
||||||
|
SqlValueColumnName = "aunitmodel.warrantylength"
|
||||||
|
});
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition
|
||||||
|
{
|
||||||
|
TKey = "UnitModelWarrantyTerms",
|
||||||
|
FieldKey = "UnitModelWarrantyTerms",
|
||||||
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||||
|
SqlValueColumnName = "aunitmodel.warrantyterms"
|
||||||
|
});
|
||||||
|
//-----------
|
||||||
|
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom1", FieldKey = "unitmodelcustom1", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom2", FieldKey = "unitmodelcustom2", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom3", FieldKey = "unitmodelcustom3", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom4", FieldKey = "unitmodelcustom4", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom5", FieldKey = "unitmodelcustom5", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom6", FieldKey = "unitmodelcustom6", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom7", FieldKey = "unitmodelcustom7", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom8", FieldKey = "unitmodelcustom8", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom9", FieldKey = "unitmodelcustom9", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom10", FieldKey = "unitmodelcustom10", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom11", FieldKey = "unitmodelcustom11", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom12", FieldKey = "unitmodelcustom12", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom13", FieldKey = "unitmodelcustom13", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom14", FieldKey = "unitmodelcustom14", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom15", FieldKey = "unitmodelcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "UnitModelCustom16", FieldKey = "unitmodelcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aunitmodel.customfields" });
|
||||||
|
}
|
||||||
|
}//eoc
|
||||||
|
}//eons
|
||||||
@@ -612,7 +612,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region TaxCode
|
#region TaxCode
|
||||||
{
|
{
|
||||||
|
|
||||||
List<AyaFormFieldDefinition> l = new List<AyaFormFieldDefinition>();
|
List<AyaFormFieldDefinition> l = new List<AyaFormFieldDefinition>();
|
||||||
@@ -648,13 +648,13 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ServiceBank
|
#region ServiceBank
|
||||||
{
|
{
|
||||||
|
|
||||||
List<AyaFormFieldDefinition> l = new List<AyaFormFieldDefinition>();
|
List<AyaFormFieldDefinition> l = new List<AyaFormFieldDefinition>();
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankDescription", FieldKey = "ServiceBankDescription", Hideable = false });
|
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankDescription", FieldKey = "ServiceBankDescription", Hideable = false });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankCurrency", FieldKey = "ServiceBankCurrency" });
|
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankCurrency", FieldKey = "ServiceBankCurrency" });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankHours", FieldKey = "ServiceBankHours"});
|
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankHours", FieldKey = "ServiceBankHours" });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankIncidents", FieldKey = "ServiceBankIncidents" });
|
l.Add(new AyaFormFieldDefinition { TKey = "ServiceBankIncidents", FieldKey = "ServiceBankIncidents" });
|
||||||
_ayaFormFields.Add(AyaType.ServiceBank.ToString(), l);
|
_ayaFormFields.Add(AyaType.ServiceBank.ToString(), l);
|
||||||
|
|
||||||
@@ -695,13 +695,23 @@ namespace AyaNova.Biz
|
|||||||
#region UnitModel
|
#region UnitModel
|
||||||
{
|
{
|
||||||
List<AyaFormFieldDefinition> l = new List<AyaFormFieldDefinition>();
|
List<AyaFormFieldDefinition> l = new List<AyaFormFieldDefinition>();
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "Name", FieldKey = "Name", Hideable = false });
|
l.Add(new AyaFormFieldDefinition { TKey = "Name", FieldKey = "Name"});
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelNotes", FieldKey = "Notes" });
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelNotes", FieldKey = "Notes" });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "Active", FieldKey = "Active", Hideable = false });
|
l.Add(new AyaFormFieldDefinition { TKey = "Active", FieldKey = "Active", Hideable = false });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "Tags", FieldKey = "Tags" });
|
l.Add(new AyaFormFieldDefinition { TKey = "Tags", FieldKey = "Tags" });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "Wiki", FieldKey = "Wiki" });
|
l.Add(new AyaFormFieldDefinition { TKey = "Wiki", FieldKey = "Wiki" });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "Attachments", FieldKey = "Attachments" });
|
l.Add(new AyaFormFieldDefinition { TKey = "Attachments", FieldKey = "Attachments" });
|
||||||
|
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelModelNumber", FieldKey = "UnitModelModelNumber", Hideable = false });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelVendorID", FieldKey = "UnitModelVendorID" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelUPC", FieldKey = "UnitModelUPC" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelLifeTimeWarranty", FieldKey = "UnitModelLifeTimeWarranty" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelIntroducedDate", FieldKey = "UnitModelIntroducedDate" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelDiscontinued", FieldKey = "UnitModelDiscontinued" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelDiscontinuedDate", FieldKey = "UnitModelDiscontinuedDate" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelWarrantyLength", FieldKey = "UnitModelWarrantyLength" });
|
||||||
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelWarrantyTerms", FieldKey = "UnitModelWarrantyTerms" });
|
||||||
|
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelCustom1", FieldKey = "UnitModelCustom1", IsCustomField = true });
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelCustom1", FieldKey = "UnitModelCustom1", IsCustomField = true });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelCustom2", FieldKey = "UnitModelCustom2", IsCustomField = true });
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelCustom2", FieldKey = "UnitModelCustom2", IsCustomField = true });
|
||||||
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelCustom3", FieldKey = "UnitModelCustom3", IsCustomField = true });
|
l.Add(new AyaFormFieldDefinition { TKey = "UnitModelCustom3", FieldKey = "UnitModelCustom3", IsCustomField = true });
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Linq;
|
||||||
using AyaNova.Util;
|
using AyaNova.Util;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
internal class UnitModelBiz : BizObject, ISearchAbleObject, INotifiableObject
|
internal class UnitModelBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, IImportAbleObject, INotifiableObject
|
||||||
{
|
{
|
||||||
internal UnitModelBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
internal UnitModelBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
@@ -202,6 +207,9 @@ namespace AyaNova.Biz
|
|||||||
if (obj != null)
|
if (obj != null)
|
||||||
searchParams.AddText(obj.Notes)
|
searchParams.AddText(obj.Notes)
|
||||||
.AddText(obj.Name)
|
.AddText(obj.Name)
|
||||||
|
.AddText(obj.Number)
|
||||||
|
.AddText(obj.UPC)
|
||||||
|
.AddText(obj.WarrantyTerms)
|
||||||
.AddText(obj.Wiki)
|
.AddText(obj.Wiki)
|
||||||
.AddText(obj.Tags)
|
.AddText(obj.Tags)
|
||||||
.AddCustomFields(obj.CustomFields);
|
.AddCustomFields(obj.CustomFields);
|
||||||
@@ -218,21 +226,12 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
bool isNew = currentObj == null;
|
bool isNew = currentObj == null;
|
||||||
|
|
||||||
//Name required
|
//## Name is not required nor required to be unique for a UnitModel so no validation for that here
|
||||||
|
//number is required but also not necessarily unique as two manufacturers could have the same model number for different products
|
||||||
|
|
||||||
|
//Number required
|
||||||
if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Number");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//If name is otherwise OK, check that name is unique
|
|
||||||
if (!PropertyHasErrors("Name"))
|
|
||||||
{
|
|
||||||
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
|
||||||
if (await ct.UnitModel.AnyAsync(z => z.Name == proposedObj.Name && z.Id != proposedObj.Id))
|
|
||||||
{
|
|
||||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Any form customizations to validate?
|
//Any form customizations to validate?
|
||||||
@@ -257,6 +256,159 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//REPORTING
|
||||||
|
//
|
||||||
|
public async Task<JArray> GetReportData(long[] idList)
|
||||||
|
{
|
||||||
|
JArray ReportData = new JArray();
|
||||||
|
while (idList.Any())
|
||||||
|
{
|
||||||
|
var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE);
|
||||||
|
idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
|
||||||
|
//query for this batch, comes back in db natural order unfortunately
|
||||||
|
var batchResults = await ct.UnitModel.Where(z => batch.Contains(z.Id)).ToArrayAsync();
|
||||||
|
//order the results back into original
|
||||||
|
var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
||||||
|
foreach (UnitModel w in orderedList)
|
||||||
|
{
|
||||||
|
var jo = JObject.FromObject(w);
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"]))
|
||||||
|
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
||||||
|
ReportData.Add(jo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ReportData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// IMPORT EXPORT
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<JArray> GetExportData(long[] idList)
|
||||||
|
{
|
||||||
|
//for now just re-use the report data code
|
||||||
|
//this may turn out to be the pattern for most biz object types but keeping it seperate allows for custom usage from time to time
|
||||||
|
return await GetReportData(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<List<string>> ImportData(JArray ja)
|
||||||
|
{
|
||||||
|
List<string> ImportResult = new List<string>();
|
||||||
|
string ImportTag = $"imported-{FileUtil.GetSafeDateFileName()}";
|
||||||
|
|
||||||
|
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
||||||
|
foreach (JObject j in ja)
|
||||||
|
{
|
||||||
|
var w = j.ToObject<UnitModel>(jsset);
|
||||||
|
if (j["CustomFields"] != null)
|
||||||
|
w.CustomFields = j["CustomFields"].ToString();
|
||||||
|
w.Tags.Add(ImportTag);//so user can find them all and revert later if necessary
|
||||||
|
var res = await CreateAsync(w);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"* {w.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"{w.Name} - ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ImportResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//JOB / OPERATIONS
|
||||||
|
//
|
||||||
|
public async Task HandleJobAsync(OpsJob job)
|
||||||
|
{
|
||||||
|
//Hand off the particular job to the corresponding processing code
|
||||||
|
//NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so
|
||||||
|
//basically any error condition during job processing should throw up an exception if it can't be handled
|
||||||
|
switch (job.JobType)
|
||||||
|
{
|
||||||
|
case JobType.BatchCoreObjectOperation:
|
||||||
|
await ProcessBatchJobAsync(job);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new System.ArgumentOutOfRangeException($"UnitModelBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private async Task ProcessBatchJobAsync(OpsJob job)
|
||||||
|
{
|
||||||
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running);
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, $"LT:StartJob {job.SubType}");
|
||||||
|
List<long> idList = new List<long>();
|
||||||
|
long FailedObjectCount = 0;
|
||||||
|
JObject jobData = JObject.Parse(job.JobInfo);
|
||||||
|
if (jobData.ContainsKey("idList"))
|
||||||
|
idList = ((JArray)jobData["idList"]).ToObject<List<long>>();
|
||||||
|
else
|
||||||
|
idList = await ct.UnitModel.Select(z => z.Id).ToListAsync();
|
||||||
|
bool SaveIt = false;
|
||||||
|
foreach (long id in idList)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SaveIt = false;
|
||||||
|
ClearErrors();
|
||||||
|
UnitModel o = null;
|
||||||
|
//save a fetch if it's a delete
|
||||||
|
if (job.SubType != JobSubType.Delete)
|
||||||
|
o = await GetAsync(id, false);
|
||||||
|
switch (job.SubType)
|
||||||
|
{
|
||||||
|
case JobSubType.TagAddAny:
|
||||||
|
case JobSubType.TagAdd:
|
||||||
|
case JobSubType.TagRemoveAny:
|
||||||
|
case JobSubType.TagRemove:
|
||||||
|
case JobSubType.TagReplaceAny:
|
||||||
|
case JobSubType.TagReplace:
|
||||||
|
SaveIt = TagBiz.ProcessBatchTagOperation(o.Tags, (string)jobData["tag"], jobData.ContainsKey("toTag") ? (string)jobData["toTag"] : null, job.SubType);
|
||||||
|
break;
|
||||||
|
case JobSubType.Delete:
|
||||||
|
if (!await DeleteAsync(id))
|
||||||
|
{
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, $"LT:Errors {GetErrorsAsString()} id {id}");
|
||||||
|
FailedObjectCount++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new System.ArgumentOutOfRangeException($"ProcessBatchJobAsync -> Invalid job Subtype{job.SubType}");
|
||||||
|
}
|
||||||
|
if (SaveIt)
|
||||||
|
{
|
||||||
|
o = await PutAsync(o);
|
||||||
|
if (o == null)
|
||||||
|
{
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, $"LT:Errors {GetErrorsAsString()} id {id}");
|
||||||
|
FailedObjectCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, $"LT:Errors id({id})");
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, ExceptionUtil.ExtractAllExceptionMessages(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, $"LT:BatchJob {job.SubType} {idList.Count}{(FailedObjectCount > 0 ? " - LT:Failed " + FailedObjectCount : "")}");
|
||||||
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user