diff --git a/Controllers/ChartsController.cs b/Controllers/ChartsController.cs new file mode 100644 index 0000000..0fc963e --- /dev/null +++ b/Controllers/ChartsController.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using EFB.Models; +using EFB.Controllers.Form; +using EFB.Sessions; + +namespace EFB.Controllers +{ + //[Route("[controller]")] + public class ChartsController : Controller + { + private readonly ILogger _logger; + + public ChartsController(ILogger logger) + { + _logger = logger; + } + + public async Task Index(string ICAO) + { + if(ICAO == null) + return View(); + + if (FormAuthenticator.ValidateICAOCode(ICAO)) + { + var charts = await ChartModel.FetchAsync(ICAO); + if (charts != null) + { + ChartModel chartModel = new ChartModel(charts); + // return ViewCharts(chartModel); + HttpContext.Session.SetObject("Charts", chartModel); + return RedirectToAction("ViewCharts"); + } + }else + { + TempData["Error"] = "Invalid ICAO"; + } + return View(); + } + + public IActionResult ViewCharts(){ + ChartModel charts = HttpContext.Session.GetObject("Charts"); + if (charts != null) + { + return View("ViewCharts", charts); + } + return RedirectToAction("Index"); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View("Error!"); + } + } +} \ No newline at end of file diff --git a/Models/ChartModel.cs b/Models/ChartModel.cs index c6313c7..3483e3e 100644 --- a/Models/ChartModel.cs +++ b/Models/ChartModel.cs @@ -67,11 +67,12 @@ namespace EFB.Models //make Charts request var requestCharts = await API.Post($"https://chartfox.org/api/charts/grouped/{ICAO}", headerData, body); Console.WriteLine("End"); - return requestCharts.Result.Response; - }else - { - return null; + if (requestCharts.Result.Status == "success") + { + return requestCharts.Result.Response; + } } + return null; } } diff --git a/Startup.cs b/Startup.cs index 90010f4..61cf386 100644 --- a/Startup.cs +++ b/Startup.cs @@ -54,6 +54,12 @@ namespace EFB endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); + // endpoints.MapControllerRoute( + // name: "Navdata", + // pattern: "{controller=Navdata}/{action=Index}/{identifier?}"); + // endpoints.MapControllerRoute( + // name: "Charts", + // pattern: "{controller=Charts}/{action=Index}/{ICAO?}"); }); } } diff --git a/Views/Charts/Index.cshtml b/Views/Charts/Index.cshtml new file mode 100644 index 0000000..9978856 --- /dev/null +++ b/Views/Charts/Index.cshtml @@ -0,0 +1,37 @@ +@{ + ViewData["Title"] = "Welcome"; +} + +
+
+
+

Chart Lookup

+ +
+
+ +
+
+ +
+ + + @{ + if (TempData["Error"] != null) + {//If an error has been flagged, information will be displayed to the user + +
+
+ +
+ Warning! @TempData["Error"]
+ } + } +
+
+
+
+ + + diff --git a/Views/Charts/ViewCharts.cshtml b/Views/Charts/ViewCharts.cshtml new file mode 100644 index 0000000..8d895a8 --- /dev/null +++ b/Views/Charts/ViewCharts.cshtml @@ -0,0 +1,93 @@ +@model EFB.Models.ChartModel; +@{ + ViewData["Title"] = "Welcome"; +} + +
+
+
+

Chart Lookup

+ +
+
+ +
+
+ +
+ + + @{ + if (TempData["Error"] != null) + {//If an error has been flagged, information will be displayed to the user + +
+
+ +
+ Warning! @TempData["Error"]
+ } + } +
+
+
+

Charts for: @Model.Approach[0].Name

+ +
+
+ +
+
+ +
+ + + @{ + if (TempData["Error"] != null) + {//If an error has been flagged, information will be displayed to the user + +
+
+ +
+ Warning! @TempData["Error"]
+ } + } +
+
+
+ +
+
+

Chart Lookup

+ +
+
+ +
+
+ +
+ + + @{ + if (TempData["Error"] != null) + {//If an error has been flagged, information will be displayed to the user + +
+
+ +
+ Warning! @TempData["Error"]
+ } + } +
+
+
+
+ + + diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 9b614b5..d8901cc 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -32,7 +32,7 @@ Navdata