Completed app page + added metar class

This commit is contained in:
Luke Else 2022-02-18 22:43:01 +00:00
parent ec5ca51602
commit c418188481
5 changed files with 91 additions and 11 deletions

View File

@ -23,18 +23,17 @@ namespace EFB.Controllers
public IActionResult Index() public IActionResult Index()
{ {
//Check to see what point on the application the user is at and where they should be sent //Check to see what point on the application the user is at and where they should be sent
UserModel User = HttpContext.Session.GetObject<UserModel>("User"); UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (User != null) if (user == null)
{ {
if (User.Route == null)
{
return RedirectToAction("Index", "Route");
}else{
return RedirectToAction("Index", "App");
}
}else{
return RedirectToAction("Index", "Home"); return RedirectToAction("Index", "Home");
} }
if (user.Route == null)
{
return RedirectToAction("Index", "Route");
}
return View(user);
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -185,7 +185,7 @@ namespace EFB.Controllers
user.Cruise = cruise; user.Cruise = cruise;
HttpContext.Session.SetObject("User", user); HttpContext.Session.SetObject("User", user);
return RedirectToAction("Index", "Route"); return RedirectToAction("Index", "App");
} }
TempData["Error"] = $"Unable to get route after {pollCount} Attempts!"; TempData["Error"] = $"Unable to get route after {pollCount} Attempts!";

View File

@ -7,5 +7,6 @@
<PackageReference Include="MySql.Data" Version="*"/> <PackageReference Include="MySql.Data" Version="*"/>
<PackageReference Include="MongoDB.Driver" Version="*"/> <PackageReference Include="MongoDB.Driver" Version="*"/>
<PackageReference Include="MongoDB.Bson" Version="*"/> <PackageReference Include="MongoDB.Bson" Version="*"/>
<PackageReference Include="libmetar" Version="*"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

32
Metar/Metar.cs Normal file
View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using libmetar.Services;
namespace EFB.Metar
{
public static class Metar
{
private static MetarService metarService { get; set; } = new MetarService();
private static TafService tafService { get; set; } = new TafService();
public static async Task<string> GetMETAR(string ICAO){
return (await metarService.GetRawAsync(ICAO)).Raw;
}
public static async Task<List<string>> GetTAF(string ICAO){
var downloadedTAF = (await tafService.GetRawAsync(ICAO)).RawSplit;
List<string> TAF = new List<string>();
foreach (var line in downloadedTAF)
{
TAF.Add(line);
}
return TAF;
}
}
}

48
Views/App/Index.cshtml Normal file
View File

@ -0,0 +1,48 @@
@using EFB.Metar;
@model EFB.Models.UserModel;
@{
ViewData["Title"] = "Welcome";
}
<div class="row d-flex">
<div class="card-body col-md-12 bg-primary">
<div class="container jumbotron">
<h3>Current Session - @Model.EMail</h3>
<br />
<br />
<div class="row d-flex">
<div class="col-md-6">
<h4>Departure</h4>
@Model.Departure
<br />
@await Metar.GetMETAR(Model.Departure)
<h4>Cruise</h4>
@Model.Cruise ft
</div>
<div class="col-md-6">
<h4>Arrival</h4>
@Model.Arrival
<br />
@await Metar.GetMETAR(Model.Arrival)
</div>
</div>
<br />
<h4>Route</h4>
@Model.Route
</div>
</div>
</div>