2022-02-11 19:40:31 +00:00
|
|
|
using EFB.Controllers.Form;
|
2022-02-28 21:53:28 +00:00
|
|
|
using EFB.Models;
|
2022-02-11 19:40:31 +00:00
|
|
|
using EFB.Sessions;
|
2022-02-28 21:53:28 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using System.Threading.Tasks;
|
2022-02-11 19:40:31 +00:00
|
|
|
|
|
|
|
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-28 21:53:28 +00:00
|
|
|
|
|
|
|
if (ICAO == null)
|
2022-02-11 19:40:31 +00:00
|
|
|
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");
|
|
|
|
}
|
2022-02-28 21:53:28 +00:00
|
|
|
}
|
|
|
|
else
|
2022-02-11 19:40:31 +00:00
|
|
|
{
|
|
|
|
TempData["Error"] = "Invalid ICAO";
|
|
|
|
}
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
|
2022-02-28 21:53:28 +00:00
|
|
|
public IActionResult ViewCharts(string chart)
|
|
|
|
{
|
2022-02-15 16:03:46 +00:00
|
|
|
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!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|