Skip to content

Commit

Permalink
[AC-1360] Add logic to automatically populate the reseller name field (
Browse files Browse the repository at this point in the history
…#3149)

* [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 0e72c14.

* Revert "[AC-1360] Added EF migration scripts"

This reverts commit a4ea5c4.

* Revert "[AC-1360] Added EF scripts for MySQL, Postgres and Sqlite"

This reverts commit 4b47d25.

* [AC-1360] Moved data migration file do data migration folder
  • Loading branch information
r-tome authored Aug 4, 2023
1 parent c479fe3 commit 222d576
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/Admin/Models/CreateProviderModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -26,6 +29,7 @@ public virtual Provider ToProvider()
return new Provider()
{
Type = Type,
Name = Name,
BusinessName = BusinessName,
BillingEmail = BillingEmail?.ToLowerInvariant().Trim()
};
Expand All @@ -38,19 +42,24 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
case ProviderType.Msp:
if (string.IsNullOrWhiteSpace(OwnerEmail))
{
var ownerEmailDisplayName = nameof(OwnerEmail).GetDisplayAttribute<CreateProviderModel>()?.GetName();
var ownerEmailDisplayName = nameof(OwnerEmail).GetDisplayAttribute<CreateProviderModel>()?.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<CreateProviderModel>()?.GetName() ?? nameof(Name);
yield return new ValidationResult($"The {nameDisplayName} field is required.");
}
if (string.IsNullOrWhiteSpace(BusinessName))
{
var businessNameDisplayName = nameof(BusinessName).GetDisplayAttribute<CreateProviderModel>()?.GetName();
var businessNameDisplayName = nameof(BusinessName).GetDisplayAttribute<CreateProviderModel>()?.GetName() ?? nameof(BusinessName);
yield return new ValidationResult($"The {businessNameDisplayName} field is required.");
}
if (string.IsNullOrWhiteSpace(BillingEmail))
{
var billingEmailDisplayName = nameof(BillingEmail).GetDisplayAttribute<CreateProviderModel>()?.GetName();
var billingEmailDisplayName = nameof(BillingEmail).GetDisplayAttribute<CreateProviderModel>()?.GetName() ?? nameof(BillingEmail);
yield return new ValidationResult($"The {billingEmailDisplayName} field is required.");
}
break;
Expand Down
12 changes: 8 additions & 4 deletions src/Admin/Views/Providers/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<form method="post">
<div asp-validation-summary="All" class="alert alert-danger"></div>

<div class="form-group">
<label asp-for="Type" class="h2"></label>
@foreach(ProviderType providerType in Enum.GetValues(typeof(ProviderType)))
Expand All @@ -31,17 +31,21 @@
</div>
}
</div>

<div id="@($"info-{(int)ProviderType.Msp}")" class="form-group @(Model.Type != ProviderType.Msp ? "d-none" : string.Empty)">
<h2>MSP Info</h2>
<div class="form-group">
<label asp-for="OwnerEmail"></label>
<input type="text" class="form-control" asp-for="OwnerEmail">
</div>
</div>

<div id="@($"info-{(int)ProviderType.Reseller}")" class="form-group @(Model.Type != ProviderType.Reseller ? "d-none" : string.Empty)">
<h2>Reseller Info</h2>
<div class="form-group">
<label asp-for="Name"></label>
<input type="text" class="form-control" asp-for="Name">
</div>
<div class="form-group">
<label asp-for="BusinessName"></label>
<input type="text" class="form-control" asp-for="BusinessName">
Expand All @@ -51,6 +55,6 @@
<input type="text" class="form-control" asp-for="BillingEmail">
</div>
</div>

<button type="submit" class="btn btn-primary mb-2">Create Provider</button>
</form>
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 222d576

Please sign in to comment.