MRB webassembly
This commit is contained in:
38
MesaFabApproval.API/Services/CustomerService.cs
Normal file
38
MesaFabApproval.API/Services/CustomerService.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace MesaFabApproval.API.Services;
|
||||
|
||||
public interface ICustomerService {
|
||||
Task<IEnumerable<string>> GetCustomerNames();
|
||||
}
|
||||
|
||||
public class CustomerService : ICustomerService {
|
||||
private readonly ILogger<CustomerService> _logger;
|
||||
private readonly IDalService _dalService;
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
public CustomerService(ILogger<CustomerService> logger, IDalService dalService, IMemoryCache cache) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
_cache = cache ?? throw new ArgumentNullException("IMemoryCache not injected");
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<string>> GetCustomerNames() {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get customer names");
|
||||
|
||||
IEnumerable<string>? customerNames = _cache.Get<IEnumerable<string>>("allCustomerNames");
|
||||
|
||||
if (customerNames is null) {
|
||||
string sql = "select ProductFamily from ProductFamilies;";
|
||||
|
||||
customerNames = (await _dalService.QueryAsync<string>(sql)).ToList();
|
||||
}
|
||||
|
||||
return customerNames;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to get customer names, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user