.vscode
Fab2ApprovalSystem
Kendo
MesaFabApproval.API
.config
.vscode
Clients
Controllers
ApprovalController.cs
AuthenticationController.cs
CAController.cs
CustomerController.cs
ECNController.cs
MRBController.cs
PCRBController.cs
UserController.cs
Models
Properties
Services
Utilities
.editorconfig
GlobalSuppressions.cs
MesaFabApproval.API.csproj
Program.cs
appsettings.json
nLog.config
MesaFabApproval.Client
MesaFabApproval.Shared
SQL
references
.editorconfig
.gitignore
Fab2ApprovalSystem-Development.yml
Fab2ApprovalSystem.sln
Fab2ApprovalSystem.yml
README.md
azure-pipelines.yml
When debugging only app.Services.GetRequiredService<IPCRBService>(); Injected AppSettings instead of using GetEnvironmentVariable at Services level Get ready to use VSCode IDE
56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
using MesaFabApproval.API.Services;
|
|
using MesaFabApproval.Shared.Models;
|
|
using MesaFabApproval.Shared.Services;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace MesaFabApproval.API.Controllers;
|
|
[ApiController]
|
|
[Authorize]
|
|
public class ECNController : ControllerBase {
|
|
private readonly ILogger<ApprovalController> _logger;
|
|
private readonly IECNService _ecnService;
|
|
private readonly IMonInWorkerClient _monInClient;
|
|
|
|
public ECNController(ILogger<ApprovalController> logger, IECNService ecnService,
|
|
IMonInWorkerClient monInClient) {
|
|
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
|
_ecnService = ecnService ?? throw new ArgumentNullException("IECNService not injected");
|
|
_monInClient = monInClient ?? throw new ArgumentNullException("IMonInWorkerClient not injected");
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("ecn/isValidEcnNumber")]
|
|
public async Task<IActionResult> IsValidEcnNumber(int number) {
|
|
DateTime start = DateTime.Now;
|
|
bool isInternalError = false;
|
|
string errorMessage = "";
|
|
|
|
try {
|
|
_logger.LogInformation($"Attempting to determine if {number} is a valid ECN#");
|
|
|
|
if (number <= 0) return Ok(false);
|
|
|
|
bool isValid = await _ecnService.IsValidECNNumber(number);
|
|
|
|
return Ok(isValid);
|
|
} catch (Exception ex) {
|
|
isInternalError = true;
|
|
errorMessage = $"Cannot determine if {number} is a valid ECN#, because {ex.Message}";
|
|
return Problem(errorMessage);
|
|
} finally {
|
|
string metricName = "IsValidEcnNumber";
|
|
DateTime end = DateTime.Now;
|
|
double millisecondsDiff = (end - start).TotalMilliseconds;
|
|
_monInClient.PostAverage(metricName + "Latency", millisecondsDiff);
|
|
|
|
if (isInternalError) {
|
|
_logger.LogError(errorMessage);
|
|
_monInClient.PostStatus(metricName, StatusValue.Critical);
|
|
} else {
|
|
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
|
}
|
|
}
|
|
}
|
|
} |