Added MongoDB Methods and introduced flight sim controller
This commit is contained in:
parent
eda71069a4
commit
10af903706
@ -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<IActionResult> Index()
|
||||
{
|
||||
//Retrieve and Check current user status
|
||||
UserModel user = HttpContext.Session.GetObject<UserModel>("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();
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
18
Models/FlightsimModel.cs
Normal file
18
Models/FlightsimModel.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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<SimPositionModel> GetLatestData(string email){
|
||||
MongoClient client = new MongoClient(
|
||||
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
|
||||
);
|
||||
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
|
||||
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
|
||||
|
||||
FilterDefinition<SimPositionModel> filter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
|
||||
var data = await collection.FindAsync<SimPositionModel>(filter).Result.ToListAsync();
|
||||
if (data.Count > 0)
|
||||
{
|
||||
return data[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user