2022-01-26 13:11:04 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-02-01 20:25:31 +00:00
|
|
|
using EFB.Models;
|
|
|
|
using EFB.Sessions;
|
2022-01-26 13:11:04 +00:00
|
|
|
|
|
|
|
namespace EFB.Controllers
|
|
|
|
{
|
|
|
|
//[Route("[controller]")]
|
|
|
|
public class NavdataController : Controller
|
|
|
|
{
|
|
|
|
private readonly ILogger<NavdataController> _logger;
|
|
|
|
|
|
|
|
public NavdataController(ILogger<NavdataController> logger)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2022-02-01 20:25:31 +00:00
|
|
|
public async Task<IActionResult> Index(string identifier)
|
2022-01-26 13:11:04 +00:00
|
|
|
{
|
2022-02-01 20:25:31 +00:00
|
|
|
if (identifier == null)
|
|
|
|
{//In the event we are just going to the base page1
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
|
|
|
|
NavdataModel[] data = null;
|
|
|
|
|
|
|
|
if (HttpContext.Session.GetObject<NavdataModel[]>("Navdata") == null)
|
|
|
|
{//If the navdata needs re-caching
|
|
|
|
data = await NavdataModel.Populate();
|
|
|
|
HttpContext.Session.SetObject("Navdata", NavdataModel.MergeSort(ref data, 0, data.Length-1));
|
|
|
|
}
|
|
|
|
|
|
|
|
//get the data out of tempdata and cast it into an array
|
|
|
|
data = HttpContext.Session.GetObject<NavdataModel[]>("Navdata");
|
|
|
|
NavdataModel navaid = NavdataModel.BinarySearch(ref data, 0, data.Length-1, identifier);
|
|
|
|
|
|
|
|
if (navaid == null)
|
|
|
|
{
|
|
|
|
TempData["Error"] = $"Sorry, no Navaid found with the name {identifier}";
|
|
|
|
}
|
|
|
|
return View(navaid);
|
2022-01-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
public IActionResult Error()
|
|
|
|
{
|
|
|
|
return View("Error!");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|