This commit is contained in:
2020-05-07 19:47:45 +00:00
parent 6b905baf9a
commit ef7d2d2ba2
2 changed files with 40 additions and 114 deletions

View File

@@ -61,30 +61,22 @@ namespace AyaNova.Biz
//CREATE //CREATE
//Called from route and also seeder //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) if (HasErrors)
return null; return null;
else else
{ {
//do stuff with widget newObject.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
Widget outObj = inObj; newObject.Tags = TagUtil.NormalizeTags(newObject.Tags);
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
//Test get serial id visible id number from generator await ct.Widget.AddAsync(newObject);
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext(); await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags); await SearchIndexAsync(newObject, true);
outObj.CustomFields = JsonUtil.CompactJson(outObj.CustomFields); await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
//Save to db return newObject;
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;
} }
} }

View File

@@ -40,14 +40,9 @@ namespace AyaNova.Biz
return await ct.WorkOrder.AnyAsync(e => e.Id == id); return await ct.WorkOrder.AnyAsync(e => e.Id == id);
} }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE //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) internal async Task<WorkOrder> CreateAsync(WorkOrder newObject)
{ {
await ValidateAsync(newObject, null); await ValidateAsync(newObject, null);
@@ -55,102 +50,41 @@ namespace AyaNova.Biz
return null; return null;
else else
{ {
//do stuff with widget newObject.Serial = ServerBootConfig.WORKORDER_SERIAL.GetNext();
WorkOrder outObj = newObject; newObject.Tags = TagUtil.NormalizeTags(newObject.Tags);
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
//Test get serial id visible id number from generator await ct.WorkOrder.AddAsync(newObject);
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);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
//Handle child and associated items: await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); await SearchIndexAsync(newObject, true);
await SearchIndexAsync(outObj, true); await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null); return newObject;
return outObj;
} }
} }
// //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 //DUPLICATE
// //
internal async Task<WorkOrder> DuplicateAsync(long id) internal async Task<WorkOrder> DuplicateAsync(long id)
{ {
throw new System.NotImplementedException("STUB: WORKORDER DUPLICATE"); WorkOrder dbObject = await ct.WorkOrder.FirstOrDefaultAsync(m => m.Id == id);
// WorkOrder outObj = new WorkOrder(); if (dbObject == null)
// CopyObject.Copy(dbObj, outObj, "Wiki"); {
// // outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255); AddError(ApiErrorCode.NOT_FOUND, "id");
// //generate unique name return null;
// string newUniqueName = string.Empty; }
// bool NotUnique = true; WorkOrder newObject = new WorkOrder();
// long l = 1; CopyObject.Copy(dbObject, newObject, "Wiki");
// do newObject.Serial = ServerBootConfig.WORKORDER_SERIAL.GetNext();
// { newObject.Id = 0;
// newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255); newObject.ConcurrencyToken = 0;
// NotUnique = await ct.WorkOrder.AnyAsync(m => m.Name == newUniqueName); await ct.WorkOrder.AddAsync(newObject);
// } while (NotUnique); await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
// outObj.Name = newUniqueName; await SearchIndexAsync(newObject, true);
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
return newObject;
// 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;
} }
@@ -188,7 +122,7 @@ WARNING: Since version 3.0.0, each Include will cause an additional JOIN to be a
} }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE //UPDATE
// //