152 lines
6.8 KiB
C#
152 lines
6.8 KiB
C#
using Code.Utils;
|
|
using EnVisage.Models;
|
|
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
using PrevuWebAPI.Code.Managers;
|
|
using PrevuWebAPI.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PrevuWebAPI.Code
|
|
{
|
|
public class MongoManager
|
|
{
|
|
public static void StoreProjectSnapShotInMongo(APIProjectModel p, ProjectModel pre, ProjectModel post)
|
|
{
|
|
if (p == null)
|
|
return;
|
|
var clientInfo = APIClientInformationCallManager.ClientInfo;
|
|
if (clientInfo != null)
|
|
{
|
|
|
|
var connectionInfo = clientInfo.DataConnections.Where(x => x.ConnectionType == (int) DBConnectionType.MONGO).FirstOrDefault();
|
|
if (connectionInfo != null)
|
|
{
|
|
string connectionString = connectionInfo.ConnectionString;
|
|
var client = new MongoClient(connectionString);
|
|
var db = client.GetDatabase(clientInfo.Id.ToString());
|
|
MongoCollectionSettings settings = new MongoCollectionSettings();
|
|
var mongoCollection = db.GetCollection<MongoProjectPreChangeModel>("MongoProjectSnapshots");
|
|
var list = mongoCollection.Find(x => x.APIProjectModel.ProjectNumber == p.ProjectNumber).ToList();
|
|
mongoCollection.InsertOne(new MongoProjectPreChangeModel()
|
|
{
|
|
APIProjectModel = p,
|
|
ProjectModelPost = post,
|
|
ProjectModelPre = pre
|
|
});
|
|
|
|
}
|
|
}
|
|
}
|
|
public static void StoreAPIProjectInMongo(APIProjectModel p,List<string> messages)
|
|
{
|
|
if (p == null)
|
|
return;
|
|
var clientInfo = APIClientInformationCallManager.ClientInfo;
|
|
if (clientInfo != null)
|
|
{
|
|
|
|
var connectionInfo = clientInfo.DataConnections.Where(x => x.ConnectionType == (int) DBConnectionType.MONGO).FirstOrDefault();
|
|
if (connectionInfo != null)
|
|
{
|
|
string connectionString = connectionInfo.ConnectionString;
|
|
var client = new MongoClient(connectionString);
|
|
var db = client.GetDatabase(clientInfo.Id.ToString());
|
|
MongoCollectionSettings settings = new MongoCollectionSettings();
|
|
var mongoCollection = db.GetCollection<MongoAPIProjectModel>("APIProjectModelErrors");
|
|
var storedRec = mongoCollection.Find(x => x.APIProjectModel.ProjectNumber == p.ProjectNumber).FirstOrDefault();
|
|
if (storedRec == null)
|
|
{
|
|
mongoCollection.InsertOne(new MongoAPIProjectModel()
|
|
{
|
|
APIProjectModel = p,
|
|
messages=messages
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
var update=Builders<MongoAPIProjectModel>.Update.Set("APIProjectModel", p).Set("messages",messages);
|
|
mongoCollection.UpdateOne(x => x.Id == storedRec.Id, update);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
public static void StoreAPIPeopleResourceInMongo(APIPeopleResourceModel p, List<string> messages)
|
|
{
|
|
if (p == null)
|
|
return;
|
|
var clientInfo = APIClientInformationCallManager.ClientInfo;
|
|
if (clientInfo != null)
|
|
{
|
|
|
|
var connectionInfo = clientInfo.DataConnections.Where(x => x.ConnectionType == (int) DBConnectionType.MONGO).FirstOrDefault();
|
|
if (connectionInfo != null)
|
|
{
|
|
string connectionString = connectionInfo.ConnectionString;
|
|
var client = new MongoClient(connectionString);
|
|
var db = client.GetDatabase(clientInfo.Id.ToString());
|
|
MongoCollectionSettings settings = new MongoCollectionSettings();
|
|
var mongoCollection = db.GetCollection<MongoAPIPeopleResourceModel>("APIPeopleResourceModelErrors");
|
|
var storedRec = mongoCollection.Find(x => x._APIPeopleResourceModel.Email == p.Email).FirstOrDefault();
|
|
if (storedRec == null)
|
|
{
|
|
mongoCollection.InsertOne(new MongoAPIPeopleResourceModel()
|
|
{
|
|
_APIPeopleResourceModel = p,
|
|
messages = messages
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
var update = Builders<MongoAPIPeopleResourceModel>.Update.Set("_APIPeopleResourceModel", p).Set("messages", messages);
|
|
mongoCollection.UpdateOne(x => x.Id == storedRec.Id, update);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
public static void StoreAPINonProjectTimeInMongo(APINonProjectTimeModel p, List<string> messages)
|
|
{
|
|
if (p == null)
|
|
return;
|
|
var clientInfo = APIClientInformationCallManager.ClientInfo;
|
|
if (clientInfo != null)
|
|
{
|
|
|
|
var connectionInfo = clientInfo.DataConnections.Where(x => x.ConnectionType == (int) DBConnectionType.MONGO).FirstOrDefault();
|
|
if (connectionInfo != null)
|
|
{
|
|
string connectionString = connectionInfo.ConnectionString;
|
|
var client = new MongoClient(connectionString);
|
|
var db = client.GetDatabase(clientInfo.Id.ToString());
|
|
MongoCollectionSettings settings = new MongoCollectionSettings();
|
|
var mongoCollection = db.GetCollection<MongoAPINonProjectTimeModel>("APINonProjectTimeModel");
|
|
var storedRec = mongoCollection.Find(x => x._APINonProjectTimeModel.WorkEmail == p.WorkEmail && x._APINonProjectTimeModel.LeaveDate == p.LeaveDate
|
|
&& x._APINonProjectTimeModel.RequestStatus == p.RequestStatus).FirstOrDefault();
|
|
if (storedRec == null)
|
|
{
|
|
mongoCollection.InsertOne(new MongoAPINonProjectTimeModel()
|
|
{
|
|
_APINonProjectTimeModel = p,
|
|
messages = messages
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
var update = Builders<MongoAPINonProjectTimeModel>.Update.Set("_APINonProjectTimeModel", p).Set("messages", messages);
|
|
mongoCollection.UpdateOne(x => x.Id == storedRec.Id, update);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|