Skip to content

Commit

Permalink
Cleaned up a bunch of UX bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Apr 13, 2024
1 parent 7c5e0b3 commit 3dc2cd9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 152 deletions.
82 changes: 61 additions & 21 deletions NumberSearch.Ops/Controllers/MessagingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

using Models;

using NuGet.Common;

using NumberSearch.DataAccess.Twilio;
using NumberSearch.Ops.Models;

Expand Down Expand Up @@ -67,26 +69,7 @@ public async Task<IActionResult> IndexAsync()
var token = await GetTokenAsync();
var stats = await $"{_baseUrl}client/all".WithOAuthBearerToken(token.AccessToken).GetJsonAsync<ClientRegistration[]>();
var ownedNumbers = await _context.OwnedPhoneNumbers.ToArrayAsync();
//bool refresh = false;
//foreach (var number in stats)
//{
// if (number.RegisteredUpstream is false && number.AsDialed is not "Total")
// {
// bool checkParse = PhoneNumbersNA.PhoneNumber.TryParse(number.AsDialed, out var phoneNumber);
// if (checkParse && phoneNumber is not null && !string.IsNullOrWhiteSpace(phoneNumber.DialedNumber))
// {
// _ = await $"{_baseUrl}client?asDialed={phoneNumber.DialedNumber}".WithOAuthBearerToken(_messagingToken).GetStringAsync();
// refresh = true;
// }
// }
//}

//if (refresh)
//{
// stats = await $"{_baseUrl}client/all".WithOAuthBearerToken(_messagingToken).GetJsonAsync<ClientRegistration[]>();
//}

return View(new MessagingResult { ClientRegistrations = stats.OrderByDescending(x => x.DateRegistered).ToArray(), Owned = ownedNumbers });
return View(new MessagingResult { ClientRegistrations = [.. stats.OrderByDescending(x => x.DateRegistered)], Owned = ownedNumbers });
}

[Authorize]
Expand Down Expand Up @@ -420,7 +403,7 @@ public async Task<IActionResult> TwilioCarrierAsync(string dialedNumber, bool? r

var stats = await $"{_baseUrl}client/all".WithOAuthBearerToken(token.AccessToken).GetJsonAsync<ClientRegistration[]>();
var ownedNumbers = await _context.OwnedPhoneNumbers.ToArrayAsync();
result.ClientRegistrations = stats.OrderByDescending(x => x.DateRegistered).ToArray();
result.ClientRegistrations = [.. stats.OrderByDescending(x => x.DateRegistered)];
result.Owned = ownedNumbers;
return View("Index", result);
}
Expand Down Expand Up @@ -479,5 +462,62 @@ public async Task<IActionResult> ExportToCSV()
result.Owned = ownedNumbers;
return View("Index", result);
}

[Authorize]
[Route("/Messaging/RefreshCarrier")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> GetCarrierNamesAsync(string carrierName)
{
var result = new MessagingResult { AlertType = "alert-success" };

var existing = await _context.OwnedPhoneNumbers.Where(x => x.Active && x.TwilioCarrierName == carrierName).ToArrayAsync();

if (carrierName is "All")
{
existing = await _context.OwnedPhoneNumbers.Where(x => x.Active).ToArrayAsync();
}

foreach (var number in existing)
{
bool checkParse = PhoneNumbersNA.PhoneNumber.TryParse(number.DialedNumber, out var phoneNumber);
if (checkParse && phoneNumber is not null)
{
try
{
var response = await LineTypeIntelligenceResponse.GetByDialedNumberAsync(phoneNumber.DialedNumber, _config.TwilioUsername, _config.TwilioPassword);
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();
}
else
{
result.Message += $"❌ Twilio has no Carrier Name for this {phoneNumber.DialedNumber}.\n";
}
}
catch (FlurlHttpException ex)
{
result.Message += $"❓Failed to query Twilio. {await ex.GetResponseStringAsync()}\n";
result.AlertType = "alert-warning";
}
catch (Exception ex)
{
result.Message += $"{ex.Message} {ex.StackTrace}\n";
result.AlertType = "alert-danger";
}
}
}

var token = await GetTokenAsync();
var stats = await $"{_baseUrl}client/all".WithOAuthBearerToken(token.AccessToken).GetJsonAsync<ClientRegistration[]>();
var ownedNumbers = await _context.OwnedPhoneNumbers.ToArrayAsync();
result.ClientRegistrations = [.. stats.OrderByDescending(x => x.DateRegistered)];
result.Owned = ownedNumbers;
result.Message = string.IsNullOrWhiteSpace(result.Message) ? $"❓Failed to query Twilio for {carrierName}" : result.Message;
return View("Index", result);
}
}
}
94 changes: 0 additions & 94 deletions NumberSearch.Ops/Controllers/OwnedNumbersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,98 +468,4 @@ public async Task<IActionResult> ExportToCSV()

return Redirect("/Home/OwnedNumbers");
}

[Authorize]
[Route("/OwnedNumbers/RouteAndCarrier")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> GetAllSMSRoutesAndCarrierNamesAsync(string carrierName)
{
var result = new OwnedNumberResultForm
{
AlertType = "alert-warning",
};

var existing = await _context.OwnedPhoneNumbers.Where(x => x.Active && x.TwilioCarrierName == carrierName).ToArrayAsync();

if (carrierName is "All")
{
existing = await _context.OwnedPhoneNumbers.Where(x => x.Active).ToArrayAsync();
}

foreach (var number in existing)
{
bool checkParse = PhoneNumbersNA.PhoneNumber.TryParse(number.DialedNumber, out var phoneNumber);
if (checkParse && phoneNumber is not null)
{
try
{
var response = await LineTypeIntelligenceResponse.GetByDialedNumberAsync(phoneNumber.DialedNumber, _config.TwilioUsername, _config.TwilioPassword);
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(); }
else
{
result.Message += $"❌ Twilio has no Carrier Name for this {phoneNumber.DialedNumber}.\n";
}
}
catch (FlurlHttpException ex)
{
result.Message += $"❓Failed to query Twilio. {await ex.GetResponseStringAsync()}\n";
result.AlertType = "alert-warning";
}
catch (Exception ex)
{
result.Message += $"{ex.Message} {ex.StackTrace}\n";
result.AlertType = "alert-danger";
}

//try
//{
// // At Finns request NANPA numbers are now 1 prefixed to match with the POST client/register endpoint.
// string dialedNumber = phoneNumber.Type is not PhoneNumbersNA.NumberType.ShortCode ? $"1{phoneNumber.DialedNumber}" : phoneNumber.DialedNumber;

// // Verify that this number is routed through our upstream provider.
// var checkRouted = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber, _config.PComNetUsername, _config.PComNetPassword);
// number.SMSRoute = checkRouted.route;
// await _context.SaveChangesAsync();
//}
//catch (Exception ex)
//{
// number.SMSRoute = "Couldn't get SMS route.";
// await _context.SaveChangesAsync();
//}
}
}

// 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[]>();

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);
}
}
14 changes: 7 additions & 7 deletions NumberSearch.Ops/Pages/Orders.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@
</td>
<td>
<strong class="d-xl-none">Customer Name</strong>
<p>
<p class="m-0">
@order?.Order?.FirstName
@order?.Order?.LastName
<a href="mailto:@order?.Order?.Email" target="_blank">
@order?.Order?.Email
</a>
@order?.Order?.ContactPhoneNumber
</p>
<p class="m-0">
<a href="mailto:@order?.Order?.Email" target="_blank">@order?.Order?.Email</a>
</p>
<p class="m-0">@order?.Order?.ContactPhoneNumber</p>
<div class="d-xl-none">
<strong>Address</strong>
<p>
Expand Down Expand Up @@ -374,7 +374,7 @@
if (!string.IsNullOrWhiteSpace(order?.Order?.CustomerNotes))
{
<strong>Customer Notes</strong>
<p>@order.Order.CustomerNotes</p>
<p class="text-break">@order.Order.CustomerNotes</p>
}
}
</td>
Expand Down Expand Up @@ -544,7 +544,7 @@
</span>
}
</p>
<p>
<p class="text-break">
@order?.Order?.FirstName
@order?.Order?.LastName
<a href="mailto:@order?.Order?.Email" target="_blank" rel="noopener noreferrer">
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Ops/Views/Home/Emails.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</td>
<td>
<strong>Body</strong>
<p>@Html.Raw(email.MessageBody)</p>
<p class="text-break">@Html.Raw(email.MessageBody)</p>
</td>
<td>
@{
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Ops/Views/Messaging/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</table>
</div>
<div class="row">
<form method="post" action="/OwnedNumbers/RouteAndCarrier">
<form method="post" action="/Messaging/RefreshCarrier">
<div class="col-6">
<div class="input-group mb-3">
@Html.AntiForgeryToken()
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Ops/Views/Orders/Orders.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
if (!string.IsNullOrWhiteSpace(order?.Order?.CustomerNotes))
{
<strong>Customer Notes</strong>
<p>@order.Order.CustomerNotes</p>
<p class="text-break">@order.Order.CustomerNotes</p>
}
}
</td>
Expand Down
4 changes: 2 additions & 2 deletions NumberSearch.Ops/Views/Orders/Quotes.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
@{
var portedNumbersForLookups = ported.Select(x => x.PortedDialedNumber).ToArray();
var lookupParameter = string.Join(",", portedNumbersForLookups);
<a class="btn btn-outline-primary mt-1" href="https://acceleratenetworks.com/Lookup?dialedNumber=@lookupParameter" target="_blank">View all in Lookups</a>
<a class="btn btn-outline-success mt-1" href="https://acceleratenetworks.com/Lookup?dialedNumber=@lookupParameter" target="_blank">View all in Lookups</a>
foreach (var product in ported)
{
var matchingPortedPhoneNumber = Model?.PortedPhoneNumbers?.Where(x => x?.OrderId == order?.Order?.OrderId && x?.PortedDialedNumber == product?.PortedDialedNumber || x?.PortedPhoneNumberId == product?.PortedPhoneNumberId).FirstOrDefault();
Expand Down Expand Up @@ -223,7 +223,7 @@
if (!string.IsNullOrWhiteSpace(order?.Order?.CustomerNotes))
{
<strong>Customer Notes</strong>
<p>@order.Order.CustomerNotes</p>
<p class="text-break">@order.Order.CustomerNotes</p>
}
}
</td>
Expand Down
Loading

0 comments on commit 3dc2cd9

Please sign in to comment.