@@ -339,132 +339,133 @@ private static async void SeedEForms(IServiceCollection services)
339339 }
340340 }
341341
342- var priorityFieldsToFix = await sdkDbContext . Fields . Where ( x => x . OriginalId == "376935" ) . ToListAsync ( ) ;
343- foreach ( var priorityFieldToFix in priorityFieldsToFix )
344- {
345- if ( priorityFieldToFix . Mandatory == 0 )
346- {
347- priorityFieldToFix . Mandatory = 1 ;
348- await priorityFieldToFix . Update ( sdkDbContext ) ;
349- SentrySdk . CaptureMessage ( "Field 376935 was fixed!" ) ;
350- }
351- }
352-
353- var fieldToFix = await sdkDbContext . Fields . OrderBy ( x => x . Id ) . LastOrDefaultAsync ( x => x . OriginalId == "375727" ) ;
354- if ( fieldToFix is { Mandatory : 0 } )
355- {
356- fieldToFix . Mandatory = 1 ;
357- await fieldToFix . Update ( sdkDbContext ) ;
358- SentrySdk . CaptureMessage ( "Field 375727 was fixed!" ) ;
359- var localizationService = serviceProvider . GetRequiredService < IBackendConfigurationLocalizationService > ( ) ;
360-
361- // 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
362- var propertiesWithWorkOrderEnabled = await backendConfigurationPnDbContext . Properties
363- . Where ( x => x . WorkflowState != Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
364- . Where ( x => x . WorkorderEnable == true )
365- . Include ( property => property . PropertyWorkers )
366- . ToListAsync ( ) ;
367-
368- var eformId = await sdkDbContext . CheckLists
369- . Where ( x => x . WorkflowState != Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
370- . Where ( x => x . OriginalId == "142663new2" )
371- . Select ( x => x . Id )
372- . FirstAsync ( ) . ConfigureAwait ( false ) ;
373- foreach ( var property in propertiesWithWorkOrderEnabled )
374- {
375- Console . WriteLine ( $ "Handling property { property . Name } ") ;
376- var propertyWorkers = property . PropertyWorkers
377- . Where ( x => x . TaskManagementEnabled == true )
378- . Where ( x => x . WorkflowState !=
379- Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
380- . ToList ( ) ;
381- await WorkOrderHelper
382- . RetractEform ( propertyWorkers , true , core , null , backendConfigurationPnDbContext )
383- . ConfigureAwait ( false ) ;
384-
385- foreach ( var propertyWorker in propertyWorkers )
386- {
387- var site = await sdkDbContext . Sites . SingleAsync ( x => x . Id == propertyWorker . WorkerId ) . ConfigureAwait ( false ) ;
388- Console . WriteLine ( $ "Handling property { property . Name } and propertyWorker { propertyWorker . WorkerId } with the site.name { site . Name } ") ;
389- var language = await sdkDbContext . Languages . SingleAsync ( x => x . Id == site . LanguageId ) . ConfigureAwait ( false ) ;
390- var mainElement = await core . ReadeForm ( eformId , language ) . ConfigureAwait ( false ) ;
391-
392- var deviceUsersGroup = await sdkDbContext . EntityGroups . FirstAsync ( x => x . Id == property . EntitySelectListDeviceUsers )
393- . ConfigureAwait ( false ) ;
394-
395- var areasGroup = await sdkDbContext . EntityGroups . FirstAsync ( x => x . Id == property . EntitySelectListAreas )
396- . ConfigureAwait ( false ) ;
397-
398- //if (localizationService != null)
399- //{
400- // get the localization service
401- Thread . CurrentThread . CurrentCulture = CultureInfo . GetCultureInfo ( language . LanguageCode ) ;
402- string description = "<strong>" + localizationService . GetString ( "Location" ) + "</strong>: " + property . Name ;
403- string newTask = localizationService . GetString ( "NewTask" ) ;
404- //}
405-
406- mainElement . Repeated = 0 ;
407- mainElement . ElementList [ 0 ] . QuickSyncEnabled = true ;
408- mainElement . ElementList [ 0 ] . Description . InderValue = description ;
409- mainElement . ElementList [ 0 ] . Label = newTask ;
410- mainElement . Label = newTask ;
411- mainElement . EnableQuickSync = true ;
412- if ( property . FolderIdForNewTasks != null )
413- {
414- mainElement . CheckListFolderName = await sdkDbContext . Folders
415- . Where ( x => x . Id == property . FolderIdForNewTasks )
416- . Select ( x => x . MicrotingUid . ToString ( ) )
417- . FirstOrDefaultAsync ( ) . ConfigureAwait ( false ) ;
418- }
419-
420- if ( ! string . IsNullOrEmpty ( description ) )
421- {
422- ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 0 ] . Description . InderValue = description ;
423- ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 0 ] . Label = " " ;
424- }
425-
426- //if (areasGroupUid != null && deviceUsersGroupId != null)
427- //{
428- ( ( EntitySelect ) ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 2 ] ) . Source = int . Parse ( areasGroup . MicrotingUid ) ;
429- ( ( EntitySelect ) ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 6 ] ) . Source =
430- int . Parse ( deviceUsersGroup . MicrotingUid ) ;
431- //}
432- // else if (areasGroupUid == null && deviceUsersGroupId != null)
433- // {
434- // ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[4]).Source =
435- // (int)deviceUsersGroupId;
436- // }
437-
438- mainElement . EndDate = DateTime . Now . AddYears ( 10 ) . ToUniversalTime ( ) ;
439- mainElement . StartDate = DateTime . Now . ToUniversalTime ( ) ;
440- var caseId = await core . CaseCreate ( mainElement , "" , ( int ) site . MicrotingUid , property . FolderIdForNewTasks ) . ConfigureAwait ( false ) ;
441- await new WorkorderCase
442- {
443- CaseId = ( int ) caseId ,
444- PropertyWorkerId = propertyWorker . Id ,
445- CaseStatusesEnum = CaseStatusesEnum . NewTask ,
446- CreatedByUserId = 1 ,
447- UpdatedByUserId = 1 ,
448- } . Create ( backendConfigurationPnDbContext ) . ConfigureAwait ( false ) ;
449- }
450- }
451- }
452-
453- fieldToFix = await sdkDbContext . Fields . OrderBy ( x => x . Id ) . LastOrDefaultAsync ( x => x . OriginalId == "375733" ) ;
454- if ( fieldToFix is { Mandatory : 0 } )
455- {
456- fieldToFix . Mandatory = 1 ;
457- await fieldToFix . Update ( sdkDbContext ) ;
458- SentrySdk . CaptureMessage ( "Field 375733 was fixed!" ) ;
459- }
460-
461- fieldToFix = await sdkDbContext . Fields . OrderBy ( x => x . Id ) . LastOrDefaultAsync ( x => x . OriginalId == "375734" ) ;
462- if ( fieldToFix is { Mandatory : 0 } )
463- {
464- fieldToFix . Mandatory = 1 ;
465- await fieldToFix . Update ( sdkDbContext ) ;
466- SentrySdk . CaptureMessage ( "Field 375734 was fixed!" ) ;
467- }
342+ // TODO remove this code when sure that the fields are fixed on all installations
343+ // var priorityFieldsToFix = await sdkDbContext.Fields.Where(x => x.OriginalId == "376935").ToListAsync();
344+ // foreach (var priorityFieldToFix in priorityFieldsToFix)
345+ // {
346+ // if (priorityFieldToFix.Mandatory == 0)
347+ // {
348+ // priorityFieldToFix.Mandatory = 1;
349+ // await priorityFieldToFix.Update(sdkDbContext);
350+ // SentrySdk.CaptureMessage("Field 376935 was fixed!");
351+ // }
352+ // }
353+ //
354+ // var fieldToFix = await sdkDbContext.Fields.OrderBy(x => x.Id).LastOrDefaultAsync(x => x.OriginalId == "375727");
355+ // if (fieldToFix is { Mandatory: 0 })
356+ // {
357+ // fieldToFix.Mandatory = 1;
358+ // await fieldToFix.Update(sdkDbContext);
359+ // SentrySdk.CaptureMessage("Field 375727 was fixed!");
360+ // var localizationService = serviceProvider.GetRequiredService<IBackendConfigurationLocalizationService>();
361+ //
362+ // // 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
363+ // var propertiesWithWorkOrderEnabled = await backendConfigurationPnDbContext.Properties
364+ // .Where(x => x.WorkflowState != Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
365+ // .Where(x => x.WorkorderEnable == true)
366+ // .Include(property => property.PropertyWorkers)
367+ // .ToListAsync();
368+ //
369+ // var eformId = await sdkDbContext.CheckLists
370+ // .Where(x => x.WorkflowState != Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
371+ // .Where(x => x.OriginalId == "142663new2")
372+ // .Select(x => x.Id)
373+ // .FirstAsync().ConfigureAwait(false);
374+ // foreach (var property in propertiesWithWorkOrderEnabled)
375+ // {
376+ // Console.WriteLine($"Handling property {property.Name}");
377+ // var propertyWorkers = property.PropertyWorkers
378+ // .Where(x => x.TaskManagementEnabled == true)
379+ // .Where(x => x.WorkflowState !=
380+ // Microting.eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed)
381+ // .ToList();
382+ // await WorkOrderHelper
383+ // .RetractEform(propertyWorkers, true, core,null, backendConfigurationPnDbContext)
384+ // .ConfigureAwait(false);
385+ //
386+ // foreach (var propertyWorker in propertyWorkers)
387+ // {
388+ // var site = await sdkDbContext.Sites.SingleAsync(x => x.Id == propertyWorker.WorkerId).ConfigureAwait(false);
389+ // Console.WriteLine($"Handling property {property.Name} and propertyWorker {propertyWorker.WorkerId} with the site.name {site.Name}");
390+ // var language = await sdkDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId).ConfigureAwait(false);
391+ // var mainElement = await core.ReadeForm(eformId, language).ConfigureAwait(false);
392+ //
393+ // var deviceUsersGroup = await sdkDbContext.EntityGroups.FirstAsync(x => x.Id == property.EntitySelectListDeviceUsers)
394+ // .ConfigureAwait(false);
395+ //
396+ // var areasGroup = await sdkDbContext.EntityGroups.FirstAsync(x => x.Id == property.EntitySelectListAreas)
397+ // .ConfigureAwait(false);
398+ //
399+ // //if (localizationService != null)
400+ // //{
401+ // // get the localization service
402+ // Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(language.LanguageCode);
403+ // string description = "<strong>"+localizationService.GetString("Location") + "</strong>: " + property.Name;
404+ // string newTask = localizationService.GetString("NewTask");
405+ // //}
406+ //
407+ // mainElement.Repeated = 0;
408+ // mainElement.ElementList[0].QuickSyncEnabled = true;
409+ // mainElement.ElementList[0].Description.InderValue = description;
410+ // mainElement.ElementList[0].Label = newTask;
411+ // mainElement.Label = newTask;
412+ // mainElement.EnableQuickSync = true;
413+ // if (property.FolderIdForNewTasks != null)
414+ // {
415+ // mainElement.CheckListFolderName = await sdkDbContext.Folders
416+ // .Where(x => x.Id == property.FolderIdForNewTasks)
417+ // .Select(x => x.MicrotingUid.ToString())
418+ // .FirstOrDefaultAsync().ConfigureAwait(false);
419+ // }
420+ //
421+ // if (!string.IsNullOrEmpty(description))
422+ // {
423+ // ((DataElement)mainElement.ElementList[0]).DataItemList[0].Description.InderValue = description;
424+ // ((DataElement)mainElement.ElementList[0]).DataItemList[0].Label = " ";
425+ // }
426+ //
427+ // //if (areasGroupUid != null && deviceUsersGroupId != null)
428+ // //{
429+ // ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[2]).Source = int.Parse(areasGroup.MicrotingUid);
430+ // ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[6]).Source =
431+ // int.Parse(deviceUsersGroup.MicrotingUid);
432+ // //}
433+ // // else if (areasGroupUid == null && deviceUsersGroupId != null)
434+ // // {
435+ // // ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[4]).Source =
436+ // // (int)deviceUsersGroupId;
437+ // // }
438+ //
439+ // mainElement.EndDate = DateTime.Now.AddYears(10).ToUniversalTime();
440+ // mainElement.StartDate = DateTime.Now.ToUniversalTime();
441+ // var caseId = await core.CaseCreate(mainElement, "", (int)site.MicrotingUid, property.FolderIdForNewTasks).ConfigureAwait(false);
442+ // await new WorkorderCase
443+ // {
444+ // CaseId = (int)caseId,
445+ // PropertyWorkerId = propertyWorker.Id,
446+ // CaseStatusesEnum = CaseStatusesEnum.NewTask,
447+ // CreatedByUserId = 1,
448+ // UpdatedByUserId = 1,
449+ // }.Create(backendConfigurationPnDbContext).ConfigureAwait(false);
450+ // }
451+ // }
452+ // }
453+ //
454+ // fieldToFix = await sdkDbContext.Fields.OrderBy(x => x.Id).LastOrDefaultAsync(x => x.OriginalId == "375733");
455+ // if (fieldToFix is { Mandatory: 0 })
456+ // {
457+ // fieldToFix.Mandatory = 1;
458+ // await fieldToFix.Update(sdkDbContext);
459+ // SentrySdk.CaptureMessage("Field 375733 was fixed!");
460+ // }
461+ //
462+ // fieldToFix = await sdkDbContext.Fields.OrderBy(x => x.Id).LastOrDefaultAsync(x => x.OriginalId == "375734");
463+ // if (fieldToFix is { Mandatory: 0 })
464+ // {
465+ // fieldToFix.Mandatory = 1;
466+ // await fieldToFix.Update(sdkDbContext);
467+ // SentrySdk.CaptureMessage("Field 375734 was fixed!");
468+ // }
468469
469470 var translations = new List < KeyValuePair < string , string > > {
470471 new ( "da" , "00. Overskredne opgaver" ) ,
0 commit comments