MRB webassembly

This commit is contained in:
Chase Tucker
2024-05-13 14:33:27 -07:00
parent ba8d92ea01
commit 9b7e3ef897
109 changed files with 11731 additions and 1024 deletions

View File

@ -0,0 +1,44 @@
using System.Text.Json;
namespace MesaFabApproval.Client.Services;
public interface ICAService {
Task<bool> CANumberIsValid(int number);
}
public class CAService : ICAService {
private readonly IHttpClientFactory _httpClientFactory;
public CAService(IHttpClientFactory httpClientFactory) {
_httpClientFactory = httpClientFactory ??
throw new ArgumentNullException("IHttpClientFactory not injected");
}
public async Task<bool> CANumberIsValid(int number) {
if (number <= 0) return false;
try {
HttpClient httpClient = _httpClientFactory.CreateClient("API");
HttpRequestMessage requestMessage = new(HttpMethod.Get, $"ca/isValidCANumber?number={number}");
HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage);
if (responseMessage.IsSuccessStatusCode) {
string responseContent = await responseMessage.Content.ReadAsStringAsync();
JsonSerializerOptions jsonSerializerOptions = new() {
PropertyNameCaseInsensitive = true
};
bool isValid = JsonSerializer.Deserialize<bool>(responseContent, jsonSerializerOptions);
return isValid;
} else {
throw new Exception(responseMessage.ReasonPhrase);
}
} catch (Exception ex) {
throw new Exception($"Unable to determine if {number} is a valid CA#, because {ex.Message}");
}
}
}