clean up server
This commit is contained in:
@@ -1,116 +1,61 @@
|
||||
using DigitalData.Modules.Database;
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.Common;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Services
|
||||
{
|
||||
public class DatabaseService
|
||||
public class DatabaseService: BaseService
|
||||
{
|
||||
public MSSQLServer MSSQL { get; set; }
|
||||
|
||||
private EnvelopeModel envelopeModel;
|
||||
private DocumentModel documentModel;
|
||||
private ReceiverModel receiverModel;
|
||||
private ElementModel elementModel;
|
||||
private HistoryModel historyModel;
|
||||
private DocumentStatusModel documentStatusModel;
|
||||
private readonly LogConfig _logConfig;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public DatabaseService(LoggingService Logging, IConfiguration Config)
|
||||
public class ModelContainer
|
||||
{
|
||||
_logConfig = Logging.LogConfig;
|
||||
_logger = Logging.LogConfig.GetLogger();
|
||||
public EnvelopeModel envelopeModel;
|
||||
public DocumentModel documentModel;
|
||||
public ReceiverModel receiverModel;
|
||||
public ElementModel elementModel;
|
||||
public HistoryModel historyModel;
|
||||
public DocumentStatusModel documentStatusModel;
|
||||
|
||||
_logger.Debug("Establishing MSSQL Database connection..");
|
||||
MSSQL = new MSSQLServer(_logConfig, Config["Config:ConnectionString"]);
|
||||
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, DatabaseService database) : 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);
|
||||
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
||||
|
||||
var state = GetState();
|
||||
InitializeModels(state);
|
||||
Models = new(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warn("Connection could not be established!");
|
||||
logger.Error("Connection could not be established!");
|
||||
}
|
||||
}
|
||||
|
||||
public State GetState()
|
||||
private State GetState()
|
||||
{
|
||||
return new State
|
||||
{
|
||||
Database = MSSQL,
|
||||
LogConfig = _logConfig,
|
||||
LogConfig = logConfig,
|
||||
UserId = 2 // TODO
|
||||
};
|
||||
}
|
||||
|
||||
public void InitializeModels(State state)
|
||||
{
|
||||
envelopeModel = new(state);
|
||||
documentModel = new(state);
|
||||
receiverModel = new(state);
|
||||
elementModel = new(state);
|
||||
historyModel = new(state);
|
||||
documentStatusModel = new(state);
|
||||
}
|
||||
|
||||
public EnvelopeResponse LoadEnvelope(string pEnvelopeKey)
|
||||
{
|
||||
Tuple<string, string> result = Helpers.DecodeEnvelopeReceiverId(pEnvelopeKey);
|
||||
var envelopeUuid = result.Item1;
|
||||
var receiverSignature = result.Item2;
|
||||
var receiverId = receiverModel.GetReceiverIdBySignature(receiverSignature);
|
||||
|
||||
Envelope? envelope = envelopeModel.GetByUuid(envelopeUuid);
|
||||
|
||||
if (envelope == null)
|
||||
{
|
||||
throw new NullReferenceException("Envelope not found");
|
||||
}
|
||||
|
||||
if (envelope.Receivers == null)
|
||||
{
|
||||
throw new NullReferenceException("Receivers for envelope not loaded");
|
||||
}
|
||||
|
||||
EnvelopeReceiver? receiver = envelope.Receivers.Where(r => r.Id == receiverId).SingleOrDefault();
|
||||
|
||||
if (receiver == null)
|
||||
{
|
||||
throw new NullReferenceException("Receiver not found");
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Receiver = receiver,
|
||||
Envelope = envelope
|
||||
};
|
||||
}
|
||||
|
||||
public List<Envelope> LoadEnvelopes(int pReceiverId)
|
||||
{
|
||||
return (List<Envelope>)envelopeModel.List(pReceiverId);
|
||||
}
|
||||
|
||||
public EnvelopeDocument LoadDocument(int pDocumentId)
|
||||
{
|
||||
return documentModel.GetById(pDocumentId);
|
||||
}
|
||||
|
||||
public bool InsertHistoryEntry(EnvelopeHistoryEntry historyEntry)
|
||||
{
|
||||
return historyModel.Insert(historyEntry);
|
||||
}
|
||||
|
||||
public bool InsertDocumentStatus(DocumentStatus documentStatus)
|
||||
{
|
||||
return documentStatusModel.InsertOrUpdate(documentStatus);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user