AVS-Carton-Shipment-Verifier/Controllers/HomeController.cs

49 lines
1.8 KiB
C#

using System.Diagnostics;
using AVSCartonShipmentVerifier.Models;
using AVSCartonShipmentVerifier.Repositories;
using AVSCartonShipmentVerifier.Services;
using AVSCartonShipmentVerifier.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace AVSCartonShipmentVerifier.Controllers;
public sealed class HomeController(
IScanHistoryStore scanHistoryStore,
ICartonVerificationRepository cartonVerificationRepository,
ILogger<HomeController> logger) : Controller
{
private readonly IScanHistoryStore _scanHistoryStore = scanHistoryStore;
private readonly ICartonVerificationRepository _cartonVerificationRepository = cartonVerificationRepository;
private readonly ILogger<HomeController> _logger = logger;
[HttpGet]
public async Task<IActionResult> Index(CancellationToken cancellationToken)
{
int? availableCartonsCount = null;
try
{
availableCartonsCount = await _cartonVerificationRepository.GetAvailableCartonCountAsync(cancellationToken);
}
catch (Exception exception)
{
_logger.LogWarning(exception, "Failed to load available cartons count for dashboard.");
}
var model = new VerificationDashboardViewModel
{
RecentSuccessfulScans = await _scanHistoryStore.GetLastFiveSuccessfulScansAsync(cancellationToken),
RecentRejectedScans = await _scanHistoryStore.GetLastFiveRejectedScansAsync(cancellationToken),
AvailableCartonsCount = availableCartonsCount
};
return View(model);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}