512a2200c6
* Added default Api unhandled exceptions * Fixed config file
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Step.Model;
|
|
using MySql.Data.Entity;
|
|
using System.Data.SqlClient;
|
|
using static Step.Utils.ExceptionManager;
|
|
using static Step.Utils.Constants;
|
|
|
|
namespace Step.Database
|
|
{
|
|
[DbConfigurationType(typeof(MySqlEFConfiguration))]
|
|
public class DatabaseContext : DbContext
|
|
{
|
|
public DbSet<UserModel> Users { get; set; }
|
|
public DbSet<RoleModel> Roles { get; set; }
|
|
public DbSet<FunctionAccessModel> FunctionsAccess { get; set; }
|
|
|
|
public DatabaseContext()
|
|
: base("mySQLDatabaseConnection")
|
|
{
|
|
}
|
|
|
|
public static void TestDatabaseConnection()
|
|
{
|
|
using (DatabaseContext dbContext = new DatabaseContext())
|
|
{
|
|
try
|
|
{
|
|
dbContext.Database.Connection.Open();
|
|
dbContext.Database.Connection.Close();
|
|
}
|
|
catch (MySql.Data.MySqlClient.MySqlException ex)
|
|
{
|
|
if (ex.Number == 1042) // Can't find MySQLServer
|
|
{
|
|
Manage(ERROR_LEVEL.FATAL, ex);
|
|
}
|
|
else
|
|
{
|
|
Manage(ERROR_LEVEL.ERROR, ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|