Skip to content

Commit f999b00

Browse files
committed
Code cleanup.
Fixing the renaming for already collected cases.
1 parent 5b8a53b commit f999b00

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU
180180
// Act
181181
var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1,
182182
BackendConfigurationPnDbContext,
183-
TimePlanningPnDbContext, logger);
183+
TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext);
184184

185185
// Assert
186186
var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync();
@@ -273,7 +273,7 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU
273273
var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core,
274274
1,
275275
BackendConfigurationPnDbContext,
276-
TimePlanningPnDbContext, logger);
276+
TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext);
277277

278278
// Assert
279279
var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync();
@@ -367,7 +367,7 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU
367367
var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core,
368368
1,
369369
BackendConfigurationPnDbContext,
370-
TimePlanningPnDbContext, logger);
370+
TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext);
371371

372372
// Assert
373373
var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync();

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,6 @@ await core.EntityItemUpdate(entity.Id, entity.Name, entity.Description,
193193
{
194194
await WorkOrderHelper.RetractEform(assignmentsForDelete, true, core, userService.UserId, backendConfigurationPnDbContext).ConfigureAwait(false);
195195
await WorkOrderHelper.RetractEform(assignmentsForDelete, false, core, userService.UserId, backendConfigurationPnDbContext).ConfigureAwait(false);
196-
197-
// foreach (var propertyWorker in assignmentsForDelete)
198-
// {
199-
// var documentSites = await caseTemplatePnDbContext.DocumentSites.Where(x => x.PropertyId == propertyWorker.PropertyId
200-
// && x.SdkSiteId == propertyWorker.WorkerId).ToListAsync();
201-
// foreach (var documentSite in documentSites)
202-
// {
203-
// if (documentSite.SdkCaseId != 0)
204-
// {
205-
// await core.CaseDelete(documentSite.SdkCaseId);
206-
// }
207-
// }
208-
// }
209-
210196
}
211197

212198
foreach (var documentId in documentIds)
@@ -267,7 +253,10 @@ await WorkOrderHelper.WorkorderFlowDeployEform(propertyWorkers, core, userServic
267253

268254
public static async Task<OperationResult> UpdateDeviceUser(DeviceUserModel deviceUserModel, Core core,
269255
int userId,
270-
BackendConfigurationPnDbContext backendConfigurationPnDbContext, TimePlanningPnDbContext timePlanningDbContext, ILogger logger)
256+
BackendConfigurationPnDbContext backendConfigurationPnDbContext,
257+
TimePlanningPnDbContext timePlanningDbContext,
258+
ILogger logger,
259+
ItemsPlanningPnDbContext itemsPlanningPnDbContext)
271260
{
272261
deviceUserModel.UserFirstName = deviceUserModel.UserFirstName.Trim();
273262
deviceUserModel.UserLastName = deviceUserModel.UserLastName.Trim();
@@ -367,6 +356,31 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti
367356
}
368357
}
369358
}
359+
360+
// find all PlanningCases where the DoneByUserId is the same as the worker.Id and update the DoneByUserName to the new name
361+
var planningCases = await itemsPlanningPnDbContext.PlanningCases
362+
.Where(x => x.DoneByUserId == worker.Id)
363+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
364+
.Where(x => x.Status == 100)
365+
.ToListAsync().ConfigureAwait(false);
366+
foreach (var planningCase in planningCases)
367+
{
368+
planningCase.DoneByUserName = fullName;
369+
await planningCase.Update(itemsPlanningPnDbContext).ConfigureAwait(false);
370+
}
371+
372+
// find all PlanningCaseSites where the DoneByUserId is the same as the SiteId and update the DoneByUserName to the new name
373+
var planningCaseSites = await itemsPlanningPnDbContext.PlanningCaseSites
374+
.Where(x => x.DoneByUserId == worker.Id)
375+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
376+
.Where(x => x.Status == 100)
377+
.ToListAsync().ConfigureAwait(false);
378+
foreach (var planningCaseSite in planningCaseSites)
379+
{
380+
planningCaseSite.DoneByUserName = fullName;
381+
await planningCaseSite.Update(itemsPlanningPnDbContext).ConfigureAwait(false);
382+
}
383+
370384
//var siteId = await sdkDbContext.Sites.Where(x => x.MicrotingUid == siteDto.SiteId).Select(x => x.Id).FirstAsync();
371385
if (deviceUserModel.TimeRegistrationEnabled == false && timePlanningDbContext.AssignedSites.Any(x => x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed))
372386
{
@@ -413,6 +427,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti
413427
}
414428
}
415429
}
430+
416431
return isUpdated
417432
? new OperationResult(true, "DeviceUserUpdatedSuccessfully")
418433
: new OperationResult(false,

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ public async Task<OperationResult> UpdateDeviceUser(DeviceUserModel deviceUserMo
527527
var core = await coreHelper.GetCore().ConfigureAwait(false);
528528
var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(deviceUserModel, core,
529529
userService.UserId, backendConfigurationPnDbContext,
530-
timePlanningDbContext, logger);
530+
timePlanningDbContext, logger, itemsPlanningPnDbContext);
531531

532532
return new OperationResult(result.Success, backendConfigurationLocalizationService.GetString(result.Message));
533533
}

0 commit comments

Comments
 (0)