using Biskilog_Accounting.Server.POSModels ;
using Biskilog_Accounting.Shared.ClientContractModels ;
using Biskilog_Accounting.Shared.Enums ;
using Biskilog_Accounting.Shared.Interfaces ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.Configuration ;
namespace Biskilog_Accounting.Server.Services
{
public class ConnectionService : IConnectionService
{
private readonly BiskilogContext m_context ;
private readonly IConfiguration m_configuration ;
public ConnectionService ( BiskilogContext a_context , IConfiguration configuration )
{
m_context = a_context ;
m_configuration = configuration ;
}
/// <summary>
/// Prepares and returns the connection string for a client using the specified database id
/// </summary>
/// <param name="a_databaseId">Specified database id to use</param>
/// <returns></returns>
public string GetClientConnectionString ( int a_databaseId )
{
Databasemap ? dbMap = m_context . Databasemaps . Find ( a_databaseId ) ;
if ( dbMap ! = null )
{
string rawConString = m_configuration . GetConnectionString ( "PrivateConnection" ) ! . ToString ( ) ;
return String . Format ( rawConString , dbMap . Domain , dbMap . DbName ) ;
}
return ConnectionEnums . ConnectionNotEstablished . ToString ( ) ;
}
/// <summary>
/// Prepare the DB context from the specified connection string
/// </summary>
/// <param name="a_context"></param>
/// <param name="a_connectionString"></param>
/// <returns>A configured BiskAcdbContext</returns>
public object PrepareDBContext ( string a_connectionString )
{
throw new NotImplementedException ( ) ;
//DbContextOptionsBuilder<BiskAcdbContext> acdbContext = new DbContextOptionsBuilder<BiskAcdbContext>();
//acdbContext.UseMySql(a_connectionString, new MariaDbServerVersion(new Version()));
//return new BiskAcdbContext(acdbContext.Options);
}
}
}