diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs index f2d8d9f4..c4ba57c2 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleDays2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -454,7 +455,8 @@ public async Task UpdatePlanning_AreaRuleWeeks1Monday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -858,7 +860,8 @@ public async Task UpdatePlanning_AreaRuleWeeks2Wednesday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1262,7 +1265,8 @@ public async Task UpdatePlanning_AreaRuleDays0_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1688,7 +1692,8 @@ public async Task UpdatePlanning_AreaRuleDays0FillAndAdd_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1817,7 +1822,8 @@ await BackendConfigurationAreaRulePlanningsServiceHelper.UpdatePlanning(areaRule LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel2, core, 1, @@ -2159,7 +2165,8 @@ public async Task UpdatePlanning_AreaRuleDays4DisableReenable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs index d49169b1..8f59e5bf 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleDays2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -457,7 +458,8 @@ public async Task UpdatePlanning_AreaRuleWeeks1Monday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -874,7 +876,8 @@ public async Task UpdatePlanning_AreaRuleWeeks2Wednesday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1281,7 +1284,8 @@ public async Task UpdatePlanning_AreaRuleDays0_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1676,7 +1680,8 @@ public async Task UpdatePlanning_AreaRuleDays0FillAndAdd_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1808,7 +1813,8 @@ await BackendConfigurationAreaRulePlanningsServiceHelper.UpdatePlanning(areaRule LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel2, core, 1, @@ -2151,7 +2157,8 @@ public async Task UpdatePlanning_AreaRuleDays4DisableReenable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs index 745caf6f..36ca6f11 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleMonths1_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -454,7 +455,8 @@ public async Task UpdatePlanning_AreaRuleMonths2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -855,7 +857,8 @@ public async Task UpdatePlanning_AreaRuleMonths3_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1257,7 +1260,8 @@ public async Task UpdatePlanning_AreaRuleMonths6_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1659,7 +1663,8 @@ public async Task UpdatePlanning_AreaRuleMonths12_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2056,7 +2061,8 @@ public async Task UpdatePlanning_AreaRuleMonths24_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2453,7 +2459,8 @@ public async Task UpdatePlanning_AreaRuleMonths36_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2850,7 +2857,8 @@ public async Task UpdatePlanning_AreaRuleMonths48_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3247,7 +3255,8 @@ public async Task UpdatePlanning_AreaRuleMonths60_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3644,7 +3653,8 @@ public async Task UpdatePlanning_AreaRuleMonths72_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4041,7 +4051,8 @@ public async Task UpdatePlanning_AreaRuleMonths84_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4438,7 +4449,8 @@ public async Task UpdatePlanning_AreaRuleMonths96_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4835,7 +4847,8 @@ public async Task UpdatePlanning_AreaRuleMonths108_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -5232,7 +5245,8 @@ public async Task UpdatePlanning_AreaRuleMonths120_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs index f7111d23..5734cfb7 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleMonths1_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -457,7 +458,8 @@ public async Task UpdatePlanning_AreaRuleMonths2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -860,7 +862,8 @@ public async Task UpdatePlanning_AreaRuleMonths3_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1263,7 +1266,8 @@ public async Task UpdatePlanning_AreaRuleMonths6_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1667,7 +1671,8 @@ public async Task UpdatePlanning_AreaRuleMonths12_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2071,7 +2076,8 @@ public async Task UpdatePlanning_AreaRuleMonths24_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2474,7 +2480,8 @@ public async Task UpdatePlanning_AreaRuleMonths36_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2877,7 +2884,8 @@ public async Task UpdatePlanning_AreaRuleMonths48_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3280,7 +3288,8 @@ public async Task UpdatePlanning_AreaRuleMonths60_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3683,7 +3692,8 @@ public async Task UpdatePlanning_AreaRuleMonths72_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4086,7 +4096,8 @@ public async Task UpdatePlanning_AreaRuleMonths84_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4489,7 +4500,8 @@ public async Task UpdatePlanning_AreaRuleMonths96_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4892,7 +4904,8 @@ public async Task UpdatePlanning_AreaRuleMonths108_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -5295,7 +5308,8 @@ public async Task UpdatePlanning_AreaRuleMonths120_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs index 85d2470e..48f92863 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs @@ -46,7 +46,8 @@ public async Task UpdatePlanning_AreaRule0Days2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -392,7 +393,8 @@ public async Task UpdatePlanning_AreaRule0Days2Disable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -763,7 +765,8 @@ public async Task UpdatePlanning_AreaRule0Days2DisableRenable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs index 41e76d68..8b786b17 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs @@ -4,10 +4,12 @@ using BackendConfiguration.Pn.Infrastructure.Models.Properties; using BackendConfiguration.Pn.Services.BackendConfigurationLocalizationService; using eFormCore; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microting.eForm.Infrastructure.Constants; using Microting.eFormApi.BasePn.Abstractions; +using Microting.eFormApi.BasePn.Infrastructure.Database.Entities; using NSubstitute; namespace BackendConfiguration.Pn.Integration.Test; @@ -32,7 +34,8 @@ public async Task BackendConfigurationAssignmentWorkerServiceHelper_CreateDevice LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; // Act @@ -178,9 +181,14 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU }; // Act + var userService = Substitute.For(); + var userManager = Substitute.For>( + Substitute.For>(), + null, null, null, null, null, null, null, null); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, + userService, userManager, BackendConfigurationPnDbContext, - TimePlanningPnDbContext, logger); + TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); // Assert var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync(); @@ -270,10 +278,16 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU }; // Act + var userService = Substitute.For(); + var userManager = Substitute.For>( + Substitute.For>(), + null, null, null, null, null, null, null, null); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, + userService, + userManager, BackendConfigurationPnDbContext, - TimePlanningPnDbContext, logger); + TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); // Assert var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync(); @@ -364,10 +378,16 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU }; // Act + var userService = Substitute.For(); + var userManager = Substitute.For>( + Substitute.For>(), + null, null, null, null, null, null, null, null); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, + userService, + userManager, BackendConfigurationPnDbContext, - TimePlanningPnDbContext, logger); + TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); // Assert var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync(); @@ -399,7 +419,11 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU // Assert timeregistrationSiteAssignments Assert.That(timeregistrationSiteAssignments.Count, Is.EqualTo(1)); Assert.That(timeregistrationSiteAssignments[0].SiteId, Is.EqualTo(sites[2].MicrotingUid)); - Assert.That(timeregistrationSiteAssignments[0].WorkflowState, Is.EqualTo(Constants.WorkflowStates.Removed)); + Assert.That(timeregistrationSiteAssignments[0].WorkflowState, Is.EqualTo(Constants.WorkflowStates.Created)); + Assert.That(timeregistrationSiteAssignments[0].Resigned, Is.True); + Assert.That(timeregistrationSiteAssignments[0].ResignedAtDate.Year, Is.EqualTo(DateTime.Now.Year)); + Assert.That(timeregistrationSiteAssignments[0].ResignedAtDate.Month, Is.EqualTo(DateTime.Now.Month)); + Assert.That(timeregistrationSiteAssignments[0].ResignedAtDate.Day, Is.EqualTo(DateTime.Now.Day)); // Assert propertyWorkers Assert.That(propertyWorkers.Count, Is.EqualTo(0)); @@ -437,7 +461,8 @@ await BackendConfigurationPropertiesServiceHelper.Create(propertyCreateModel, co LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; /*var result = */await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -532,7 +557,8 @@ await BackendConfigurationPropertiesServiceHelper.Create(propertyCreateModel, co LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; /*var result = */await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -799,7 +825,8 @@ await BackendConfigurationPropertiesServiceHelper.Create(propertyCreateModel2, c TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), UserLastName = Guid.NewGuid().ToString(), - TaskManagementEnabled = true + TaskManagementEnabled = true, + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index 9e19d22e..e4887ca1 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -9,6 +9,7 @@ using BackendConfiguration.Pn.Services.BackendConfigurationLocalizationService; using eFormCore; using JetBrains.Annotations; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microting.eForm.Infrastructure; using Microting.eForm.Infrastructure.Constants; @@ -23,6 +24,7 @@ using Microting.TimePlanningBase.Infrastructure.Data.Entities; using Rebus.Bus; using Microsoft.Extensions.Logging; +using Microting.eFormApi.BasePn.Infrastructure.Database.Entities; namespace BackendConfiguration.Pn.Infrastructure.Helpers; @@ -193,20 +195,6 @@ await core.EntityItemUpdate(entity.Id, entity.Name, entity.Description, { await WorkOrderHelper.RetractEform(assignmentsForDelete, true, core, userService.UserId, backendConfigurationPnDbContext).ConfigureAwait(false); await WorkOrderHelper.RetractEform(assignmentsForDelete, false, core, userService.UserId, backendConfigurationPnDbContext).ConfigureAwait(false); - - // foreach (var propertyWorker in assignmentsForDelete) - // { - // var documentSites = await caseTemplatePnDbContext.DocumentSites.Where(x => x.PropertyId == propertyWorker.PropertyId - // && x.SdkSiteId == propertyWorker.WorkerId).ToListAsync(); - // foreach (var documentSite in documentSites) - // { - // if (documentSite.SdkCaseId != 0) - // { - // await core.CaseDelete(documentSite.SdkCaseId); - // } - // } - // } - } foreach (var documentId in documentIds) @@ -267,7 +255,12 @@ await WorkOrderHelper.WorkorderFlowDeployEform(propertyWorkers, core, userServic public static async Task UpdateDeviceUser(DeviceUserModel deviceUserModel, Core core, int userId, - BackendConfigurationPnDbContext backendConfigurationPnDbContext, TimePlanningPnDbContext timePlanningDbContext, ILogger logger) + IUserService userService, + UserManager userManager, + BackendConfigurationPnDbContext backendConfigurationPnDbContext, + TimePlanningPnDbContext timePlanningDbContext, + ILogger logger, + ItemsPlanningPnDbContext itemsPlanningPnDbContext) { deviceUserModel.UserFirstName = deviceUserModel.UserFirstName.Trim(); deviceUserModel.UserLastName = deviceUserModel.UserLastName.Trim(); @@ -280,13 +273,14 @@ public static async Task UpdateDeviceUser(DeviceUserModel devic var sdkDbContext = core.DbContextHelper.GetDbContext(); var language = sdkDbContext.Languages.Single(x => x.LanguageCode == deviceUserModel.LanguageCode); var siteDto = await core.SiteRead(deviceUserModel.SiteMicrotingUid).ConfigureAwait(false); - if (siteDto.WorkerUid != null) + var oldSiteName = siteDto.SiteName; + if (siteDto.WorkerUid == null) return new OperationResult(false, "DeviceUserNotFound"); { // var workerDto = await core.Advanced_WorkerRead((int)siteDto.WorkerUid); var worker = await sdkDbContext.Workers.SingleOrDefaultAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false); - if (worker != null) + if (worker == null) return new OperationResult(false, "DeviceUserCouldNotBeObtained"); { - + var oldEmail = worker.Email; if (sdkDbContext.Workers.Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid)) { // this email is already in use @@ -304,6 +298,16 @@ public static async Task UpdateDeviceUser(DeviceUserModel devic worker.PhoneNumber = deviceUserModel.PhoneNumber; await worker.Update(sdkDbContext).ConfigureAwait(false); + var user = await userService.GetByUsernameAsync(oldEmail).ConfigureAwait(false); + if (user != null) + { + user.Email = deviceUserModel.WorkerEmail; + user.FirstName = deviceUserModel.UserFirstName; + user.LastName = deviceUserModel.UserLastName; + user.Locale = language.LanguageCode; + var result = await userManager.UpdateAsync(user); + } + if (isUpdated) { if (deviceUserModel.TaskManagementEnabled == true) @@ -367,6 +371,31 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti } } } + + // find all PlanningCases where the DoneByUserId is the same as the worker.Id and update the DoneByUserName to the new name + var planningCases = await itemsPlanningPnDbContext.PlanningCases + .Where(x => x.DoneByUserId == worker.Id) + .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + .Where(x => x.Status == 100) + .ToListAsync().ConfigureAwait(false); + foreach (var planningCase in planningCases) + { + planningCase.DoneByUserName = fullName; + await planningCase.Update(itemsPlanningPnDbContext).ConfigureAwait(false); + } + + // find all PlanningCaseSites where the DoneByUserId is the same as the SiteId and update the DoneByUserName to the new name + var planningCaseSites = await itemsPlanningPnDbContext.PlanningCaseSites + .Where(x => x.DoneByUserId == worker.Id) + .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + .Where(x => x.Status == 100) + .ToListAsync().ConfigureAwait(false); + foreach (var planningCaseSite in planningCaseSites) + { + planningCaseSite.DoneByUserName = fullName; + await planningCaseSite.Update(itemsPlanningPnDbContext).ConfigureAwait(false); + } + //var siteId = await sdkDbContext.Sites.Where(x => x.MicrotingUid == siteDto.SiteId).Select(x => x.Id).FirstAsync(); if (deviceUserModel.TimeRegistrationEnabled == false && timePlanningDbContext.AssignedSites.Any(x => x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed)) { @@ -375,87 +404,21 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti foreach (var assignmentForDelete in assignmentForDeletes) { - await assignmentForDelete.Delete(timePlanningDbContext).ConfigureAwait(false); - if (assignmentForDelete.CaseMicrotingUid != null) - { - await core.CaseDelete((int) assignmentForDelete.CaseMicrotingUid).ConfigureAwait(false); - } - } - var planRegistrations = await timePlanningDbContext.PlanRegistrations.Where(x => x.SdkSitId == siteDto.SiteId).ToListAsync().ConfigureAwait(false); - - foreach (var planRegistration in planRegistrations) - { - try - { - if (planRegistration.StatusCaseId != 0) - { - await core.CaseDelete(planRegistration.StatusCaseId).ConfigureAwait(false); - } - } - catch (Exception e) - { - Console.WriteLine(e); - //throw; - } + assignmentForDelete.Resigned = true; + assignmentForDelete.ResignedAtDate = DateTime.UtcNow; + await assignmentForDelete.Update(timePlanningDbContext).ConfigureAwait(false); } } else { if (deviceUserModel.TimeRegistrationEnabled == true) { - var registrationDevices = await timePlanningDbContext.RegistrationDevices - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - - if (registrationDevices.Any()) - { - var assignmentForDeletes = await timePlanningDbContext.AssignedSites.Where(x => - x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false); - - foreach (var assignmentForDelete in assignmentForDeletes) - { - //await assignmentForDelete.Delete(timePlanningDbContext).ConfigureAwait(false); - if (assignmentForDelete.CaseMicrotingUid != null) - { - await core.CaseDelete((int) assignmentForDelete.CaseMicrotingUid).ConfigureAwait(false); - } - } - - var planRegistrations = await timePlanningDbContext.PlanRegistrations.Where(x => x.SdkSitId == siteDto.SiteId).ToListAsync().ConfigureAwait(false); - - foreach (var planRegistration in planRegistrations) - { - if (planRegistration.StatusCaseId != 0) - { - await core.CaseDelete(planRegistration.StatusCaseId).ConfigureAwait(false); - } - } - - var assignments1 = await timePlanningDbContext.AssignedSites.Where(x => - x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false); - - if (assignments1.Any()) - { - return new OperationDataResult(true, siteDto.SiteId); - } - - var assignmentSite = new AssignedSite - { - SiteId = siteDto.SiteId, - CreatedByUserId = userId, - UpdatedByUserId = userId - }; - await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false); - await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); - return new OperationDataResult(true, siteDto.SiteId); - } - var assignments = await timePlanningDbContext.AssignedSites.Where(x => x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false); - if (assignments.Any()) + if (assignments.Count != 0) { - await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); + await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger, oldSiteName, fullName).ConfigureAwait(false); return new OperationDataResult(true, siteDto.SiteId); } @@ -468,7 +431,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti UpdatedByUserId = userId }; await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false); - + await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger, oldSiteName, fullName).ConfigureAwait(false); return new OperationDataResult(true, siteDto.SiteId); } catch (Exception e) @@ -479,21 +442,15 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti } } } - // { - // Site site = await db.Sites.SingleAsync(x => x.MicrotingUid == deviceUserModel.Id); - // site.LanguageId = language.Id; - // await site.Update(db); - // } + return isUpdated ? new OperationResult(true, "DeviceUserUpdatedSuccessfully") : new OperationResult(false, "DeviceUserParamCouldNotBeUpdated"); } - return new OperationResult(false, "DeviceUserCouldNotBeObtained"); } - return new OperationResult(false, "DeviceUserNotFound"); } catch (Exception ex) { @@ -505,13 +462,21 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti public static async Task> CreateDeviceUser(DeviceUserModel deviceUserModel, Core core, int userId, TimePlanningPnDbContext timePlanningDbContext) { + + var sdkDbContext = core.DbContextHelper.GetDbContext(); + + if (sdkDbContext.Workers.AsNoTracking().Any(x => x.Email == deviceUserModel.WorkerEmail && x.WorkflowState != Constants.WorkflowStates.Removed)) + { + // this email is already in use + return new OperationDataResult(false, "EmailIsAlreadyInUse"); + } + deviceUserModel.UserFirstName = deviceUserModel.UserFirstName.Trim(); deviceUserModel.UserLastName = deviceUserModel.UserLastName.Trim(); // var result = await _deviceUsersService.Create(deviceUserModel); var siteName = deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName; - var sdkDbContext = core.DbContextHelper.GetDbContext(); - var site = await sdkDbContext.Sites.SingleOrDefaultAsync(x => x.Name == deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName && x.WorkflowState != Constants.WorkflowStates.Removed); + var site = await sdkDbContext.Sites.AsNoTracking().SingleOrDefaultAsync(x => x.Name == deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName && x.WorkflowState != Constants.WorkflowStates.Removed); if (site != null) { @@ -525,12 +490,6 @@ public static async Task> CreateDeviceUser(DeviceUserMo var worker = await sdkDbContext.Workers.SingleAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false); - if (sdkDbContext.Workers.Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid)) - { - // this email is already in use - return new OperationDataResult(false, "EmailIsAlreadyInUse"); - } - worker.EmployeeNo = deviceUserModel.EmployeeNo; worker.PinCode = deviceUserModel.PinCode; worker.Email = deviceUserModel.WorkerEmail; diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs index f3e38b79..4cc4a171 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -16,7 +17,7 @@ namespace BackendConfiguration.Pn.Infrastructure.Helpers; public class GoogleSheetHelper { - public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext dbContext, ILogger logger) + public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext dbContext, ILogger logger, string? oldSiteName = null, string? newSiteName = null) { var privateKeyId = Environment.GetEnvironmentVariable("PRIVATE_KEY_ID"); var googleSheetId = dbContext.PluginConfigurationValues @@ -85,6 +86,11 @@ public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext db { var timerHeader = $"{siteName} - timer"; var textHeader = $"{siteName} - tekst"; + if (newSiteName == siteName) + { + timerHeader = $"{oldSiteName} - tekst"; + textHeader = $"{oldSiteName} - timer"; + } if (!newHeaders.Contains(timerHeader)) { newHeaders.Add(timerHeader); @@ -117,6 +123,32 @@ public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext db logger.LogInformation("Headers updated successfully."); } + // loop through all the existing headers and find the oldSiteName and rename it to newSiteName + if (!string.IsNullOrEmpty(oldSiteName) && !string.IsNullOrEmpty(newSiteName) && newSiteName != oldSiteName) + { + for (int i = 0; i < existingHeaders.Count; i++) + { + if (existingHeaders[i].ToString() == $"{oldSiteName} - timer") + { + existingHeaders[i] = $"{newSiteName} - timer"; + } + else if (existingHeaders[i].ToString() == $"{oldSiteName} - tekst") + { + existingHeaders[i] = $"{newSiteName} - tekst"; + } + } + var updateRequest = new ValueRange + { + Values = new List> { existingHeaders } + }; + var columnLetter = GetColumnLetter(existingHeaders.Count); + var updateHeaderRequest = + service.Spreadsheets.Values.Update(updateRequest, googleSheetId, $"{sheetName}!A1:{columnLetter}1"); + updateHeaderRequest.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW; + await updateHeaderRequest.ExecuteAsync(); + } + AutoAdjustColumnWidths(service, googleSheetId, sheetName, logger); try diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs index 377439f6..ce0b27fc 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs @@ -150,55 +150,55 @@ public static async Task DeployEform(PropertyWorker propertyWorker, int eformId && x.CaseStatusesEnum == CaseStatusesEnum.NewTask && x.WorkflowState != Constants.WorkflowStates.Removed)) { - // find all cases that are not removed and assignedTo is equal to site.name and update them with the new name - var workorderCases = await backendConfigurationPnDbContext.WorkorderCases - .Where(x => x.AssignedToSdkSiteId == propertyWorker.WorkerId) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) - .Where(x => x.LeadingCase == true) - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - foreach (var workorderCase in workorderCases) - { - await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, - localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); - } - - workorderCases = await backendConfigurationPnDbContext.WorkorderCases - .Where(x => x.CreatedBySdkSiteId == propertyWorker.WorkerId) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) - .Where(x => x.LeadingCase == true) - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - foreach (var workorderCase in workorderCases) - { - if(workorderCase.AssignedToSdkSiteId == null) - { - continue; - } - - await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, - localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); - } - - workorderCases = await backendConfigurationPnDbContext.WorkorderCases - .Where(x => x.UpdatedBySdkSiteId == propertyWorker.WorkerId) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) - .Where(x => x.LeadingCase == true) - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - foreach (var workorderCase in workorderCases) - { - if(workorderCase.AssignedToSdkSiteId == null) - { - continue; - } - - await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, - localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); - } + // // find all cases that are not removed and assignedTo is equal to site.name and update them with the new name + // var workorderCases = await backendConfigurationPnDbContext.WorkorderCases + // .Where(x => x.AssignedToSdkSiteId == propertyWorker.WorkerId) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) + // .Where(x => x.LeadingCase == true) + // .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + // .ToListAsync().ConfigureAwait(false); + // foreach (var workorderCase in workorderCases) + // { + // await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, + // localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); + // } + // + // workorderCases = await backendConfigurationPnDbContext.WorkorderCases + // .Where(x => x.CreatedBySdkSiteId == propertyWorker.WorkerId) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) + // .Where(x => x.LeadingCase == true) + // .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + // .ToListAsync().ConfigureAwait(false); + // foreach (var workorderCase in workorderCases) + // { + // if(workorderCase.AssignedToSdkSiteId == null) + // { + // continue; + // } + // + // await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, + // localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); + // } + // + // workorderCases = await backendConfigurationPnDbContext.WorkorderCases + // .Where(x => x.UpdatedBySdkSiteId == propertyWorker.WorkerId) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) + // .Where(x => x.LeadingCase == true) + // .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + // .ToListAsync().ConfigureAwait(false); + // foreach (var workorderCase in workorderCases) + // { + // if(workorderCase.AssignedToSdkSiteId == null) + // { + // continue; + // } + // + // await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, + // localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); + // } return; diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs index a8cea2f7..787585fb 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ #nullable enable +using System; using System.Collections.Generic; namespace BackendConfiguration.Pn.Infrastructure.Models; @@ -92,9 +93,7 @@ public class DeviceUserModel public bool IsLocked { get; set; } public bool IsBackendUser { get; set; } public bool HasWorkOrdersAssigned { get; set; } - public string Manufacturer { get; set; } - public string Model { get; set; } public string Os { get; set; } public string OsVersion { get; set; } @@ -107,6 +106,8 @@ public class DeviceUserModel public string? WorkerEmail { get; set; } public string? PhoneNumber { get; set; } + public DateTime? CreatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } public static implicit operator DeviceUserModel(Microting.EformAngularFrontendBase.Infrastructure.Data.Models.DeviceUserModel model) { diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs index 606a1ae2..778c4934 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs @@ -25,7 +25,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using BackendConfiguration.Pn.Infrastructure.Helpers; using BackendConfiguration.Pn.Infrastructure.Models; using BackendConfiguration.Pn.Services.RebusService; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; +using Microting.eFormApi.BasePn.Infrastructure.Database.Entities; using Microting.EformBackendConfigurationBase.Infrastructure.Enum; using Microting.eFormCaseTemplateBase.Infrastructure.Data; using Microting.ItemsPlanningBase.Infrastructure.Data; @@ -51,6 +53,7 @@ namespace BackendConfiguration.Pn.Services.BackendConfigurationAssignmentWorkerS public class BackendConfigurationAssignmentWorkerService( IEFormCoreService coreHelper, + UserManager userManager, IUserService userService, BackendConfigurationPnDbContext backendConfigurationPnDbContext, IBackendConfigurationLocalizationService backendConfigurationLocalizationService, @@ -364,6 +367,8 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id site.WorkflowState, WorkerEmail = worker.Email, worker.PhoneNumber, + site.CreatedAt, + site.UpdatedAt }; sitesQuery = sitesQuery.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed); @@ -371,6 +376,8 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id var deviceUsers = await sitesQuery .Select(x => new DeviceUserModel { + CreatedAt = x.CreatedAt, + UpdatedAt = x.UpdatedAt, UserFirstName = x.UserFirstName, UserLastName = x.UserLastName, EmployeeNo = x.EmployeeNo, @@ -490,13 +497,6 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id // Convert deviceUsers to IQueryable var deviceUsersQuery = deviceUsers.AsQueryable(); - var tempList = deviceUsersQuery.ToList(); - - foreach (var deviceUserModel in tempList) - { - Console.WriteLine("Device user: " + deviceUserModel.SiteName + " with workerEmail: " + deviceUserModel.WorkerEmail + " and phone number: " + deviceUserModel.PhoneNumber); - } - try { deviceUsersQuery = QueryHelper.AddFilterAndSortToQuery(deviceUsersQuery, requestModel, new List { "SiteName", "WorkerEmail", "PhoneNumber", "EmployeeNo" }); @@ -526,8 +526,8 @@ public async Task UpdateDeviceUser(DeviceUserModel deviceUserMo { var core = await coreHelper.GetCore().ConfigureAwait(false); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(deviceUserModel, core, - userService.UserId, backendConfigurationPnDbContext, - timePlanningDbContext, logger); + userService.UserId, userService, userManager, backendConfigurationPnDbContext, + timePlanningDbContext, logger, itemsPlanningPnDbContext); return new OperationResult(result.Success, backendConfigurationLocalizationService.GetString(result.Message)); } diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs index 213871bf..3a694864 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs @@ -749,7 +749,7 @@ await backendConfigurationPnDbContext.AreaRulePlannings.FirstOrDefaultAsync(x => var dbCase = await sdkDbContext.Cases.FirstOrDefaultAsync(x => x.Id == planningCase.MicrotingSdkCaseId); - var workerId = sdkDbContext.SiteWorkers.First(x => x.Id == dbCase.SiteId).WorkerId; + var workerId = sdkDbContext.SiteWorkers.First(x => x.SiteId == dbCase.SiteId).WorkerId; var worker = await sdkDbContext.Workers.FirstOrDefaultAsync(x => x.Id == workerId); if (dbCase == null) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs index 4a852624..7a7e576b 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs @@ -58,7 +58,7 @@ public async Task GenerateWorkOrderCaseReport(TaskManagementFiltersModel Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "results")); var filePath = Path.Combine(Path.GetTempPath(), "results", - $"{propertyName}_{filtersModel.AreaName}.xlsx"); + $"{propertyName.Replace("/", "")}_{filtersModel.AreaName}.xlsx"); using (var document = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook)) diff --git a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts index a7748ae1..73de8264 100644 --- a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts +++ b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts @@ -220,8 +220,10 @@ export class PropertyWorkerCreateEditModalComponent implements OnInit, OnDestroy .assignPropertiesToWorker({ siteId, assignments: this.assignments, - timeRegistrationEnabled: this.form.value.timeRegistrationEnabled, - taskManagementEnabled: this.form.value.taskManagementEnabled + // eslint-disable-next-line max-len + timeRegistrationEnabled: this.form.value.timeRegistrationEnabled === undefined ? this.selectedDeviceUser.timeRegistrationEnabled : this.form.value.timeRegistrationEnabled, + // eslint-disable-next-line max-len + taskManagementEnabled: this.form.value.taskManagementEnabled === undefined ? this.selectedDeviceUser.taskManagementEnabled : this.form.value.taskManagementEnabled, }) .subscribe((operation) => { if (operation && operation.success) { @@ -235,8 +237,10 @@ export class PropertyWorkerCreateEditModalComponent implements OnInit, OnDestroy .updateAssignPropertiesToWorker({ siteId: this.selectedDeviceUser.normalId, assignments: this.assignments, - timeRegistrationEnabled: this.form.value.timeRegistrationEnabled, - taskManagementEnabled: this.form.value.taskManagementEnabled, + // eslint-disable-next-line max-len + timeRegistrationEnabled: this.form.value.timeRegistrationEnabled === undefined ? this.selectedDeviceUser.timeRegistrationEnabled : this.form.value.timeRegistrationEnabled, + // eslint-disable-next-line max-len + taskManagementEnabled: this.form.value.taskManagementEnabled === undefined ? this.selectedDeviceUser.taskManagementEnabled : this.form.value.taskManagementEnabled, }) .subscribe((operation) => { if (operation && operation.success) { diff --git a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html index 94a4e675..69113996 100644 --- a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html +++ b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html @@ -46,8 +46,18 @@ + + + + -
{{row.siteId}}
+
+ + {{row.siteId}} ({{getFormattedDate(row.createdAt)}} / {{getFormattedDate(row.updatedAt)}}) + + + {{row.siteId}} +
diff --git a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts index d805f75d..5e9eb07e 100644 --- a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts +++ b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts @@ -18,12 +18,18 @@ import { } from '../'; import {dialogConfigHelper} from 'src/app/common/helpers'; import {Store} from '@ngrx/store'; -import {selectCurrentUserClaimsDeviceUsersDelete, selectCurrentUserClaimsDeviceUsersUpdate} from 'src/app/state'; +import { + selectAuthIsAdmin, + selectCurrentUserClaimsDeviceUsersDelete, + selectCurrentUserClaimsDeviceUsersUpdate +} from 'src/app/state'; import { selectPropertyWorkersNameFilters, selectPropertyWorkersPaginationIsSortDsc, selectPropertyWorkersPaginationSort } from '../../../../state'; +import {format} from "date-fns"; +import {AuthStateService} from "src/app/common/store"; @AutoUnsubscribe() @Component({ @@ -49,6 +55,7 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy { public selectPropertyWorkersPaginationSort$ = this.store.select(selectPropertyWorkersPaginationSort); public selectPropertyWorkersPaginationIsSortDsc$ = this.store.select(selectPropertyWorkersPaginationIsSortDsc); public selectPropertyWorkersNameFilters$ = this.store.select(selectPropertyWorkersNameFilters); + public selectAuthIsAdmin$ = this.store.select(selectAuthIsAdmin); get TaskWizardStatusesEnum() { return TaskWizardStatusesEnum; @@ -57,6 +64,7 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy { constructor( private store: Store, private translateService: TranslateService, + private authStateService: AuthStateService, public propertyWorkersStateService: PropertyWorkersStateService, private dialog: MatDialog, private overlay: Overlay,) { @@ -299,4 +307,8 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy { ngOnDestroy(): void { } + + getFormattedDate(date: Date) { + return format(date, 'P', {locale: this.authStateService.dateFnsLocale}); + } }