Skip to content

Commit 4bbeff0

Browse files
committed
Fixing resigned issue.
1 parent a79bdb1 commit 4bbeff0

File tree

2 files changed

+38
-128
lines changed

2 files changed

+38
-128
lines changed

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/EformBackendConfigurationPlugin.cs

Lines changed: 29 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ private static async void SeedEForms(IServiceCollection services)
202202

203203
var backendConfigurationPnDbContext = serviceProvider.GetRequiredService<BackendConfigurationPnDbContext>();
204204
var itemsPlanningContext = serviceProvider.GetRequiredService<ItemsPlanningPnDbContext>();
205+
var timePlanningPnDbContext = serviceProvider.GetRequiredService<TimePlanningPnDbContext>();
205206
// var caseTemplateContext = serviceProvider.GetRequiredService<CaseTemplatePnDbContext>();
206207
// seed eforms
207208
var assembly = Assembly.GetExecutingAssembly();
@@ -340,134 +341,7 @@ private static async void SeedEForms(IServiceCollection services)
340341
}
341342
}
342343

343-
// TODO remove this code when sure that the fields are fixed on all installations
344-
// var priorityFieldsToFix = await sdkDbContext.Fields.Where(x => x.OriginalId == "376935").ToListAsync();
345-
// foreach (var priorityFieldToFix in priorityFieldsToFix)
346-
// {
347-
// if (priorityFieldToFix.Mandatory == 0)
348-
// {
349-
// priorityFieldToFix.Mandatory = 1;
350-
// await priorityFieldToFix.Update(sdkDbContext);
351-
// SentrySdk.CaptureMessage("Field 376935 was fixed!");
352-
// }
353-
// }
354-
//
355-
// var fieldToFix = await sdkDbContext.Fields.OrderBy(x => x.Id).LastOrDefaultAsync(x => x.OriginalId == "375727");
356-
// if (fieldToFix is { Mandatory: 0 })
357-
// {
358-
// fieldToFix.Mandatory = 1;
359-
// await fieldToFix.Update(sdkDbContext);
360-
// SentrySdk.CaptureMessage("Field 375727 was fixed!");
361-
// var localizationService = serviceProvider.GetRequiredService<IBackendConfigurationLocalizationService>();
362-
//
363-
// // find all propertyworkers where TaskManagementEnabled is true and retract the eform and deploy it again. Do the same for all tasks assigned to the propertyworker
364-
// var propertiesWithWorkOrderEnabled = await backendConfigurationPnDbContext.Properties
365-
// .Where(x => x.WorkflowState != Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
366-
// .Where(x => x.WorkorderEnable == true)
367-
// .Include(property => property.PropertyWorkers)
368-
// .ToListAsync();
369-
//
370-
// var eformId = await sdkDbContext.CheckLists
371-
// .Where(x => x.WorkflowState != Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
372-
// .Where(x => x.OriginalId == "142663new2")
373-
// .Select(x => x.Id)
374-
// .FirstAsync().ConfigureAwait(false);
375-
// foreach (var property in propertiesWithWorkOrderEnabled)
376-
// {
377-
// Console.WriteLine($"Handling property {property.Name}");
378-
// var propertyWorkers = property.PropertyWorkers
379-
// .Where(x => x.TaskManagementEnabled == true)
380-
// .Where(x => x.WorkflowState !=
381-
// Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
382-
// .ToList();
383-
// await WorkOrderHelper
384-
// .RetractEform(propertyWorkers, true, core,null, backendConfigurationPnDbContext)
385-
// .ConfigureAwait(false);
386-
//
387-
// foreach (var propertyWorker in propertyWorkers)
388-
// {
389-
// var site = await sdkDbContext.Sites.SingleAsync(x => x.Id == propertyWorker.WorkerId).ConfigureAwait(false);
390-
// Console.WriteLine($"Handling property {property.Name} and propertyWorker {propertyWorker.WorkerId} with the site.name {site.Name}");
391-
// var language = await sdkDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId).ConfigureAwait(false);
392-
// var mainElement = await core.ReadeForm(eformId, language).ConfigureAwait(false);
393-
//
394-
// var deviceUsersGroup = await sdkDbContext.EntityGroups.FirstAsync(x => x.Id == property.EntitySelectListDeviceUsers)
395-
// .ConfigureAwait(false);
396-
//
397-
// var areasGroup = await sdkDbContext.EntityGroups.FirstAsync(x => x.Id == property.EntitySelectListAreas)
398-
// .ConfigureAwait(false);
399-
//
400-
// //if (localizationService != null)
401-
// //{
402-
// // get the localization service
403-
// Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(language.LanguageCode);
404-
// string description = "<strong>"+localizationService.GetString("Location") + "</strong>: " + property.Name;
405-
// string newTask = localizationService.GetString("NewTask");
406-
// //}
407-
//
408-
// mainElement.Repeated = 0;
409-
// mainElement.ElementList[0].QuickSyncEnabled = true;
410-
// mainElement.ElementList[0].Description.InderValue = description;
411-
// mainElement.ElementList[0].Label = newTask;
412-
// mainElement.Label = newTask;
413-
// mainElement.EnableQuickSync = true;
414-
// if (property.FolderIdForNewTasks != null)
415-
// {
416-
// mainElement.CheckListFolderName = await sdkDbContext.Folders
417-
// .Where(x => x.Id == property.FolderIdForNewTasks)
418-
// .Select(x => x.MicrotingUid.ToString())
419-
// .FirstOrDefaultAsync().ConfigureAwait(false);
420-
// }
421-
//
422-
// if (!string.IsNullOrEmpty(description))
423-
// {
424-
// ((DataElement)mainElement.ElementList[0]).DataItemList[0].Description.InderValue = description;
425-
// ((DataElement)mainElement.ElementList[0]).DataItemList[0].Label = " ";
426-
// }
427-
//
428-
// //if (areasGroupUid != null && deviceUsersGroupId != null)
429-
// //{
430-
// ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[2]).Source = int.Parse(areasGroup.MicrotingUid);
431-
// ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[6]).Source =
432-
// int.Parse(deviceUsersGroup.MicrotingUid);
433-
// //}
434-
// // else if (areasGroupUid == null && deviceUsersGroupId != null)
435-
// // {
436-
// // ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[4]).Source =
437-
// // (int)deviceUsersGroupId;
438-
// // }
439-
//
440-
// mainElement.EndDate = DateTime.Now.AddYears(10).ToUniversalTime();
441-
// mainElement.StartDate = DateTime.Now.ToUniversalTime();
442-
// var caseId = await core.CaseCreate(mainElement, "", (int)site.MicrotingUid, property.FolderIdForNewTasks).ConfigureAwait(false);
443-
// await new WorkorderCase
444-
// {
445-
// CaseId = (int)caseId,
446-
// PropertyWorkerId = propertyWorker.Id,
447-
// CaseStatusesEnum = CaseStatusesEnum.NewTask,
448-
// CreatedByUserId = 1,
449-
// UpdatedByUserId = 1,
450-
// }.Create(backendConfigurationPnDbContext).ConfigureAwait(false);
451-
// }
452-
// }
453-
// }
454-
//
455-
// fieldToFix = await sdkDbContext.Fields.OrderBy(x => x.Id).LastOrDefaultAsync(x => x.OriginalId == "375733");
456-
// if (fieldToFix is { Mandatory: 0 })
457-
// {
458-
// fieldToFix.Mandatory = 1;
459-
// await fieldToFix.Update(sdkDbContext);
460-
// SentrySdk.CaptureMessage("Field 375733 was fixed!");
461-
// }
462-
//
463-
// fieldToFix = await sdkDbContext.Fields.OrderBy(x => x.Id).LastOrDefaultAsync(x => x.OriginalId == "375734");
464-
// if (fieldToFix is { Mandatory: 0 })
465-
// {
466-
// fieldToFix.Mandatory = 1;
467-
// await fieldToFix.Update(sdkDbContext);
468-
// SentrySdk.CaptureMessage("Field 375734 was fixed!");
469-
// }
470-
344+
// seed "Exceeded tasks" folder translations
471345
var translations = new List<KeyValuePair<string, string>> {
472346
new("da", "00. Overskredne opgaver"),
473347
new("en-US", "00. Overdue tasks"),
@@ -703,6 +577,33 @@ await sdkDbContext.Folders
703577
brokenWorkorderCase.CaseStatusesEnum = CaseStatusesEnum.Awaiting;
704578
await brokenWorkorderCase.Update(backendConfigurationPnDbContext);
705579
}
580+
581+
var timeRegistrationAssignedSites = await timePlanningPnDbContext.AssignedSites
582+
.Where(x => x.WorkflowState !=
583+
Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
584+
.ToListAsync();
585+
foreach (var timeRegistrationAssignedSite in timeRegistrationAssignedSites)
586+
{
587+
var sdkWorker = await sdkDbContext.Sites
588+
.Join(sdkDbContext.SiteWorkers,
589+
site => site.Id,
590+
siteWorker => siteWorker.SiteId,
591+
(site, siteWorker) => new {site, siteWorker})
592+
.Join(sdkDbContext.Workers,
593+
combined => combined.siteWorker.WorkerId,
594+
worker => worker.Id,
595+
(combined, worker) => new {combined.site, combined.siteWorker, worker})
596+
.Where(x => x.site.MicrotingUid == timeRegistrationAssignedSite.SiteId)
597+
.Select(x => x.worker)
598+
.FirstOrDefaultAsync();
599+
if (sdkWorker != null)
600+
{
601+
var worker = await sdkDbContext.Workers.FirstAsync(x => x.Id == sdkWorker.Id).ConfigureAwait(false);
602+
worker.Resigned = timeRegistrationAssignedSite.Resigned;
603+
worker.ResignedAtDate = timeRegistrationAssignedSite.ResignedAtDate;
604+
await worker.Update(sdkDbContext).ConfigureAwait(false);
605+
}
606+
}
706607
}
707608

708609
public void ConfigureDbContext(IServiceCollection services, string connectionString)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti
380380
entityItemIncrementer++;
381381
}
382382
}
383+
384+
var assignment = await timePlanningDbContext.AssignedSites.FirstOrDefaultAsync(x =>
385+
x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ConfigureAwait(false);
386+
if (assignment != null)
387+
{
388+
assignment.Resigned = deviceUserModel.Resigned;
389+
assignment.ResignedAtDate = deviceUserModel.ResignedAtDate;
390+
await assignment.Update(timePlanningDbContext).ConfigureAwait(false);
391+
}
383392
}
384393

385394
// find all PlanningCases where the DoneByUserId is the same as the worker.Id and update the DoneByUserName to the new name

0 commit comments

Comments
 (0)