69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
|
using MongoDB.Driver;
|
|||
|
using RouteGuideMongoDBImplement.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace RouteGuideMongoDBImplement
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Класс для взаимодействия с базой данных
|
|||
|
/// </summary>
|
|||
|
public class RouteGuideDatabase : IDisposable
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Клиент
|
|||
|
/// </summary>
|
|||
|
public readonly MongoClient _client;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// База данных
|
|||
|
/// </summary>
|
|||
|
private readonly IMongoDatabase _database;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
/// <param name="connectionString">Параметры подключения к базе данных</param>
|
|||
|
/// <param name="databaseName">Название базы данных</param>
|
|||
|
public RouteGuideDatabase(string connectionString = "mongodb://localhost:27017",
|
|||
|
string databaseName = "RouteGuideDatabase")
|
|||
|
{
|
|||
|
_client = new MongoClient(connectionString);
|
|||
|
_database = _client.GetDatabase(databaseName);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Коллекция "Водители"
|
|||
|
/// </summary>
|
|||
|
public IMongoCollection<Driver> Drivers => _database.GetCollection<Driver>("Drivers");
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Коллекция "Транспорт"
|
|||
|
/// </summary>
|
|||
|
public IMongoCollection<Transport> Transport => _database.GetCollection<Transport>("Transport");
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Коллекция "Маршруты"
|
|||
|
/// </summary>
|
|||
|
public IMongoCollection<Route> Routes => _database.GetCollection<Route>("Routes");
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Коллекция "Остановки"
|
|||
|
/// </summary>
|
|||
|
public IMongoCollection<Stop> Stops => _database.GetCollection<Stop>("Stops");
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Коллекция "Расписания"
|
|||
|
/// </summary>
|
|||
|
public IMongoCollection<Schedule> Schedules => _database.GetCollection<Schedule>("Schedules");
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Освободить ресурсы
|
|||
|
/// </summary>
|
|||
|
public void Dispose() { }
|
|||
|
}
|
|||
|
}
|