Created ECN# autocomplete for PCR3 docs
This commit is contained in:
@ -5,6 +5,7 @@ namespace MesaFabApproval.Client.Services;
|
||||
public interface IECNService {
|
||||
Task<string> ECNNumberIsValidStr(int ecnNumber);
|
||||
Task<bool> ECNNumberIsValid(int number);
|
||||
Task<IEnumerable<int>> GetAllECNNumbers();
|
||||
}
|
||||
|
||||
public class ECNService : IECNService {
|
||||
@ -49,4 +50,32 @@ public class ECNService : IECNService {
|
||||
throw new Exception($"Unable to determine if {number} is a valid ECN#, because {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<int>> GetAllECNNumbers() {
|
||||
try {
|
||||
HttpClient httpClient = _httpClientFactory.CreateClient("API");
|
||||
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, $"ecn/allNumbers");
|
||||
|
||||
HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage);
|
||||
|
||||
if (responseMessage.IsSuccessStatusCode) {
|
||||
string responseContent = await responseMessage.Content.ReadAsStringAsync();
|
||||
|
||||
JsonSerializerOptions jsonSerializerOptions = new() {
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
IEnumerable<int> allEcnNumbers =
|
||||
JsonSerializer.Deserialize<IEnumerable<int>>(responseContent, jsonSerializerOptions) ??
|
||||
new List<int>();
|
||||
|
||||
return allEcnNumbers;
|
||||
} else {
|
||||
throw new Exception(responseMessage.ReasonPhrase);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new Exception($"Unable to get all ECN#s, because {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user