67 lines
1.4 KiB
C#
67 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using EgtBEAMWALL.DataLayer.DatabaseModels;
|
|
|
|
namespace EgtBEAMWALL.DataLayer.Controllers
|
|
{
|
|
public class DbController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private DatabaseContext dbCtx;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Fields
|
|
|
|
/// <summary>
|
|
/// Singleton gestione
|
|
/// </summary>
|
|
public static DbController man = new DbController();
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public DbController()
|
|
{
|
|
// Initialize database context
|
|
dbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING);
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
public bool ResetDb()
|
|
{
|
|
bool answ = false;
|
|
|
|
try
|
|
{
|
|
dbCtx
|
|
.Database
|
|
.SqlQuery<int>("CALL stp_ResetDb()");
|
|
answ = true;
|
|
|
|
dbCtx.SaveChanges();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Console.WriteLine($"EXCEPTION on ResetDb: {exc}");
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |