36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using MongoDB.Driver;
|
|
using System.Configuration;
|
|
|
|
namespace BeautySaloonNoSQLDatabaseImplement
|
|
{
|
|
public class NewdbContext
|
|
{
|
|
private static NewdbContext? _instance;
|
|
public IMongoCollection<Client> Clients { get; set; }
|
|
public IMongoCollection<Order> Orders { get; set; }
|
|
public IMongoCollection<Employee> Employees { get; set; }
|
|
public IMongoCollection<Service> Services { get; set; }
|
|
public IMongoCollection<Position> Positions { get; set; }
|
|
private NewdbContext()
|
|
{
|
|
var connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString;
|
|
var databaseName = MongoUrl.Create(connectionString).DatabaseName;
|
|
MongoClient client = new MongoClient(connectionString);
|
|
var database = client.GetDatabase(databaseName);
|
|
|
|
Clients = database.GetCollection<Client>("clients");
|
|
Orders = database.GetCollection<Order>("orders");
|
|
Employees = database.GetCollection<Employee>("employees");
|
|
Services = database.GetCollection<Service>("services");
|
|
Positions = database.GetCollection<Position>("positions");
|
|
}
|
|
public static NewdbContext GetInstance()
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new NewdbContext();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
} |