Skip to content

Commit e08982c

Browse files
committed
More code cleanup.
1 parent 3b5ae7c commit e08982c

File tree

1 file changed

+5
-71
lines changed

1 file changed

+5
-71
lines changed

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

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -374,85 +374,19 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti
374374

375375
foreach (var assignmentForDelete in assignmentForDeletes)
376376
{
377-
await assignmentForDelete.Delete(timePlanningDbContext).ConfigureAwait(false);
378-
if (assignmentForDelete.CaseMicrotingUid != null)
379-
{
380-
await core.CaseDelete((int) assignmentForDelete.CaseMicrotingUid).ConfigureAwait(false);
381-
}
382-
}
383-
var planRegistrations = await timePlanningDbContext.PlanRegistrations.Where(x => x.SdkSitId == siteDto.SiteId).ToListAsync().ConfigureAwait(false);
384-
385-
foreach (var planRegistration in planRegistrations)
386-
{
387-
try
388-
{
389-
if (planRegistration.StatusCaseId != 0)
390-
{
391-
await core.CaseDelete(planRegistration.StatusCaseId).ConfigureAwait(false);
392-
}
393-
}
394-
catch (Exception e)
395-
{
396-
Console.WriteLine(e);
397-
//throw;
398-
}
377+
assignmentForDelete.Resigned = true;
378+
assignmentForDelete.ResignedAtDate = DateTime.UtcNow;
379+
await assignmentForDelete.Update(timePlanningDbContext).ConfigureAwait(false);
399380
}
400381
}
401382
else
402383
{
403384
if (deviceUserModel.TimeRegistrationEnabled == true)
404385
{
405-
var registrationDevices = await timePlanningDbContext.RegistrationDevices
406-
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
407-
.ToListAsync().ConfigureAwait(false);
408-
409-
if (registrationDevices.Any())
410-
{
411-
var assignmentForDeletes = await timePlanningDbContext.AssignedSites.Where(x =>
412-
x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false);
413-
414-
foreach (var assignmentForDelete in assignmentForDeletes)
415-
{
416-
//await assignmentForDelete.Delete(timePlanningDbContext).ConfigureAwait(false);
417-
if (assignmentForDelete.CaseMicrotingUid != null)
418-
{
419-
await core.CaseDelete((int) assignmentForDelete.CaseMicrotingUid).ConfigureAwait(false);
420-
}
421-
}
422-
423-
var planRegistrations = await timePlanningDbContext.PlanRegistrations.Where(x => x.SdkSitId == siteDto.SiteId).ToListAsync().ConfigureAwait(false);
424-
425-
foreach (var planRegistration in planRegistrations)
426-
{
427-
if (planRegistration.StatusCaseId != 0)
428-
{
429-
await core.CaseDelete(planRegistration.StatusCaseId).ConfigureAwait(false);
430-
}
431-
}
432-
433-
var assignments1 = await timePlanningDbContext.AssignedSites.Where(x =>
434-
x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false);
435-
436-
if (assignments1.Any())
437-
{
438-
return new OperationDataResult<int>(true, siteDto.SiteId);
439-
}
440-
441-
var assignmentSite = new AssignedSite
442-
{
443-
SiteId = siteDto.SiteId,
444-
CreatedByUserId = userId,
445-
UpdatedByUserId = userId
446-
};
447-
await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false);
448-
await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger);
449-
return new OperationDataResult<int>(true, siteDto.SiteId);
450-
}
451-
452386
var assignments = await timePlanningDbContext.AssignedSites.Where(x =>
453387
x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false);
454388

455-
if (assignments.Any())
389+
if (assignments.Count != 0)
456390
{
457391
await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger);
458392
return new OperationDataResult<int>(true, siteDto.SiteId);
@@ -467,7 +401,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti
467401
UpdatedByUserId = userId
468402
};
469403
await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false);
470-
404+
await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger);
471405
return new OperationDataResult<int>(true, siteDto.SiteId);
472406
}
473407
catch (Exception e)

0 commit comments

Comments
 (0)