From 222d57622ee5675d64e6984d6ac79c6ff4524947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Fri, 4 Aug 2023 17:47:03 +0100 Subject: [PATCH] [AC-1360] Add logic to automatically populate the reseller name field (#3149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [AC-1360] Added Name field to view for creating a Reseller Provider * [AC-1360] Added migration script to populate existing Reseller Provider names with value from BusinessName * [AC-1360] Added fallback when retrieving display attribute name value * [AC-1360] Added EF scripts for MySQL, Postgres and Sqlite * [AC-1360] Added EF migration scripts * [AC-1360] Changed down migrator methods to empty * Revert "[AC-1360] Changed down migrator methods to empty" This reverts commit 0e72c14d2fad011d4be002a765682446e65de79c. * Revert "[AC-1360] Added EF migration scripts" This reverts commit a4ea5c4dca2e2fef2f678c21188531c54da0d3ea. * Revert "[AC-1360] Added EF scripts for MySQL, Postgres and Sqlite" This reverts commit 4b47d257556b5059167cbc58f6c624158783aae4. * [AC-1360] Moved data migration file do data migration folder --- src/Admin/Models/CreateProviderModel.cs | 15 ++++++++++++--- src/Admin/Views/Providers/Create.cshtml | 12 ++++++++---- .../2023-08-03_00_PopulateResellerNames.sql | 5 +++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 util/Migrator/DbScripts_data_migration/2023-08-03_00_PopulateResellerNames.sql diff --git a/src/Admin/Models/CreateProviderModel.cs b/src/Admin/Models/CreateProviderModel.cs index a9a2f4ac4391..9dcd218fa625 100644 --- a/src/Admin/Models/CreateProviderModel.cs +++ b/src/Admin/Models/CreateProviderModel.cs @@ -15,6 +15,9 @@ public CreateProviderModel() { } [Display(Name = "Owner Email")] public string OwnerEmail { get; set; } + [Display(Name = "Name")] + public string Name { get; set; } + [Display(Name = "Business Name")] public string BusinessName { get; set; } @@ -26,6 +29,7 @@ public virtual Provider ToProvider() return new Provider() { Type = Type, + Name = Name, BusinessName = BusinessName, BillingEmail = BillingEmail?.ToLowerInvariant().Trim() }; @@ -38,19 +42,24 @@ public IEnumerable Validate(ValidationContext validationContex case ProviderType.Msp: if (string.IsNullOrWhiteSpace(OwnerEmail)) { - var ownerEmailDisplayName = nameof(OwnerEmail).GetDisplayAttribute()?.GetName(); + var ownerEmailDisplayName = nameof(OwnerEmail).GetDisplayAttribute()?.GetName() ?? nameof(OwnerEmail); yield return new ValidationResult($"The {ownerEmailDisplayName} field is required."); } break; case ProviderType.Reseller: + if (string.IsNullOrWhiteSpace(Name)) + { + var nameDisplayName = nameof(Name).GetDisplayAttribute()?.GetName() ?? nameof(Name); + yield return new ValidationResult($"The {nameDisplayName} field is required."); + } if (string.IsNullOrWhiteSpace(BusinessName)) { - var businessNameDisplayName = nameof(BusinessName).GetDisplayAttribute()?.GetName(); + var businessNameDisplayName = nameof(BusinessName).GetDisplayAttribute()?.GetName() ?? nameof(BusinessName); yield return new ValidationResult($"The {businessNameDisplayName} field is required."); } if (string.IsNullOrWhiteSpace(BillingEmail)) { - var billingEmailDisplayName = nameof(BillingEmail).GetDisplayAttribute()?.GetName(); + var billingEmailDisplayName = nameof(BillingEmail).GetDisplayAttribute()?.GetName() ?? nameof(BillingEmail); yield return new ValidationResult($"The {billingEmailDisplayName} field is required."); } break; diff --git a/src/Admin/Views/Providers/Create.cshtml b/src/Admin/Views/Providers/Create.cshtml index 2263da06e1c9..107e93150b41 100644 --- a/src/Admin/Views/Providers/Create.cshtml +++ b/src/Admin/Views/Providers/Create.cshtml @@ -17,7 +17,7 @@
- +
@foreach(ProviderType providerType in Enum.GetValues(typeof(ProviderType))) @@ -31,7 +31,7 @@
} - +

MSP Info

@@ -39,9 +39,13 @@
- +

Reseller Info

+
+ + +
@@ -51,6 +55,6 @@
- +
diff --git a/util/Migrator/DbScripts_data_migration/2023-08-03_00_PopulateResellerNames.sql b/util/Migrator/DbScripts_data_migration/2023-08-03_00_PopulateResellerNames.sql new file mode 100644 index 000000000000..b5eb0b9aa3e5 --- /dev/null +++ b/util/Migrator/DbScripts_data_migration/2023-08-03_00_PopulateResellerNames.sql @@ -0,0 +1,5 @@ +-- Reseller Providers were being created with a NULL value in the [Name] column. +-- This script will populate them with the value from [BusinessName] which was already required. +UPDATE [dbo].[Provider] +SET [Name] = [BusinessName] +WHERE [Name] IS NULL