Skip to content

Commit

Permalink
Fixed up the success messages in support of #455.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Apr 8, 2024
1 parent a91d5a5 commit dfd734f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
34 changes: 28 additions & 6 deletions NumberSearch.Ops/Controllers/OwnedNumbersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,8 @@ public async Task<IActionResult> ExportToCSV()
[ValidateAntiForgeryToken]
public async Task<IActionResult> GetAllSMSRoutesAndCarrierNamesAsync(string carrierName)
{
var result = new OwnedNumberResult
var result = new OwnedNumberResultForm
{
Message = $"❓Failed to export this CSV.",
AlertType = "alert-warning",
};

Expand All @@ -499,10 +498,9 @@ public async Task<IActionResult> GetAllSMSRoutesAndCarrierNamesAsync(string carr
if (!string.IsNullOrWhiteSpace(response.line_type_intelligence?.carrier_name))
{
// Update the owned number record
result.Message += $"✔️ {phoneNumber.DialedNumber} - Old: {number.TwilioCarrierName} - New: {response.line_type_intelligence.carrier_name.Trim()}\n";
number.TwilioCarrierName = response.line_type_intelligence.carrier_name.Trim();
await _context.SaveChangesAsync();
result.Message += $"✔️ Refreshed Carrier Name from Twilio! {number.TwilioCarrierName}\n";
}
await _context.SaveChangesAsync(); }
else
{
result.Message += $"❌ Twilio has no Carrier Name for this {phoneNumber.DialedNumber}.\n";
Expand Down Expand Up @@ -537,7 +535,31 @@ public async Task<IActionResult> GetAllSMSRoutesAndCarrierNamesAsync(string carr
}
}

// Show all orders
var ownedNumbers = await _context.OwnedPhoneNumbers.OrderByDescending(x => x.DialedNumber).AsNoTracking().ToListAsync();
var portedNumbers = await _context.PortedPhoneNumbers.ToArrayAsync();
var purchasedNumbers = await _context.PurchasedPhoneNumbers.ToArrayAsync();
var e911s = await _context.EmergencyInformation.ToArrayAsync();
var token = await GetTokenAsync();
var registeredNumbers = await $"{_config.MessagingURL}client/all"
.WithOAuthBearerToken(token.AccessToken)
.GetJsonAsync<ClientRegistration[]>();

return Redirect("/Home/OwnedNumbers");
var viewOrders = new List<OwnedNumberResult>();
foreach (var ownedNumber in ownedNumbers)
{
viewOrders.Add(new OwnedNumberResult
{
EmergencyInformation = e911s.FirstOrDefault(x => x.DialedNumber == ownedNumber.DialedNumber) ?? new(),
Owned = ownedNumber,
PortedPhoneNumbers = portedNumbers.Where(x => x.PortedDialedNumber == ownedNumber.DialedNumber).ToArray(),
PurchasedPhoneNumbers = purchasedNumbers.Where(x => x.DialedNumber == ownedNumber.DialedNumber).ToArray(),
ClientRegistration = registeredNumbers.FirstOrDefault(x => x.AsDialed == ownedNumber.DialedNumber) ?? new()
});
}

result.Results = [.. viewOrders];
result.Message = string.IsNullOrWhiteSpace(result.Message) ? $"❓Failed to query Twilio for {carrierName}" : result.Message;
return View("OwnedNumbers", result);
}
}
4 changes: 4 additions & 0 deletions NumberSearch.Ops/Models/OwnedNumberResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace NumberSearch.Ops
{
// For the edit single page
public class OwnedNumberResult
{
public OwnedPhoneNumber Owned { get; set; } = new();
Expand All @@ -23,9 +24,12 @@ public class OwnedNumberResult
public string LastName { get; set; } = string.Empty;
public string BusinessName { get; set; } = string.Empty;
}
// For the list all page
public class OwnedNumberResultForm
{
public OwnedNumberResult[] Results { get; set; } = [];
public string CarrierName { get; set; } = string.Empty;
public string Message { get; set; } = string.Empty;
public string AlertType { get; set; } = string.Empty;
}
}
16 changes: 16 additions & 0 deletions NumberSearch.Ops/Views/OwnedNumbers/OwnedNumbers.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
ViewData["Title"] = "Owned Phone Numbers";
}
<h1 class="display-4 p-3">🏢 Owned Numbers</h1>
@if (!string.IsNullOrWhiteSpace(Model?.Message))
{
if (string.IsNullOrWhiteSpace(Model?.AlertType))
{
<div class="alert alert-danger col-12" role="alert">
@Model?.Message
</div>
}
else
{
var alertType = Model?.AlertType ?? "alert-danger";
<div class="alert @alertType col-12" role="alert">
@Model?.Message
</div>
}
}
<form method="post" action="/OwnedNumbers/RouteAndCarrier">
<div class="row">
<div class="col-6">
Expand Down

0 comments on commit dfd734f

Please sign in to comment.