From ff9d9ae3c5c2880227f5c4cfce923da99cbeba4d Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Sat, 1 Jul 2023 12:51:39 +0200 Subject: [PATCH] WIP system user create web shop user --- .../AdvisorActivityListComponent.razor | 2 +- .../AdvisorCustomerListComponent.razor | 4 +- .../OfficeCountryCustomerListComponent.razor | 4 +- .../OfficeReportActivityListComponent.razor | 2 +- .../ReportViewActivityListComponent.razor | 2 +- Wonky.Client/Helpers/MapUtils.cs | 43 ----- Wonky.Client/Helpers/Mapper.cs | 93 +++++++++- Wonky.Client/Helpers/Utils.cs | 93 +--------- Wonky.Client/Models/NewUserForm.cs | 11 +- .../OverlaySystem/CustomerSearchOverlay.razor | 4 +- .../AdvisorCustomerViewEditPage.razor.cs | 2 +- Wonky.Client/Pages/SystemUserCreatePage.razor | 161 ++++++++++-------- .../Pages/SystemUserCreatePage.razor.cs | 28 +-- .../Pages/SystemUserViewEditPage.razor.cs | 4 +- 14 files changed, 217 insertions(+), 236 deletions(-) delete mode 100644 Wonky.Client/Helpers/MapUtils.cs diff --git a/Wonky.Client/Components/AdvisorActivityListComponent.razor b/Wonky.Client/Components/AdvisorActivityListComponent.razor index 5b67d98a..a997b4bd 100644 --- a/Wonky.Client/Components/AdvisorActivityListComponent.razor +++ b/Wonky.Client/Components/AdvisorActivityListComponent.razor @@ -60,7 +60,7 @@ @if (activity.Lines.Any() && activity.StatusTypeEnum == "Order") { - + } @activity.ESalesNumber diff --git a/Wonky.Client/Components/AdvisorCustomerListComponent.razor b/Wonky.Client/Components/AdvisorCustomerListComponent.razor index fd811f77..1aaefb1d 100644 --- a/Wonky.Client/Components/AdvisorCustomerListComponent.razor +++ b/Wonky.Client/Components/AdvisorCustomerListComponent.razor @@ -36,10 +36,10 @@ { - + - + @if (!string.IsNullOrWhiteSpace(company.Note)) diff --git a/Wonky.Client/Components/OfficeCountryCustomerListComponent.razor b/Wonky.Client/Components/OfficeCountryCustomerListComponent.razor index 3e7da759..af0dd978 100644 --- a/Wonky.Client/Components/OfficeCountryCustomerListComponent.razor +++ b/Wonky.Client/Components/OfficeCountryCustomerListComponent.razor @@ -59,13 +59,13 @@ Sidst besøgt - @(Utils.MapVisitState(company.LastVisit) == "the-draw" ? "?" : company.LastVisit) + @(Mapper.MapVisitState(company.LastVisit) == "the-draw" ? "?" : company.LastVisit) Næste besøg - @(Utils.MapVisitState(company.LastVisit) == "the-draw" ? "?" : company.NextVisit) + @(Mapper.MapVisitState(company.LastVisit) == "the-draw" ? "?" : company.NextVisit) diff --git a/Wonky.Client/Components/OfficeReportActivityListComponent.razor b/Wonky.Client/Components/OfficeReportActivityListComponent.razor index 0d5633f2..dbd6c949 100644 --- a/Wonky.Client/Components/OfficeReportActivityListComponent.razor +++ b/Wonky.Client/Components/OfficeReportActivityListComponent.razor @@ -60,7 +60,7 @@ @if (activity.Lines.Any() && activity.StatusTypeEnum == "Order") { - + } diff --git a/Wonky.Client/Components/ReportViewActivityListComponent.razor b/Wonky.Client/Components/ReportViewActivityListComponent.razor index 1fb1fe3f..dec2e9d0 100644 --- a/Wonky.Client/Components/ReportViewActivityListComponent.razor +++ b/Wonky.Client/Components/ReportViewActivityListComponent.razor @@ -60,7 +60,7 @@ @if (activity.Lines.Any() && activity.StatusTypeEnum == "Order") { - + } diff --git a/Wonky.Client/Helpers/MapUtils.cs b/Wonky.Client/Helpers/MapUtils.cs deleted file mode 100644 index 205a87c3..00000000 --- a/Wonky.Client/Helpers/MapUtils.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 FCS Frede's Computer Services. -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] -// - -using Wonky.Client.Models; -using Wonky.Entity.DTO; - -namespace Wonky.Client.Helpers; - -public class MapUtils -{ - public static ManagerNewUserDto MapCreateUser(NewUserForm model) - { - return new ManagerNewUserDto - { - Description = model.Description, - Email = model.Email, - Passwd = model.NewPassword, - AssignedRoles = model.AssignedRoles, - CompanyId = model.CompanyId, - CountryCode = model.CountryCode, - EmailConfirmed = true, - EShop = model.EShop, - FirstName = model.FirstName, - LastName = model.LastName, - LockoutEnabled = false, - PhoneNumber = model.PhoneNumber, - SalesRep = model.SalesRep, - UserId = "" - }; - } -} \ No newline at end of file diff --git a/Wonky.Client/Helpers/Mapper.cs b/Wonky.Client/Helpers/Mapper.cs index b03d44bd..589645f7 100644 --- a/Wonky.Client/Helpers/Mapper.cs +++ b/Wonky.Client/Helpers/Mapper.cs @@ -12,7 +12,7 @@ public class Mapper { Description = model.Description, Email = model.Email, - Passwd = model.NewPassword, + Passwd = model.PasswordInput.NewPassword, AssignedRoles = model.AssignedRoles, CompanyId = model.CompanyId, CountryCode = model.CountryCode, @@ -26,4 +26,95 @@ public class Mapper UserId = "" }; } + + public static string MapOrgState(int validVat) + { + return validVat == 0 ? "no-vat" : "the-good"; + } + + + public static string MapVisitState(string dtNextVisit) + { + if (dtNextVisit is "0001-01-01" or "1970-01-01" or "2010-01-01" or "2020-01-01") + return "the-draw"; + if (!DateTime.TryParse(dtNextVisit, out _)) + return "the-draw"; + + var dtNow = DateTime.Now; + var dtNext = DateTime.Parse(dtNextVisit); + if (dtNow > dtNext) + return "the-ugly"; + + return dtNow > dtNext.AddDays(-14) ? "the-bad" : "the-good"; + } + + + public static string MapProcessStatus(string processStatus) + { + return processStatus.ToLower() switch + { + "express" => "the-fast", + "none" => "the-good", + "picked" => "the-bad", + "packed" => "the-ugly", + "shipped" => "the-dead", + "printed" => "printed", + _ => "question" + }; + } + + + public static List MapSaveAssignedRoles(RoleAssignment model) + { + return new List() + { + new() { Name = "Admin", Assigned = model.Admin }, + new() { Name = "Advisor", Assigned = model.Advisor }, + new() { Name = "EDoc", Assigned = model.EDoc }, + new() { Name = "EShop", Assigned = model.EShop }, + new() { Name = "Management", Assigned = model.Management }, + new() { Name = "Office", Assigned = model.Office }, + new() { Name = "Supervisor", Assigned = model.Supervisor }, + new() { Name = "Warehouse", Assigned = model.Warehouse } + }; + } + + + public static RoleAssignment MapEditAssignedRoles(UserManagerEditView model) + { + var x = new RoleAssignment(); + foreach (var role in model.AssignedRoles) + { + switch (role.Name.ToLower()) + { + case "admin": + x.Admin = role.Assigned; + break; + case "advisor": + x.Advisor = role.Assigned; + break; + case "edoc": + x.EDoc = role.Assigned; + break; + case "eshop": + x.EShop = role.Assigned; + break; + case "management": + x.Management = role.Assigned; + break; + case "office": + x.Office = role.Assigned; + break; + case "supervisor": + x.Supervisor = role.Assigned; + break; + case "warehouse": + x.Warehouse = role.Assigned; + break; + } + } + + return x; + } + } \ No newline at end of file diff --git a/Wonky.Client/Helpers/Utils.cs b/Wonky.Client/Helpers/Utils.cs index 7bdd00fb..29aced9e 100644 --- a/Wonky.Client/Helpers/Utils.cs +++ b/Wonky.Client/Helpers/Utils.cs @@ -157,61 +157,7 @@ public static class Utils }).ToList(); } - - public static List MapSaveAssignedRoles(RoleAssignment model) - { - return new List() - { - new() { Name = "Admin", Assigned = model.Admin }, - new() { Name = "Advisor", Assigned = model.Advisor }, - new() { Name = "EDoc", Assigned = model.EDoc }, - new() { Name = "EShop", Assigned = model.EShop }, - new() { Name = "Management", Assigned = model.Management }, - new() { Name = "Office", Assigned = model.Office }, - new() { Name = "Supervisor", Assigned = model.Supervisor }, - new() { Name = "Warehouse", Assigned = model.Warehouse } - }; - } - - - public static RoleAssignment MapEditAssignedRoles(UserManagerEditView model) - { - var x = new RoleAssignment(); - foreach (var role in model.AssignedRoles) - { - switch (role.Name.ToLower()) - { - case "admin": - x.Admin = role.Assigned; - break; - case "advisor": - x.Advisor = role.Assigned; - break; - case "edoc": - x.EDoc = role.Assigned; - break; - case "eshop": - x.EShop = role.Assigned; - break; - case "management": - x.Management = role.Assigned; - break; - case "office": - x.Office = role.Assigned; - break; - case "supervisor": - x.Supervisor = role.Assigned; - break; - case "warehouse": - x.Warehouse = role.Assigned; - break; - } - } - - return x; - } - - + public static string StringToDigits(string digitString) { if (string.IsNullOrWhiteSpace(digitString)) @@ -332,41 +278,4 @@ public static class Utils { return DateTime.Now.ToFileTimeUtc().GetHashCode(); } - - - public static string MapOrgState(int validVat) - { - return validVat == 0 ? "no-vat" : "the-good"; - } - - - public static string MapVisitState(string dtNextVisit) - { - if (dtNextVisit is "0001-01-01" or "1970-01-01" or "2010-01-01" or "2020-01-01") - return "the-draw"; - if (!DateTime.TryParse(dtNextVisit, out _)) - return "the-draw"; - - var dtNow = DateTime.Now; - var dtNext = DateTime.Parse(dtNextVisit); - if (dtNow > dtNext) - return "the-ugly"; - - return dtNow > dtNext.AddDays(-14) ? "the-bad" : "the-good"; - } - - - public static string MapProcessStatus(string processStatus) - { - return processStatus.ToLower() switch - { - "express" => "the-fast", - "none" => "the-good", - "picked" => "the-bad", - "packed" => "the-ugly", - "shipped" => "the-dead", - "printed" => "printed", - _ => "question" - }; - } } \ No newline at end of file diff --git a/Wonky.Client/Models/NewUserForm.cs b/Wonky.Client/Models/NewUserForm.cs index 56262ff3..90761148 100644 --- a/Wonky.Client/Models/NewUserForm.cs +++ b/Wonky.Client/Models/NewUserForm.cs @@ -30,11 +30,11 @@ public class NewUserForm public bool LockoutEnabled { get; set; } - [Required(ErrorMessage = "AdgangsKode skal udfyldes")] - public string NewPassword { get; set; } = ""; - - [Compare(nameof(NewPassword), ErrorMessage = "Adgangskoder er ikke ens.")] - public string ConfirmPassword { get; set; } = ""; + // [Required(ErrorMessage = "AdgangsKode skal udfyldes")] + // public string NewPassword { get; set; } = ""; + // + // [Compare(nameof(NewPassword), ErrorMessage = "Adgangskoder er ikke ens.")] + // public string ConfirmPassword { get; set; } = ""; [MaxLength(20, ErrorMessage = "Der er afsat 20 tegn til telefon nummber")] public string PhoneNumber { get; set; } = ""; @@ -43,4 +43,5 @@ public class NewUserForm public string SalesRep { get; set; } = ""; public List AssignedRoles { get; set; } = new(); + public PasswordInput PasswordInput { get; set; } = new(); } \ No newline at end of file diff --git a/Wonky.Client/OverlaySystem/CustomerSearchOverlay.razor b/Wonky.Client/OverlaySystem/CustomerSearchOverlay.razor index 59373a46..81189687 100644 --- a/Wonky.Client/OverlaySystem/CustomerSearchOverlay.razor +++ b/Wonky.Client/OverlaySystem/CustomerSearchOverlay.razor @@ -18,8 +18,8 @@