Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AC-1360] Add logic to automatically populate the reseller name field #3149

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
Loading