2022-02-11 19:40:31 +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;
|
|
|
|
using EFB.Models;
|
2022-02-11 19:54:11 +00:00
|
|
|
using EFB.Models.JSON;
|
2022-02-11 19:40:31 +00:00
|
|
|
using EFB.Controllers.Form;
|
|
|
|
using EFB.Sessions;
|
|
|
|
|
|
|
|
namespace EFB.Controllers
|
|
|
|
{
|
|
|
|
//[Route("[controller]")]
|
|
|
|
public class ChartsController : Controller
|
|
|
|
{
|
|
|
|
private readonly ILogger<ChartsController> _logger;
|
|
|
|
|
|
|
|
public ChartsController(ILogger<ChartsController> logger)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IActionResult> Index(string ICAO)
|
|
|
|
{
|
2022-02-11 20:14:57 +00:00
|
|
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
|
|
|
if (user == null)
|
|
|
|
{
|
|
|
|
TempData["Error"] = "Must be logged in to view charts";
|
|
|
|
return RedirectToAction("Index", "Home");
|
|
|
|
}
|
|
|
|
|
2022-02-11 19:40:31 +00:00
|
|
|
if(ICAO == null)
|
|
|
|
return View();
|
|
|
|
|
|
|
|
if (FormAuthenticator.ValidateICAOCode(ICAO))
|
|
|
|
{
|
|
|
|
var charts = await ChartModel.FetchAsync(ICAO);
|
|
|
|
if (charts != null)
|
|
|
|
{
|
2022-02-11 19:54:11 +00:00
|
|
|
ChartModel chartModel = new ChartModel(ICAO, charts);
|
|
|
|
//Save the current chart into user model for later access
|
|
|
|
user.CurrentCharts = chartModel;
|
|
|
|
HttpContext.Session.SetObject("User", user);
|
2022-02-11 19:40:31 +00:00
|
|
|
return RedirectToAction("ViewCharts");
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
TempData["Error"] = "Invalid ICAO";
|
|
|
|
}
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
|
2022-02-15 16:03:46 +00:00
|
|
|
public IActionResult ViewCharts(string chart){
|
|
|
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
|
|
|
if (user != null)
|
2022-02-11 19:40:31 +00:00
|
|
|
{
|
2022-02-15 16:03:46 +00:00
|
|
|
ViewChartModel charts = new ViewChartModel(user.CurrentCharts, chart);
|
|
|
|
|
|
|
|
if (charts != null)
|
|
|
|
{
|
|
|
|
return View("ViewCharts", charts);
|
|
|
|
}
|
|
|
|
return RedirectToAction("Index");
|
2022-02-11 19:40:31 +00:00
|
|
|
}
|
2022-02-15 16:03:46 +00:00
|
|
|
return RedirectToAction("Index", "Home");
|
2022-02-11 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
public IActionResult Error()
|
|
|
|
{
|
|
|
|
return View("Error!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|