Skip to content

Commit

Permalink
Fixed a whole pile of warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Sep 30, 2024
1 parent 3c20339 commit 0d7ba59
Show file tree
Hide file tree
Showing 17 changed files with 463 additions and 450 deletions.
2 changes: 1 addition & 1 deletion NumberSearch.DataAccess/Models/PurchasedPhoneNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static async Task<IEnumerable<PurchasedPhoneNumber>> GetByOrderIdAsync(Gu
/// </summary>
/// <param name="connectionString"></param>
/// <returns></returns>
public static async Task<PurchasedPhoneNumber> GetByDialedNumberAsync(string dialedNumber, string connectionString)
public static async Task<PurchasedPhoneNumber?> GetByDialedNumberAsync(string dialedNumber, string connectionString)
{
await using var connection = new NpgsqlConnection(connectionString);

Expand Down
5 changes: 4 additions & 1 deletion NumberSearch.Ingest/Owned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ public async static Task<SMSRouteChange[]> IngestAsync(IngestConfiguration confi

// Remove the lock from the database to prevent it from getting cluttered with blank entries.
var lockEntry = await IngestStatistics.GetLockAsync("OwnedNumbers", configuration.Postgresql).ConfigureAwait(false);
_ = await lockEntry.DeleteAsync(configuration.Postgresql).ConfigureAwait(false);
if (lockEntry is not null)
{
_ = await lockEntry.DeleteAsync(configuration.Postgresql).ConfigureAwait(false);
}

// Remove all of the old numbers from the database.
Log.Information("[OwnedNumbers] Marking numbers that failed to reingest as inactive in the database.");
Expand Down
15 changes: 10 additions & 5 deletions NumberSearch.Ingest/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ public static async Task<IngestStatistics> BulkVSDailyAsync(IngestConfiguration
UpdatedExisting = 0,
Lock = true
};

var checkLock = await lockingStats.PostAsync(appConfig.Postgresql).ConfigureAwait(false);
_ = await lockingStats.PostAsync(appConfig.Postgresql).ConfigureAwait(false);

// Ingest all available phones numbers from the BulkVs API.
Log.Information("Ingesting data from BulkVS");
var BulkVSStats = await Provider.BulkVSAsync(appConfig.BulkVSUsername, appConfig.BulkVSPassword, PhoneNumbersNA.AreaCode.All, appConfig.Postgresql).ConfigureAwait(false);

// Remove the lock from the database to prevent it from getting cluttered with blank entries.
var lockEntry = await IngestStatistics.GetLockAsync("BulkVS", appConfig.Postgresql).ConfigureAwait(false);
var checkRemoveLock = await lockEntry.DeleteAsync(appConfig.Postgresql).ConfigureAwait(false);
if (lockEntry is not null)
{
_ = await lockEntry.DeleteAsync(appConfig.Postgresql).ConfigureAwait(false);
}

// Remove all of the old numbers from the database.
Log.Information("[BulkVS] Removing old numbers from the database.");
Expand Down Expand Up @@ -254,15 +256,18 @@ public static async Task<IngestStatistics> FirstPointComDailyAsync(IngestConfigu
Lock = true
};

var checkLock = await lockingStats.PostAsync(appConfig.Postgresql).ConfigureAwait(false);
_ = await lockingStats.PostAsync(appConfig.Postgresql).ConfigureAwait(false);

// Ingest all available numbers in the FirsPointCom API.
Log.Information("[FirstPointCom] Ingesting data from FirstPointCom");
var FirstPointComStats = await Provider.FirstPointComAsync(appConfig.PComNetUsername, appConfig.PComNetPassword, PhoneNumbersNA.AreaCode.All, appConfig.Postgresql).ConfigureAwait(false);

// Remove the lock from the database to prevent it from getting cluttered with blank entries.
var lockEntry = await IngestStatistics.GetLockAsync("FirstPointCom", appConfig.Postgresql).ConfigureAwait(false);
var checkRemoveLock = await lockEntry.DeleteAsync(appConfig.Postgresql).ConfigureAwait(false);
if (lockEntry is not null)
{
_ = await lockEntry.DeleteAsync(appConfig.Postgresql).ConfigureAwait(false);
}

// Remove all of the old numbers from the database.
Log.Information("[FirstPointCom] Removing old FirstPointCom numbers from the database.");
Expand Down
127 changes: 62 additions & 65 deletions NumberSearch.Mvc/Controllers/CartController.cs

Large diffs are not rendered by default.

30 changes: 11 additions & 19 deletions NumberSearch.Mvc/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,18 @@ namespace NumberSearch.Mvc.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]
[EnableRateLimiting("lookup")]
public class LookupController : Controller
public class LookupController(MvcConfiguration mvcConfiguration) : Controller
{
private readonly string _postgresql;
private readonly string _bulkVSKey;
private readonly string _bulkVSUsername;
private readonly string _bulkVSPassword;
private readonly string _callWithUsAPIkey;

public LookupController(MvcConfiguration mvcConfiguration)
{
_postgresql = mvcConfiguration.PostgresqlProd;
_bulkVSKey = mvcConfiguration.BulkVSAPIKEY;
_bulkVSUsername = mvcConfiguration.BulkVSUsername;
_bulkVSPassword = mvcConfiguration.BulkVSPassword;
_callWithUsAPIkey = mvcConfiguration.CallWithUsAPIKEY;
}
private readonly string _postgresql = mvcConfiguration.PostgresqlProd;
private readonly string _bulkVSKey = mvcConfiguration.BulkVSAPIKEY;
private readonly string _bulkVSUsername = mvcConfiguration.BulkVSUsername;
private readonly string _bulkVSPassword = mvcConfiguration.BulkVSPassword;
private readonly string _callWithUsAPIkey = mvcConfiguration.CallWithUsAPIKEY;

[HttpGet]
[DisableRateLimiting]
[ResponseCache(Duration = 30, Location = ResponseCacheLocation.Any, NoStore = false)]
public async Task<IActionResult> IndexAsync(string dialedNumber)
public IActionResult Index(string dialedNumber)
{
if (string.IsNullOrWhiteSpace(dialedNumber))
{
Expand Down Expand Up @@ -238,9 +229,10 @@ public async Task<PortedPhoneNumber> VerifyPortabilityAsync(string dialedNumber)
lectype = canada?.Prefix_Type ?? string.Empty,
city = canada?.Ratecenter ?? string.Empty,
province = canada?.State ?? string.Empty,
});

checkNumber.LosingCarrier = portable?.LosingCarrier ?? string.Empty;
})
{
LosingCarrier = portable?.LosingCarrier ?? string.Empty
};

// Warning this costs $$$$
var numberName = await CnamBulkVs.GetAsync(phoneNumber.DialedNumber ?? string.Empty, _bulkVSKey);
Expand Down
109 changes: 53 additions & 56 deletions NumberSearch.Mvc/Controllers/NewClientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
namespace NumberSearch.Mvc.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]
public class NewClientController : Controller
public class NewClientController(MvcConfiguration mvcConfiguration) : Controller
{
private readonly string _postgresql;
private readonly MvcConfiguration _mvcConfiguration;

public NewClientController(MvcConfiguration mvcConfiguration)
{
_postgresql = mvcConfiguration.PostgresqlProd;
_mvcConfiguration = mvcConfiguration;
}
private readonly string _postgresql = mvcConfiguration.PostgresqlProd;
private readonly MvcConfiguration _mvcConfiguration = mvcConfiguration;

[HttpGet("Cart/Order/{orderId}/NewClient")]
[ResponseCache(VaryByHeader = "User-Agent", Duration = 30, Location = ResponseCacheLocation.Any)]
Expand All @@ -33,69 +27,72 @@ public async Task<IActionResult> IndexAsync(Guid orderId)
var order = await Order.GetByIdAsync(orderId, _postgresql);
var productOrders = await ProductOrder.GetAsync(orderId, _postgresql).ConfigureAwait(false);
var products = await Product.GetAllAsync(_postgresql).ConfigureAwait(false);
var newClient = await NewClient.GetByOrderIdAsync(order.OrderId, _postgresql).ConfigureAwait(false);
NewClient newClient = await NewClient.GetByOrderIdAsync(order?.OrderId ?? new(), _postgresql).ConfigureAwait(false) ?? new();
var phoneNumbers = productOrders.Where(x => !string.IsNullOrWhiteSpace(x.DialedNumber))?.Select(x => x.DialedNumber)?.ToArray();
var portedNumbers = await PortedPhoneNumber.GetByOrderIdAsync(orderId, _postgresql).ConfigureAwait(false);
var portedStrippedNumbers = portedNumbers?.Select(x => x.PortedDialedNumber).ToArray();
var allNumbers = phoneNumbers?.Concat(portedStrippedNumbers ?? Array.Empty<string>())?.ToArray();
var allNumbers = phoneNumbers?.Concat(portedStrippedNumbers ?? [])?.ToArray();

if (newClient is null)
if (newClient is null && order?.OrderId is not null)
{
newClient = new NewClient { NewClientId = Guid.NewGuid(), OrderId = order.OrderId };
var checkCreate = await newClient.PostAsync(_postgresql).ConfigureAwait(false);

if (checkCreate)
{
newClient = await NewClient.GetByOrderIdAsync(order.OrderId, _postgresql).ConfigureAwait(false);
newClient = await NewClient.GetByOrderIdAsync(order.OrderId, _postgresql).ConfigureAwait(false) ?? new();
}
}

// Gather up all the childern
newClient.ExtensionRegistrations = await ExtensionRegistration.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.NumberDescriptions = await NumberDescription.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.IntercomRegistrations = await IntercomRegistration.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.SpeedDialKeys = await SpeedDialKey.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.FollowMeRegistrations = await FollowMeRegistration.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.PhoneMenuOptions = await PhoneMenuOption.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);

// There is info entered make sure the users sees it.
if (newClient.IntercomRegistrations.Any())
if (newClient is not null)
{
newClient.Intercom = true;
}
// Gather up all the childern
newClient.ExtensionRegistrations = await ExtensionRegistration.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.NumberDescriptions = await NumberDescription.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.IntercomRegistrations = await IntercomRegistration.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.SpeedDialKeys = await SpeedDialKey.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.FollowMeRegistrations = await FollowMeRegistration.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient.PhoneMenuOptions = await PhoneMenuOption.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);

if (!string.IsNullOrWhiteSpace(newClient.IntercomDescription))
{
newClient.Intercom = true;
}
// There is info entered make sure the users sees it.
if (newClient.IntercomRegistrations.Length != 0)
{
newClient.Intercom = true;
}

if (newClient.SpeedDialKeys.Any())
{
newClient.SpeedDial = true;
}
if (!string.IsNullOrWhiteSpace(newClient.IntercomDescription))
{
newClient.Intercom = true;
}

if (newClient.PhoneMenuOptions.Any())
{
newClient.PhoneMenu = true;
}
if (newClient.SpeedDialKeys.Length != 0)
{
newClient.SpeedDial = true;
}

if (!string.IsNullOrWhiteSpace(newClient.TextingServiceName))
{
newClient.TextingService = true;
}
if (newClient.PhoneMenuOptions.Length != 0)
{
newClient.PhoneMenu = true;
}

if (!string.IsNullOrWhiteSpace(newClient.OverheadPagingDescription))
{
newClient.OverheadPaging = true;
if (!string.IsNullOrWhiteSpace(newClient.TextingServiceName))
{
newClient.TextingService = true;
}

if (!string.IsNullOrWhiteSpace(newClient.OverheadPagingDescription))
{
newClient.OverheadPaging = true;
}
}

var form = new NewClientResult
{
Order = order,
NewClient = newClient,
ProductOrders = productOrders.ToArray(),
Products = products.ToArray(),
PhoneNumbers = allNumbers ?? Array.Empty<string>(),
Order = order ?? new(),
NewClient = newClient ?? new(),
ProductOrders = [.. productOrders],
Products = [.. products],
PhoneNumbers = allNumbers ?? [],
};

return View("Index", form);
Expand Down Expand Up @@ -161,7 +158,7 @@ public async Task<IActionResult> SubmitNewClientAsync(NewClient newClient)

if (checkUpdate)
{
newClient = await NewClient.GetAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient = await NewClient.GetAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false) ?? new();
}
}
else
Expand All @@ -170,7 +167,7 @@ public async Task<IActionResult> SubmitNewClientAsync(NewClient newClient)

if (checkCreate)
{
newClient = await NewClient.GetAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);
newClient = await NewClient.GetAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false) ?? new();
}
}

Expand All @@ -183,7 +180,7 @@ public async Task<IActionResult> SubmitNewClientAsync(NewClient newClient)
newClient.PhoneMenuOptions = await PhoneMenuOption.GetByNewClientAsync(newClient.NewClientId, _postgresql).ConfigureAwait(false);

// There is info entered make sure the users sees it.
if (newClient.IntercomRegistrations.Any())
if (newClient.IntercomRegistrations.Length != 0)
{
newClient.Intercom = true;
}
Expand All @@ -193,12 +190,12 @@ public async Task<IActionResult> SubmitNewClientAsync(NewClient newClient)
newClient.Intercom = true;
}

if (newClient.SpeedDialKeys.Any())
if (newClient.SpeedDialKeys.Length != 0)
{
newClient.SpeedDial = true;
}

if (newClient.PhoneMenuOptions.Any())
if (newClient.PhoneMenuOptions.Length != 0)
{
newClient.PhoneMenu = true;
}
Expand All @@ -218,9 +215,9 @@ public async Task<IActionResult> SubmitNewClientAsync(NewClient newClient)
var phoneNumbers = productOrders.Where(x => !string.IsNullOrWhiteSpace(x.DialedNumber))?.Select(x => x.DialedNumber)?.ToArray();
var portedNumbers = await PortedPhoneNumber.GetByOrderIdAsync(newClient.OrderId, _postgresql).ConfigureAwait(false);
var portedStrippedNumbers = portedNumbers?.Select(x => x.PortedDialedNumber).ToArray();
var allNumbers = phoneNumbers?.Concat(portedStrippedNumbers ?? Array.Empty<string>())?.ToArray();
var allNumbers = phoneNumbers?.Concat(portedStrippedNumbers ?? [])?.ToArray();

return View("Index", new NewClientResult { NewClient = newClient, Order = order, Products = products.ToArray(), ProductOrders = productOrders.ToArray(), PhoneNumbers = allNumbers ?? Array.Empty<string>() });
return View("Index", new NewClientResult { NewClient = newClient, Order = order, Products = [..products], ProductOrders = [..productOrders], PhoneNumbers = allNumbers ?? [] });
}

return View("Index");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand Down Expand Up @@ -49,7 +51,7 @@ public async Task<IActionResult> OnPostAsync()
personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey);
}

Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
Response.Headers.Append("Content-Disposition", "attachment; filename=PersonalData.json");
return new FileContentResult(JsonSerializer.SerializeToUtf8Bytes(personalData), "application/json");
}
}
Expand Down
13 changes: 8 additions & 5 deletions NumberSearch.Ops/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<IActionResult> NumbersToVerify(Guid? orderId)
{
var orders = await _context.VerifiedPhoneNumbers.Where(x => x.OrderId == orderId).AsNoTracking().ToListAsync();

if (orders is not null && orders.Any())
if (orders is not null && orders.Count != 0)
{
foreach (var order in orders)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task<IActionResult> ShipmentsAsync(Guid? ProductShipmentId)

if (checkExists is not null)
{
return View("Shipments", new InventoryResult { Products = products, ProductShipments = new ProductShipment[] { checkExists }, Shipment = checkExists });
return View("Shipments", new InventoryResult { Products = products, ProductShipments = [checkExists], Shipment = checkExists });
}
else
{
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task<IActionResult> ProductsAsync(Guid? ProductId)
{
var products = await _context.Products.AsNoTracking().FirstOrDefaultAsync(x => x.ProductId == ProductId);

return View("Products", new InventoryResult { Products = new Product[] { products ?? new() }, Product = products ?? new() });
return View("Products", new InventoryResult { Products = [products ?? new()], Product = products ?? new() });
}
}

Expand Down Expand Up @@ -280,7 +280,7 @@ public async Task<IActionResult> Coupons(Guid? couponId)
// Show all orders
var result = await _context.Coupons.Where(x => x.CouponId == couponId).FirstOrDefaultAsync();

return View("Coupons", new CouponResult { Coupon = result ?? new(), Coupons = new Coupon[] { result ?? new Coupon() } });
return View("Coupons", new CouponResult { Coupon = result ?? new(), Coupons = [result ?? new Coupon()] });
}
}

Expand Down Expand Up @@ -414,7 +414,10 @@ public async Task<IActionResult> ResendEmails(Guid orderId, Guid emailId)
response.AlertType = "alert-danger";
}

response.Emails = await _context.SentEmails.Where(x => x.OrderId == email.OrderId).ToArrayAsync();
if (email?.OrderId is not null)
{
response.Emails = await _context.SentEmails.Where(x => x.OrderId == email.OrderId).ToArrayAsync();
}
}
catch (Exception ex)
{
Expand Down
Loading

0 comments on commit 0d7ba59

Please sign in to comment.