Added Navdata View (Needs Tweaking)

This commit is contained in:
Luke Else 2022-02-01 20:25:31 +00:00
parent ef4d44d7d2
commit 58eef9ea67
3 changed files with 102 additions and 7 deletions

View File

@ -5,6 +5,8 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using EFB.Models;
using EFB.Sessions;
namespace EFB.Controllers namespace EFB.Controllers
{ {
@ -18,11 +20,32 @@ namespace EFB.Controllers
_logger = logger; _logger = logger;
} }
public IActionResult Index() public async Task<IActionResult> Index(string identifier)
{ {
if (identifier == null)
{//In the event we are just going to the base page1
return View(); 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);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {

View File

@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using EFB.Sessions;
namespace EFB.Models namespace EFB.Models
{ {
@ -10,22 +13,26 @@ namespace EFB.Models
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Type { get; set; }
public int? Frequency { get; set; } public int? Frequency { get; set; }
public string Latitude { get; set; } public string Latitude { get; set; }
public string Longitude { get; set; } public string Longitude { get; set; }
public NavdataModel(int id, string name, string latitude, string longitude){ public NavdataModel(int id, string name, string type, string latitude, string longitude){
Id = id; Id = id;
Name = name; Name = name;
Type = type;
Frequency = null; Frequency = null;
Latitude = latitude; Latitude = latitude;
Longitude = longitude; Longitude = longitude;
} }
public NavdataModel(int id, string name, int? frequency, string latitude, string longitude){ [JsonConstructor]
public NavdataModel(int id, string name, string type, int? frequency, string latitude, string longitude){
Id = id; Id = id;
Name = name; Name = name;
Type = type;
Frequency = frequency; Frequency = frequency;
Latitude = latitude; Latitude = latitude;
Longitude = longitude; Longitude = longitude;
@ -52,16 +59,16 @@ namespace EFB.Models
string latitude = reader.GetString(4); string latitude = reader.GetString(4);
string longitude = reader.GetString(5); string longitude = reader.GetString(5);
if (reader.GetString(2) == "VOR" || reader.GetString(2) == "NDB") if (type == "VOR" || type == "NDB")
{ {
// int? frequency = reader.GetInt32(3); // int? frequency = reader.GetInt32(3);
int? frequency = null; int? frequency = null;
navdata.Add( navdata.Add(
new NavdataModel(id, name, frequency, latitude, longitude) new NavdataModel(id, name, type, frequency, latitude, longitude)
); );
}else{ }else{
navdata.Add( navdata.Add(
new NavdataModel(id, name, latitude, longitude) new NavdataModel(id, name, type, latitude, longitude)
); );
} }
} }

View File

@ -0,0 +1,65 @@
@model EFB.Models.NavdataModel
@{
ViewData["Title"] = "Welcome";
}
<div class="row d-flex justify-content-center">
<div class="card-body col-md-6">
<div class="container jumbotron">
<h3>Navdata Lookup</h3>
<br />
<br />
<form asp-controller="Navdata" asp-action="Index">
<div class="form-group">
<input type="text" class="form-control" placeholder="Identifier" name="identifier" value="@TempData["identifier"]">
</div>
<button type="submit" class="btn btn-secondary">Search</button>
@{
if (TempData["Error"] != null)
{//If an error has been flagged, information will be displayed to the user
<br />
<br />
<div class="alert alert-danger">
<strong>Warning!</strong> @TempData["Error"] <button type='button' class='close' data-dismiss='alert' aria-hidden='true' />&times;
</div>
}
}
</form>
</div>
</div>
@{
if(Model != null){
<div class="card-body col-md-6">
<div class="container jumbotron">
<h3>@Model.Name (@Model.Type) [@Model.Id]</h3>
<br />
<h4>Latitude</h4>
@Model.Latitude
<h4>Longitude</h4>
@Model.Longitude
@{
if(Model.Frequency != null){
<h4>Frequency</h4>
@Model.Frequency
}
}
</div>
</div>
}
}
</div>