2022-02-18 17:18:00 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MongoDB.Driver;
|
|
|
|
using MongoDB.Bson;
|
|
|
|
using EFB.Models;
|
|
|
|
|
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
|
|
|
|
public static async Task<SimPositionModel> GetLatestData(string email){
|
|
|
|
MongoClient client = new MongoClient(
|
2022-02-19 21:26:31 +00:00
|
|
|
Environment.GetEnvironmentVariable("MongoDBConnectionString")
|
2022-02-18 18:49:56 +00:00
|
|
|
);
|
|
|
|
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;
|
|
|
|
}
|
2022-02-18 17:18:00 +00:00
|
|
|
}
|
|
|
|
}
|