This commit is contained in:
@@ -61,30 +61,22 @@ namespace AyaNova.Biz
|
||||
//CREATE
|
||||
|
||||
//Called from route and also seeder
|
||||
internal async Task<Widget> CreateAsync(Widget inObj)
|
||||
internal async Task<Widget> CreateAsync(Widget newObject)
|
||||
{
|
||||
await ValidateAsync(inObj, null);
|
||||
await ValidateAsync(newObject, null);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//do stuff with widget
|
||||
Widget outObj = inObj;
|
||||
|
||||
//Test get serial id visible id number from generator
|
||||
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
|
||||
|
||||
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
||||
outObj.CustomFields = JsonUtil.CompactJson(outObj.CustomFields);
|
||||
//Save to db
|
||||
await ct.Widget.AddAsync(outObj);
|
||||
await ct.SaveChangesAsync();
|
||||
//Handle child and associated items:
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(outObj, true);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
||||
|
||||
return outObj;
|
||||
{
|
||||
newObject.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
|
||||
newObject.Tags = TagUtil.NormalizeTags(newObject.Tags);
|
||||
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.Widget.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,14 +40,9 @@ namespace AyaNova.Biz
|
||||
return await ct.WorkOrder.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE
|
||||
|
||||
//TODO: Modify this to expect a workorder object like most POST routes for other objects
|
||||
//No need for this style of create empty and return
|
||||
|
||||
|
||||
//Called from route and also seeder
|
||||
//
|
||||
internal async Task<WorkOrder> CreateAsync(WorkOrder newObject)
|
||||
{
|
||||
await ValidateAsync(newObject, null);
|
||||
@@ -55,102 +50,41 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//do stuff with widget
|
||||
WorkOrder outObj = newObject;
|
||||
|
||||
//Test get serial id visible id number from generator
|
||||
outObj.Serial = ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||
|
||||
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
||||
outObj.CustomFields = JsonUtil.CompactJson(outObj.CustomFields);
|
||||
//Save to db
|
||||
await ct.WorkOrder.AddAsync(outObj);
|
||||
newObject.Serial = ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||
newObject.Tags = TagUtil.NormalizeTags(newObject.Tags);
|
||||
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrder.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
//Handle child and associated items:
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(outObj, true);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
||||
|
||||
return outObj;
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
|
||||
// //Called from route and also seeder
|
||||
// internal async Task<WorkOrder> CreateAsync(long? workorderTemplateId, long? customerId, uint? serial)
|
||||
// {
|
||||
// //Create and save to db a new workorder and return it
|
||||
// //NOTE: Serial can be specified or edited after the fact in a limited way by full role specfic only!! (service manager, bizadminfull, accounting maybe)
|
||||
|
||||
// if (serial != null && !Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
||||
// {
|
||||
// AddError(ApiErrorCode.NOT_AUTHORIZED, "Serial");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
// // await ValidateAsync(inObj, null);
|
||||
// // if (HasErrors)
|
||||
// // return null;
|
||||
// // else
|
||||
// // {
|
||||
// //do stuff with WorkOrder
|
||||
// WorkOrder o = new WorkOrder();
|
||||
// o.Serial = serial ?? ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||
|
||||
// //TODO: template
|
||||
// //TODO: CUSTOMER ID
|
||||
|
||||
|
||||
// //Save to db
|
||||
// await ct.WorkOrder.AddAsync(o);
|
||||
// await ct.SaveChangesAsync();
|
||||
// //Handle child and associated items:
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, o.Id, BizType, AyaEvent.Created), ct);
|
||||
// await SearchIndexAsync(o, true);
|
||||
// // await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, o.Tags, null);
|
||||
|
||||
// return o;
|
||||
// //}
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DUPLICATE
|
||||
//
|
||||
|
||||
internal async Task<WorkOrder> DuplicateAsync(long id)
|
||||
{
|
||||
throw new System.NotImplementedException("STUB: WORKORDER DUPLICATE");
|
||||
// WorkOrder outObj = new WorkOrder();
|
||||
// CopyObject.Copy(dbObj, outObj, "Wiki");
|
||||
// // outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255);
|
||||
// //generate unique name
|
||||
// string newUniqueName = string.Empty;
|
||||
// bool NotUnique = true;
|
||||
// long l = 1;
|
||||
// do
|
||||
// {
|
||||
// newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
||||
// NotUnique = await ct.WorkOrder.AnyAsync(m => m.Name == newUniqueName);
|
||||
// } while (NotUnique);
|
||||
|
||||
// outObj.Name = newUniqueName;
|
||||
|
||||
|
||||
// outObj.Id = 0;
|
||||
// outObj.ConcurrencyToken = 0;
|
||||
|
||||
// await ct.WorkOrder.AddAsync(outObj);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// //Handle child and associated items:
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
// await SearchIndexAsync(outObj, true);
|
||||
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
||||
// return outObj;
|
||||
|
||||
WorkOrder dbObject = await ct.WorkOrder.FirstOrDefaultAsync(m => m.Id == id);
|
||||
if (dbObject == null)
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||
return null;
|
||||
}
|
||||
WorkOrder newObject = new WorkOrder();
|
||||
CopyObject.Copy(dbObject, newObject, "Wiki");
|
||||
newObject.Serial = ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||
newObject.Id = 0;
|
||||
newObject.ConcurrencyToken = 0;
|
||||
await ct.WorkOrder.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +122,7 @@ WARNING: Since version 3.0.0, each Include will cause an additional JOIN to be a
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//UPDATE
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user