62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using DigitalData.Modules.Database;
|
|
using EnvelopeGenerator.Common;
|
|
|
|
namespace EnvelopeGenerator.Web.Services
|
|
{
|
|
public class DatabaseService: BaseService
|
|
{
|
|
public MSSQLServer MSSQL { get; set; }
|
|
|
|
public class ModelContainer
|
|
{
|
|
public EnvelopeModel envelopeModel;
|
|
public DocumentModel documentModel;
|
|
public ReceiverModel receiverModel;
|
|
public ElementModel elementModel;
|
|
public HistoryModel historyModel;
|
|
public DocumentStatusModel documentStatusModel;
|
|
|
|
public ModelContainer(State state)
|
|
{
|
|
envelopeModel = new(state);
|
|
documentModel = new(state);
|
|
receiverModel = new(state);
|
|
elementModel = new(state);
|
|
historyModel = new(state);
|
|
documentStatusModel = new(state);
|
|
}
|
|
}
|
|
public readonly ModelContainer? Models;
|
|
|
|
public DatabaseService(IConfiguration Config, LoggingService Logging) : base(Config, Logging)
|
|
{
|
|
logger = Logging.LogConfig.GetLogger();
|
|
|
|
logger.Debug("Establishing MSSQL Database connection..");
|
|
MSSQL = new MSSQLServer(logConfig, Config["Config:ConnectionString"]);
|
|
|
|
if (MSSQL.DBInitialized == true)
|
|
{
|
|
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
|
|
|
var state = GetState();
|
|
Models = new(state);
|
|
}
|
|
else
|
|
{
|
|
logger.Error("Connection could not be established!");
|
|
}
|
|
}
|
|
|
|
private State GetState()
|
|
{
|
|
return new State
|
|
{
|
|
Database = MSSQL,
|
|
LogConfig = logConfig,
|
|
UserId = 2 // TODO
|
|
};
|
|
}
|
|
}
|
|
}
|