@@ -23,10 +23,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323*/
2424
2525
26+ using System . Globalization ;
2627using System . Runtime . InteropServices ;
2728using System . Text . RegularExpressions ;
29+ using System . Threading ;
30+ using BackendConfiguration . Pn . Infrastructure . Helpers ;
31+ using BackendConfiguration . Pn . Infrastructure . Models . TaskManagement ;
32+ using Microting . eForm . Infrastructure . Models ;
2833using Microting . EformAngularFrontendBase . Infrastructure . Data ;
2934using Microting . EformAngularFrontendBase . Infrastructure . Data . Factories ;
35+ using Microting . EformBackendConfigurationBase . Infrastructure . Data . Entities ;
36+ using Microting . EformBackendConfigurationBase . Infrastructure . Enum ;
3037using QuestPDF . Infrastructure ;
3138using Sentry ;
3239
@@ -192,9 +199,9 @@ private static async void SeedEForms(IServiceCollection services)
192199 }
193200
194201
195- var context = serviceProvider . GetRequiredService < BackendConfigurationPnDbContext > ( ) ;
196- var itemsPlanningContext = serviceProvider . GetRequiredService < ItemsPlanningPnDbContext > ( ) ;
197- var caseTemplateContext = serviceProvider . GetRequiredService < CaseTemplatePnDbContext > ( ) ;
202+ var backendConfigurationPnDbContext = serviceProvider . GetRequiredService < BackendConfigurationPnDbContext > ( ) ;
203+ // var itemsPlanningContext = serviceProvider.GetRequiredService<ItemsPlanningPnDbContext>();
204+ // var caseTemplateContext = serviceProvider.GetRequiredService<CaseTemplatePnDbContext>();
198205 // seed eforms
199206 var assembly = Assembly . GetExecutingAssembly ( ) ;
200207 foreach ( var ( eformName , eform ) in eforms )
@@ -332,65 +339,188 @@ private static async void SeedEForms(IServiceCollection services)
332339 }
333340 }
334341
335- var powerToolCheckList = await sdkDbContext . CheckListTranslations . FirstOrDefaultAsync ( x => x . Text == "Elvætktøj " ) ;
336- if ( powerToolCheckList != null )
342+ var fieldToFix = await sdkDbContext . Fields . FirstOrDefaultAsync ( x => x . OriginalId == "375733 " ) ;
343+ if ( fieldToFix != null )
337344 {
338- powerToolCheckList . Text = "Elværktøj" ;
339- await powerToolCheckList . Update ( sdkDbContext ) ;
340- }
341-
342- var cls = await sdkDbContext . CheckLists . Where ( x =>
343- x . OriginalId == "142719" && x . WorkflowState != Microting . eForm . Infrastructure . Constants
344- . Constants . WorkflowStates . Removed ) . ToListAsync ( ) ;
345- foreach ( var checkList in cls )
346- {
347- await checkList . Delete ( sdkDbContext ) ;
348- var clts = await sdkDbContext . CheckListTranslations . Where ( x =>
349- x . CheckListId == checkList . Id ) . ToListAsync ( ) ;
345+ fieldToFix . Mandatory = 1 ;
346+ await fieldToFix . Update ( sdkDbContext ) ;
347+ SentrySdk . CaptureMessage ( "Field 375733 was fixed!" ) ;
348+ var localizationService = serviceProvider . GetRequiredService < IBackendConfigurationLocalizationService > ( ) ;
349+
350+ // 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
351+ var propertiesWithWorkOrderEnabled = await backendConfigurationPnDbContext . Properties
352+ . Where ( x => x . WorkflowState != Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
353+ . Where ( x => x . WorkorderEnable == true )
354+ . Include ( property => property . PropertyWorkers )
355+ . ToListAsync ( ) ;
350356
351- foreach ( var clt in clts )
357+ var eformId = await sdkDbContext . CheckLists
358+ . Where ( x => x . WorkflowState != Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
359+ . Where ( x => x . OriginalId == "142663new2" )
360+ . Select ( x => x . Id )
361+ . FirstAsync ( ) . ConfigureAwait ( false ) ;
362+ foreach ( var property in propertiesWithWorkOrderEnabled )
352363 {
353- await clt . Delete ( sdkDbContext ) ;
364+ var propertyWorkers = property . PropertyWorkers
365+ . Where ( x => x . TaskManagementEnabled == true )
366+ . Where ( x => x . WorkflowState !=
367+ Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
368+ . ToList ( ) ;
369+ await WorkOrderHelper
370+ . RetractEform ( propertyWorkers , true , core , null , backendConfigurationPnDbContext )
371+ . ConfigureAwait ( false ) ;
372+
373+ foreach ( var propertyWorker in propertyWorkers )
374+ {
375+ var site = await sdkDbContext . Sites . SingleAsync ( x => x . Id == propertyWorker . WorkerId ) . ConfigureAwait ( false ) ;
376+ var language = await sdkDbContext . Languages . SingleAsync ( x => x . Id == site . LanguageId ) . ConfigureAwait ( false ) ;
377+ var mainElement = await core . ReadeForm ( eformId , language ) . ConfigureAwait ( false ) ;
378+
379+ var deviceUsersGroup = await sdkDbContext . EntityGroups . FirstAsync ( x => x . Id == property . EntitySelectListDeviceUsers )
380+ . ConfigureAwait ( false ) ;
381+
382+ var areasGroup = await sdkDbContext . EntityGroups . FirstAsync ( x => x . Id == property . EntitySelectListAreas )
383+ . ConfigureAwait ( false ) ;
384+
385+ //if (localizationService != null)
386+ //{
387+ // get the localization service
388+ Thread . CurrentThread . CurrentCulture = CultureInfo . GetCultureInfo ( language . LanguageCode ) ;
389+ string description = "<strong>" + localizationService . GetString ( "Location" ) + "</strong>: " + property . Name ;
390+ string newTask = localizationService . GetString ( "NewTask" ) ;
391+ //}
392+
393+ mainElement . Repeated = 0 ;
394+ mainElement . ElementList [ 0 ] . QuickSyncEnabled = true ;
395+ mainElement . ElementList [ 0 ] . Description . InderValue = description ;
396+ mainElement . ElementList [ 0 ] . Label = newTask ;
397+ mainElement . Label = newTask ;
398+ mainElement . EnableQuickSync = true ;
399+ if ( property . FolderIdForNewTasks != null )
400+ {
401+ mainElement . CheckListFolderName = await sdkDbContext . Folders
402+ . Where ( x => x . Id == property . FolderIdForNewTasks )
403+ . Select ( x => x . MicrotingUid . ToString ( ) )
404+ . FirstOrDefaultAsync ( ) . ConfigureAwait ( false ) ;
405+ }
406+
407+ if ( ! string . IsNullOrEmpty ( description ) )
408+ {
409+ ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 0 ] . Description . InderValue = description ;
410+ ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 0 ] . Label = " " ;
411+ }
412+
413+ //if (areasGroupUid != null && deviceUsersGroupId != null)
414+ //{
415+ ( ( EntitySelect ) ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 2 ] ) . Source = int . Parse ( areasGroup . MicrotingUid ) ;
416+ ( ( EntitySelect ) ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList [ 6 ] ) . Source =
417+ int . Parse ( deviceUsersGroup . MicrotingUid ) ;
418+ //}
419+ // else if (areasGroupUid == null && deviceUsersGroupId != null)
420+ // {
421+ // ((EntitySelect)((DataElement)mainElement.ElementList[0]).DataItemList[4]).Source =
422+ // (int)deviceUsersGroupId;
423+ // }
424+
425+ mainElement . EndDate = DateTime . Now . AddYears ( 10 ) . ToUniversalTime ( ) ;
426+ mainElement . StartDate = DateTime . Now . ToUniversalTime ( ) ;
427+ var caseId = await core . CaseCreate ( mainElement , "" , ( int ) site . MicrotingUid , property . FolderIdForNewTasks ) . ConfigureAwait ( false ) ;
428+ await new WorkorderCase
429+ {
430+ CaseId = ( int ) caseId ,
431+ PropertyWorkerId = propertyWorker . Id ,
432+ CaseStatusesEnum = CaseStatusesEnum . NewTask ,
433+ CreatedByUserId = 1 ,
434+ UpdatedByUserId = 1 ,
435+ } . Create ( backendConfigurationPnDbContext ) . ConfigureAwait ( false ) ;
436+ }
354437 }
355- }
356438
357- var fieldLabels = await sdkDbContext . FieldTranslations . Where ( x => x . Text == "Værktøjshus og håndtag OK" ) . ToListAsync ( ) ;
358- foreach ( var fieldLabel in fieldLabels )
359- {
360- fieldLabel . Text = "Værktøjshus og håndtag OK" ;
361- await fieldLabel . Update ( sdkDbContext ) ;
362439 }
363440
364- fieldLabels = await sdkDbContext . FieldTranslations . Where ( x => x . Text == "Kæder OK" ) . ToListAsync ( ) ;
365- foreach ( var fieldLabel in fieldLabels )
441+ fieldToFix = await sdkDbContext . Fields . FirstOrDefaultAsync ( x => x . OriginalId == "375727" ) ;
442+ if ( fieldToFix != null )
366443 {
367- fieldLabel . Text = "Kæder OK" ;
368- await fieldLabel . Update ( sdkDbContext ) ;
444+ fieldToFix . Mandatory = 1 ;
445+ await fieldToFix . Update ( sdkDbContext ) ;
446+ SentrySdk . CaptureMessage ( "Field 375727 was fixed!" ) ;
369447 }
370448
371- // Seed areas
372- foreach ( var newArea in BackendConfigurationSeedAreas . AreasSeed
373- . Where ( newArea => ! context . Areas . Any ( x => x . Id == newArea . Id ) )
374- . Where ( x => x . IsDisabled == false ) )
449+ var translations = new List < KeyValuePair < string , string > > {
450+ new ( "da" , "00. Overskredne opgaver" ) ,
451+ new ( "en-US" , "00. Exceeded tasks" ) ,
452+ new ( "de-DE" , "00. Überschrittene Aufgaben" ) ,
453+ new ( "uk-UA" , "00. Перевищені завдання" ) ,
454+ new ( "pl-PL" , "00. Przekroczone zadania" ) ,
455+ new ( "no-NO" , "00. Overskredne oppgaver" ) ,
456+ new ( "sv-SE" , "00. Överskridna uppgifter" ) ,
457+ new ( "es-ES" , "00. Tareas excedidas" ) ,
458+ new ( "fr-FR" , "00. Tâches dépassées" ) ,
459+ new ( "it-IT" , "00. Compiti superati" ) ,
460+ new ( "nl-NL" , "00. Overschreden taken" ) ,
461+ new ( "pt-BR" , "00. Tarefas excedidas" ) ,
462+ new ( "pt-PT" , "00. Tarefas excedidas" ) ,
463+ new ( "fi-FI" , "00. Ylitetyt tehtävät" ) ,
464+ new ( "tr-TR" , "00. Aşılan görevler" ) ,
465+ new ( "et-ET" , "00. Ületatud ülesanded" ) ,
466+ new ( "lv-LV" , "00. Pārsniegtie uzdevumi" ) ,
467+ new ( "lt-LT" , "00. Viršyti uždaviniai" ) ,
468+ new ( "ro-RO" , "00. Sarcini depășite" ) ,
469+ new ( "bg-BG" , "00. Превишени задачи" ) ,
470+ new ( "sk-SK" , "00. Prekročené úlohy" ) ,
471+ new ( "sl-SL" , "00. Presežene naloge" ) ,
472+ new ( "is-IS" , "00. Yfirskredin verkefni" ) ,
473+ new ( "cs-CZ" , "00. Překročené úkoly" ) ,
474+ new ( "hr-HR" , "00. Prekoračeni zad" )
475+ } ;
476+
477+ var sdkLanguages = await sdkDbContext . Languages . ToListAsync ( ) ;
478+ // create a List of CommonTranslationsModel for each language
479+ var commonTranslations = new List < CommonTranslationsModel > ( ) ;
480+ foreach ( var translation in translations )
375481 {
376- await newArea . Create ( context ) . ConfigureAwait ( false ) ;
482+ var language = sdkLanguages . FirstOrDefault ( x => x . LanguageCode == translation . Key ) ;
483+ if ( language != null )
484+ {
485+ commonTranslations . Add ( new CommonTranslationsModel
486+ {
487+ Name = translation . Value ,
488+ LanguageId = language . Id
489+ } ) ;
490+ }
377491 }
378492
379- var tailBitPlanningTag = await itemsPlanningContext . PlanningTags . Where ( x => x . Name == "Halebid" ) . FirstOrDefaultAsync ( ) ;
493+ var currentProperties = await backendConfigurationPnDbContext . Properties
494+ . Where ( x => x . WorkflowState != Microting . eForm . Infrastructure . Constants . Constants . WorkflowStates . Removed )
495+ . ToListAsync ( ) . ConfigureAwait ( false ) ;
380496
381- if ( tailBitPlanningTag != null )
497+ foreach ( var property in currentProperties )
382498 {
383- var plannings = await itemsPlanningContext . Plannings
384- . Where ( x => x . RelatedEFormName . Contains ( "Halebid" ) )
385- . Where ( x => x . ReportGroupPlanningTagId == null )
386- . ToListAsync ( ) ;
387-
388- foreach ( var planning in plannings )
499+ // loop over each property and find the property.FolderId and see if it has any subfolders with the name "Exceeded tasks" if not create it calling core.FolderCreate with the parentId set to the property.FolderId
500+ var folder = await sdkDbContext . Folders . FirstOrDefaultAsync ( x => x . Id == property . FolderId ) ;
501+ if ( folder != null )
389502 {
390- planning . ReportGroupPlanningTagId = tailBitPlanningTag . Id ;
391- await planning . Update ( itemsPlanningContext ) ;
503+ // join the table Folder with the FolderTranslations to find the "Exceeded tasks" folder with the parentId set to the property.FolderId
504+ var folderAndFolderTranslation = await sdkDbContext . Folders
505+ . Join ( sdkDbContext . FolderTranslations ,
506+ lookupFolder => lookupFolder . Id ,
507+ folderTranslation => folderTranslation . FolderId ,
508+ ( lookupFolder , folderTranslation ) => new { lookupFolder , folderTranslation } )
509+ . Where ( x => x . lookupFolder . ParentId == folder . Id && x . folderTranslation . Name == "Exceeded tasks" )
510+ . FirstOrDefaultAsync ( ) ;
511+ if ( folderAndFolderTranslation == null ) // if the folder does not exist create it
512+ {
513+ await core . FolderCreate ( commonTranslations , folder . Id ) . ConfigureAwait ( false ) ;
514+ }
392515 }
393516 }
517+
518+ foreach ( var newArea in BackendConfigurationSeedAreas . AreasSeed
519+ . Where ( newArea => ! backendConfigurationPnDbContext . Areas . Any ( x => x . Id == newArea . Id ) )
520+ . Where ( x => x . IsDisabled == false ) )
521+ {
522+ await newArea . Create ( backendConfigurationPnDbContext ) . ConfigureAwait ( false ) ;
523+ }
394524 }
395525
396526 public void ConfigureDbContext ( IServiceCollection services , string connectionString )
0 commit comments