Stubbing out workorder
This commit is contained in:
@@ -10,6 +10,8 @@ namespace AyaNova.Biz
|
||||
|
||||
internal class WorkOrderBiz : BizObject, ISearchAbleObject
|
||||
{
|
||||
//Feature specific roles
|
||||
internal static AuthorizationRoles RolesAllowedToChangeSerial = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.AccountingFull;
|
||||
|
||||
internal WorkOrderBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
@@ -63,7 +65,14 @@ namespace AyaNova.Biz
|
||||
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 && CurrentUserRoles.HasFlag(RolesAllowedToChangeSerial))
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_AUTHORIZED, "Serial");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// await ValidateAsync(inObj, null);
|
||||
// if (HasErrors)
|
||||
@@ -73,18 +82,18 @@ namespace AyaNova.Biz
|
||||
//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);
|
||||
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, o.Tags, null);
|
||||
|
||||
return o;
|
||||
//}
|
||||
@@ -135,34 +144,40 @@ namespace AyaNova.Biz
|
||||
//
|
||||
|
||||
//put
|
||||
internal async Task<bool> PutAsync(WorkOrder dbObj, WorkOrder inObj)
|
||||
internal async Task<bool> PutAsync(WorkOrder dbObj, WorkOrder putObj)
|
||||
{
|
||||
throw new System.NotImplementedException("STUB: WORKORDER PUT");
|
||||
//make a snapshot of the original for validation but update the original to preserve workflow
|
||||
// WorkOrder SnapshotOfOriginalDBObj = new WorkOrder();
|
||||
// CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
||||
|
||||
// //Replace the db object with the PUT object
|
||||
// CopyObject.Copy(inObj, dbObj, "Id");
|
||||
// make a snapshot of the original for validation but update the original to preserve workflow
|
||||
WorkOrder SnapshotOfOriginalDBObj = new WorkOrder();
|
||||
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
||||
|
||||
// dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
||||
// dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
||||
//Replace the db object with the PUT object
|
||||
CopyObject.Copy(putObj, dbObj, "Id,Serial");
|
||||
|
||||
// //Set "original" value of concurrency token to input token
|
||||
// //this will allow EF to check it out
|
||||
// ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
||||
//if user has rights then change it, otherwise just ignore it and do the rest
|
||||
if (SnapshotOfOriginalDBObj.Serial != putObj.Serial && CurrentUserRoles.HasFlag(RolesAllowedToChangeSerial))
|
||||
{
|
||||
dbObj.Serial = putObj.Serial;
|
||||
}
|
||||
|
||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
||||
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
||||
|
||||
//Set "original" value of concurrency token to input token
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = putObj.ConcurrencyToken;
|
||||
|
||||
|
||||
// await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||
// if (HasErrors)
|
||||
// return false;
|
||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
// //Log event and save context
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
// await SearchIndexAsync(dbObj, false);
|
||||
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
//Log event and save context
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
await SearchIndexAsync(dbObj, false);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
|
||||
// return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user