2022-02-28 21:53:28 +00:00
|
|
|
using EFB.Models;
|
|
|
|
using MongoDB.Driver;
|
2022-02-18 17:18:00 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2022-02-18 18:49:56 +00:00
|
|
|
namespace EFB.MongoData
|
2022-02-18 17:18:00 +00:00
|
|
|
{
|
|
|
|
public class Mongo
|
|
|
|
{
|
2022-02-18 18:49:56 +00:00
|
|
|
//function that is responsible to getting the user's latest sim position from the MongoDB
|
2022-02-28 21:53:28 +00:00
|
|
|
public static async Task<SimPositionModel> GetLatestData(string email)
|
|
|
|
{
|
2022-02-28 22:04:02 +00:00
|
|
|
//Create mongo client to allow connection to the database
|
2022-02-18 18:49:56 +00:00
|
|
|
MongoClient client = new MongoClient(
|
|
|
|
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
|
|
|
|
);
|
|
|
|
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
|
|
|
|
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
|
|
|
|
|
2022-02-28 22:04:02 +00:00
|
|
|
//Create filter to select specifically the records where the Email is the same as what we specified
|
2022-02-18 18:49:56 +00:00
|
|
|
FilterDefinition<SimPositionModel> filter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
|
|
|
|
var data = await collection.FindAsync<SimPositionModel>(filter).Result.ToListAsync();
|
|
|
|
if (data.Count > 0)
|
2022-02-28 22:04:02 +00:00
|
|
|
{//Return the first item in the list (Should only be 1)
|
2022-02-18 18:49:56 +00:00
|
|
|
return data[0];
|
2022-02-28 22:04:02 +00:00
|
|
|
}//Or return null if not present
|
2022-02-18 18:49:56 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-02-18 17:18:00 +00:00
|
|
|
}
|
|
|
|
}
|