diff --git a/Controllers/FlightsimController.cs b/Controllers/FlightsimController.cs index 0e7a17f..a2af131 100644 --- a/Controllers/FlightsimController.cs +++ b/Controllers/FlightsimController.cs @@ -4,7 +4,10 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using EFB.Sessions; using Microsoft.Extensions.Logging; +using EFB.Models; +using EFB.MongoData; namespace EFB.Controllers { @@ -18,8 +21,17 @@ namespace EFB.Controllers _logger = logger; } - public IActionResult Index() + public async Task Index() { + //Retrieve and Check current user status + UserModel user = HttpContext.Session.GetObject("User"); + if(user == null) return RedirectToAction("Index", "Home"); + + //Retrieve the user's latest sim position and construct it into FlightsimModel + SimPositionModel latestPosition = await Mongo.GetLatestData(user.EMail); + // RouteModel route = RouteModel.StringToRoute(); + + return View(); } diff --git a/Controllers/RouteController.cs b/Controllers/RouteController.cs index 635934d..ee74e01 100644 --- a/Controllers/RouteController.cs +++ b/Controllers/RouteController.cs @@ -175,6 +175,8 @@ namespace EFB.Controllers //fill in route string finalRoute = RouteModel.ParseRoute(routeString); user.Route = finalRoute; + user.Departure = departure; + user.Arrival = arrival; HttpContext.Session.SetObject("User", user); return RedirectToAction("Index", "Route"); diff --git a/Models/FlightsimModel.cs b/Models/FlightsimModel.cs new file mode 100644 index 0000000..90b6b10 --- /dev/null +++ b/Models/FlightsimModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EFB.Models +{ + public class FlightsimModel + { + public SimPositionModel CurrentPosition { get; set; } + public RouteModel Route { get; set; } + public FlightsimModel(SimPositionModel position, RouteModel route) + { + CurrentPosition = position; + Route = route; + } + } +} \ No newline at end of file diff --git a/Models/UserModel.cs b/Models/UserModel.cs index 09580ab..4aa6982 100644 --- a/Models/UserModel.cs +++ b/Models/UserModel.cs @@ -24,8 +24,7 @@ namespace EFB.Models public string Departure { get; set; } public string Route { get; set; } public string Arrival { get; set; } - - + public RouteModel RouteObject { get; set; } public TokenModel RouteToken { get; set; } = null; diff --git a/Mongo/Mongo.cs b/Mongo/Mongo.cs index 22604ad..6624770 100644 --- a/Mongo/Mongo.cs +++ b/Mongo/Mongo.cs @@ -6,10 +6,25 @@ using MongoDB.Driver; using MongoDB.Bson; using EFB.Models; -namespace EFB.Mongo +namespace EFB.MongoData { public class Mongo { - + //function that is responsible to getting the user's latest sim position from the MongoDB + public static async Task GetLatestData(string email){ + MongoClient client = new MongoClient( + Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User) + ); + MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB"); + MongoCollectionBase collection = (MongoCollectionBase)database.GetCollection("Simdata"); + + FilterDefinition filter = Builders.Filter.Eq(x => x.EMail, email); + var data = await collection.FindAsync(filter).Result.ToListAsync(); + if (data.Count > 0) + { + return data[0]; + } + return null; + } } } \ No newline at end of file