diff --git a/RouteGuide/RouteGuide.sln b/RouteGuide/RouteGuide.sln index 99b0ab2..41f7630 100644 --- a/RouteGuide/RouteGuide.sln +++ b/RouteGuide/RouteGuide.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideContracts", "Rout EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideDatabaseImplement", "RouteGuideDatabaseImplement\RouteGuideDatabaseImplement.csproj", "{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideBusinessLogics", "RouteGuideBusinessLogics\RouteGuideBusinessLogics.csproj", "{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideBusinessLogics", "RouteGuideBusinessLogics\RouteGuideBusinessLogics.csproj", "{7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideMongoDBImplement", "RouteGuideMongoDBImplement\RouteGuideMongoDBImplement.csproj", "{4FC074A5-4AB9-40C5-8833-B0A7D138F675}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Release|Any CPU.Build.0 = Release|Any CPU + {4FC074A5-4AB9-40C5-8833-B0A7D138F675}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4FC074A5-4AB9-40C5-8833-B0A7D138F675}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4FC074A5-4AB9-40C5-8833-B0A7D138F675}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4FC074A5-4AB9-40C5-8833-B0A7D138F675}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs index 0fab9b1..19c81fa 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs @@ -216,7 +216,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { Phone = model.Phone }); - if (element != null && element.Id != model.Id) + if (element != null && !element.Id.Equals(model.Id)) { throw new InvalidOperationException("Водитель с таким номером телефона уже существует"); } diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs index b719770..dbd83fd 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs @@ -204,7 +204,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { throw new ArgumentNullException("Не указано название маршрута", nameof(model.Name)); } - if (model.TransportId < 0) + if (model.TransportId == null || (model.TransportId is int && (int)model.TransportId < 0)) { throw new ArgumentNullException("Некорректный идентификатор транспортного средства", nameof(model.TransportId)); } @@ -215,7 +215,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { Name = model.Name }); - if (element != null && element.Id != model.Id) + if (element != null && !element.Id.Equals(model.Id)) { throw new InvalidOperationException("Маршрут с таким названием уже существует"); } diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs index 156047c..bdb63bf 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs @@ -200,7 +200,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { return; } - if (model.RouteId < 0) + if (model.RouteId == null || (model.RouteId is int && (int)model.RouteId < 0)) { throw new ArgumentNullException("Некорректный идентификатор маршрута", nameof(model.RouteId)); } diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs index 4e2624d..3dbfe22 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs @@ -219,7 +219,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { Name = model.Name }); - if (element != null && element.Id != model.Id) + if (element != null && !element.Id.Equals(model.Id)) { throw new InvalidOperationException("Остановка с таким названием уже существует"); } diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs index afc18f3..e2a0ee8 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs @@ -208,7 +208,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { throw new ArgumentNullException("Вместимость транспортного средства должна быть положительным числом", nameof(model.Capacity)); } - if (model.DriverId < 0) + if (model.DriverId == null || (model.DriverId is int && (int)model.DriverId < 0)) { throw new ArgumentNullException("Некорректный идентификатор водителя", nameof(model.DriverId)); } @@ -219,7 +219,7 @@ namespace RouteGuideBusinessLogics.BusinessLogics { License = model.License }); - if (element != null && element.Id != model.Id) + if (element != null && !element.Id.Equals(model.Id)) { throw new InvalidOperationException("Транспортное средство с таким номерным знаком уже есть"); } diff --git a/RouteGuide/RouteGuideContracts/BindingModels/DriverBindingModel.cs b/RouteGuide/RouteGuideContracts/BindingModels/DriverBindingModel.cs index fbc78ce..72bae68 100644 --- a/RouteGuide/RouteGuideContracts/BindingModels/DriverBindingModel.cs +++ b/RouteGuide/RouteGuideContracts/BindingModels/DriverBindingModel.cs @@ -11,12 +11,12 @@ namespace RouteGuideContracts.BindingModels /// Модель для передачи данных пользователя /// в методы для сохранения данных для водителей /// - public class DriverBindingModel : IDriverModel + public class DriverBindingModel : IDriverModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// ФИО водителя diff --git a/RouteGuide/RouteGuideContracts/BindingModels/RouteBindingModel.cs b/RouteGuide/RouteGuideContracts/BindingModels/RouteBindingModel.cs index 48de80a..e52e518 100644 --- a/RouteGuide/RouteGuideContracts/BindingModels/RouteBindingModel.cs +++ b/RouteGuide/RouteGuideContracts/BindingModels/RouteBindingModel.cs @@ -11,12 +11,12 @@ namespace RouteGuideContracts.BindingModels /// Модель для передачи данных пользователя /// в методы для сохранения данных для маршрутов /// - public class RouteBindingModel : IRouteModel + public class RouteBindingModel : IRouteModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Название маршрута @@ -26,12 +26,12 @@ namespace RouteGuideContracts.BindingModels /// /// Идентификатор транспорта /// - public int TransportId { get; set; } + public object TransportId { get; set; } /// /// Коллекция остановок маршрута /// - public Dictionary RouteStops + public Dictionary, int)> RouteStops { get; set; diff --git a/RouteGuide/RouteGuideContracts/BindingModels/ScheduleBindingModel.cs b/RouteGuide/RouteGuideContracts/BindingModels/ScheduleBindingModel.cs index 902062a..cd0066e 100644 --- a/RouteGuide/RouteGuideContracts/BindingModels/ScheduleBindingModel.cs +++ b/RouteGuide/RouteGuideContracts/BindingModels/ScheduleBindingModel.cs @@ -11,12 +11,12 @@ namespace RouteGuideContracts.BindingModels /// Модель для передачи данных пользователя /// в методы для сохранения данных для расписания /// - public class ScheduleBindingModel : IScheduleModel + public class ScheduleBindingModel : IScheduleModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Дата записи расписания @@ -41,6 +41,6 @@ namespace RouteGuideContracts.BindingModels /// /// Идентификатор маршрута /// - public int RouteId { get; set; } + public object RouteId { get; set; } } } diff --git a/RouteGuide/RouteGuideContracts/BindingModels/StopBindingModel.cs b/RouteGuide/RouteGuideContracts/BindingModels/StopBindingModel.cs index 9175a11..b1278db 100644 --- a/RouteGuide/RouteGuideContracts/BindingModels/StopBindingModel.cs +++ b/RouteGuide/RouteGuideContracts/BindingModels/StopBindingModel.cs @@ -11,12 +11,12 @@ namespace RouteGuideContracts.BindingModels /// Модель для передачи данных пользователя /// в методы для сохранения данных для остановок /// - public class StopBindingModel : IStopModel + public class StopBindingModel : IStopModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Название остановки diff --git a/RouteGuide/RouteGuideContracts/BindingModels/TransportBindingModel.cs b/RouteGuide/RouteGuideContracts/BindingModels/TransportBindingModel.cs index d8f0167..b5b018b 100644 --- a/RouteGuide/RouteGuideContracts/BindingModels/TransportBindingModel.cs +++ b/RouteGuide/RouteGuideContracts/BindingModels/TransportBindingModel.cs @@ -12,12 +12,12 @@ namespace RouteGuideContracts.BindingModels /// Модель для передачи данных пользователя /// в методы для сохранения данных для транспорта /// - public class TransportBindingModel : ITransportModel + public class TransportBindingModel : ITransportModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Номерной знак @@ -37,6 +37,6 @@ namespace RouteGuideContracts.BindingModels /// /// Идентификатор водителя /// - public int DriverId { get; set; } + public object DriverId { get; set; } } } diff --git a/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs b/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs index c9d079c..6800696 100644 --- a/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs +++ b/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs @@ -15,7 +15,7 @@ namespace RouteGuideContracts.SearchModels /// /// Идентификатор /// - public int? Id { get; set; } + public object? Id { get; set; } /// /// Номер телефона водителя diff --git a/RouteGuide/RouteGuideContracts/SearchModels/RouteSearchModel.cs b/RouteGuide/RouteGuideContracts/SearchModels/RouteSearchModel.cs index 6963c20..08ae7d7 100644 --- a/RouteGuide/RouteGuideContracts/SearchModels/RouteSearchModel.cs +++ b/RouteGuide/RouteGuideContracts/SearchModels/RouteSearchModel.cs @@ -15,7 +15,7 @@ namespace RouteGuideContracts.SearchModels /// /// Идентификатор /// - public int? Id { get; set; } + public object? Id { get; set; } /// /// Название маршрута diff --git a/RouteGuide/RouteGuideContracts/SearchModels/ScheduleSearchModel.cs b/RouteGuide/RouteGuideContracts/SearchModels/ScheduleSearchModel.cs index 5d0b740..0f55634 100644 --- a/RouteGuide/RouteGuideContracts/SearchModels/ScheduleSearchModel.cs +++ b/RouteGuide/RouteGuideContracts/SearchModels/ScheduleSearchModel.cs @@ -15,6 +15,6 @@ namespace RouteGuideContracts.SearchModels /// /// Идентификатор /// - public int? Id { get; set; } + public object? Id { get; set; } } } diff --git a/RouteGuide/RouteGuideContracts/SearchModels/StopSearchModel.cs b/RouteGuide/RouteGuideContracts/SearchModels/StopSearchModel.cs index 57b776e..a912376 100644 --- a/RouteGuide/RouteGuideContracts/SearchModels/StopSearchModel.cs +++ b/RouteGuide/RouteGuideContracts/SearchModels/StopSearchModel.cs @@ -15,7 +15,7 @@ namespace RouteGuideContracts.SearchModels /// /// Идентификатор /// - public int? Id { get; set; } + public object? Id { get; set; } /// /// Название остановки diff --git a/RouteGuide/RouteGuideContracts/SearchModels/TransportSearchModel.cs b/RouteGuide/RouteGuideContracts/SearchModels/TransportSearchModel.cs index d576c1f..ce17ede 100644 --- a/RouteGuide/RouteGuideContracts/SearchModels/TransportSearchModel.cs +++ b/RouteGuide/RouteGuideContracts/SearchModels/TransportSearchModel.cs @@ -15,7 +15,7 @@ namespace RouteGuideContracts.SearchModels /// /// Идентификатор /// - public int? Id { get; set; } + public object? Id { get; set; } /// /// Номерной знак diff --git a/RouteGuide/RouteGuideContracts/ViewModels/DriverViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/DriverViewModel.cs index f46546b..0bfab25 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/DriverViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/DriverViewModel.cs @@ -12,12 +12,12 @@ namespace RouteGuideContracts.ViewModels /// Модель для передачи данных пользователю /// для отображения для водителей /// - public class DriverViewModel : IDriverModel + public class DriverViewModel : IDriverModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// ФИО водителя diff --git a/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs index c14c42b..e843b16 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs @@ -12,12 +12,12 @@ namespace RouteGuideContracts.ViewModels /// Модель для передачи данных пользователю /// для отображения для маршрутов /// - public class RouteViewModel : IRouteModel + public class RouteViewModel : IRouteModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Название маршрута @@ -28,7 +28,7 @@ namespace RouteGuideContracts.ViewModels /// /// Идентификатор транспорта /// - public int TransportId { get; set; } + public object TransportId { get; set; } /// /// Номерной знак транспорта @@ -39,7 +39,7 @@ namespace RouteGuideContracts.ViewModels /// /// Коллекция остановок маршрута /// - public Dictionary RouteStops + public Dictionary, int)> RouteStops { get; set; diff --git a/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs index 1c7f3f0..a70c628 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs @@ -12,12 +12,12 @@ namespace RouteGuideContracts.ViewModels /// Модель для передачи данных пользователю /// для отображения для расписания /// - public class ScheduleViewModel : IScheduleModel + public class ScheduleViewModel : IScheduleModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Дата записи расписания @@ -46,7 +46,7 @@ namespace RouteGuideContracts.ViewModels /// /// Идентификатор маршрута /// - public int RouteId { get; set; } + public object RouteId { get; set; } /// /// Название маршрута diff --git a/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs index 6d4a50a..6fe7cb5 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs @@ -12,12 +12,12 @@ namespace RouteGuideContracts.ViewModels /// Модель для передачи данных пользователю /// для отображения для остановок /// - public class StopViewModel : IStopModel + public class StopViewModel : IStopModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Название остановки diff --git a/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs index e8253c8..174dcd7 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs @@ -13,12 +13,12 @@ namespace RouteGuideContracts.ViewModels /// Модель для передачи данных пользователю /// для отображения для транспорта /// - public class TransportViewModel : ITransportModel + public class TransportViewModel : ITransportModel { /// /// Идентификатор /// - public int Id { get; set; } + public object Id { get; set; } /// /// Номерной знак @@ -41,7 +41,7 @@ namespace RouteGuideContracts.ViewModels /// /// Идентификатор водителя /// - public int DriverId { get; set; } + public object DriverId { get; set; } /// /// ФИО водителя diff --git a/RouteGuide/RouteGuideDataModels/IId.cs b/RouteGuide/RouteGuideDataModels/IId.cs index 1c0b66a..60ee98b 100644 --- a/RouteGuide/RouteGuideDataModels/IId.cs +++ b/RouteGuide/RouteGuideDataModels/IId.cs @@ -9,11 +9,12 @@ namespace RouteGuideDataModels /// /// Интерфейс для идентификатора /// - public interface IId - { + public interface IId + + { /// /// Идентификатор /// - int Id { get; } + T Id { get; } } } diff --git a/RouteGuide/RouteGuideDataModels/Models/IDriverModel.cs b/RouteGuide/RouteGuideDataModels/Models/IDriverModel.cs index e1dbd72..67cadad 100644 --- a/RouteGuide/RouteGuideDataModels/Models/IDriverModel.cs +++ b/RouteGuide/RouteGuideDataModels/Models/IDriverModel.cs @@ -9,7 +9,7 @@ namespace RouteGuideDataModels.Models /// /// Интерфейс для модели водителя /// - public interface IDriverModel : IId + public interface IDriverModel : IId { /// /// ФИО водителя diff --git a/RouteGuide/RouteGuideDataModels/Models/IRouteModel.cs b/RouteGuide/RouteGuideDataModels/Models/IRouteModel.cs index 663c280..8b06899 100644 --- a/RouteGuide/RouteGuideDataModels/Models/IRouteModel.cs +++ b/RouteGuide/RouteGuideDataModels/Models/IRouteModel.cs @@ -9,7 +9,7 @@ namespace RouteGuideDataModels.Models /// /// Интерфейс для модели маршрута /// - public interface IRouteModel : IId + public interface IRouteModel : IId { /// /// Название маршрута @@ -19,11 +19,11 @@ namespace RouteGuideDataModels.Models /// /// Идентификатор транспорта /// - int TransportId { get; } + T TransportId { get; } /// /// Коллекция остановок маршрута /// - Dictionary RouteStops { get; } + Dictionary, int)> RouteStops { get; } } } diff --git a/RouteGuide/RouteGuideDataModels/Models/IScheduleModel.cs b/RouteGuide/RouteGuideDataModels/Models/IScheduleModel.cs index a48f05a..4343eaa 100644 --- a/RouteGuide/RouteGuideDataModels/Models/IScheduleModel.cs +++ b/RouteGuide/RouteGuideDataModels/Models/IScheduleModel.cs @@ -9,7 +9,7 @@ namespace RouteGuideDataModels.Models /// /// Интерфейс для модели расписания /// - public interface IScheduleModel : IId + public interface IScheduleModel : IId { /// /// Дата записи расписания @@ -34,6 +34,6 @@ namespace RouteGuideDataModels.Models /// /// Идентификатор маршрута /// - int RouteId { get; } + T RouteId { get; } } } diff --git a/RouteGuide/RouteGuideDataModels/Models/IStopModel.cs b/RouteGuide/RouteGuideDataModels/Models/IStopModel.cs index e81ff21..83fbc4e 100644 --- a/RouteGuide/RouteGuideDataModels/Models/IStopModel.cs +++ b/RouteGuide/RouteGuideDataModels/Models/IStopModel.cs @@ -9,7 +9,7 @@ namespace RouteGuideDataModels.Models /// /// Интерфейс для модели остановки /// - public interface IStopModel : IId + public interface IStopModel : IId { /// /// Название остановки diff --git a/RouteGuide/RouteGuideDataModels/Models/ITransportModel.cs b/RouteGuide/RouteGuideDataModels/Models/ITransportModel.cs index f0b7504..ffef38b 100644 --- a/RouteGuide/RouteGuideDataModels/Models/ITransportModel.cs +++ b/RouteGuide/RouteGuideDataModels/Models/ITransportModel.cs @@ -10,7 +10,7 @@ namespace RouteGuideDataModels.Models /// /// Интерфейс для модели транспорта /// - public interface ITransportModel : IId + public interface ITransportModel : IId { /// /// Номерной знак @@ -30,6 +30,6 @@ namespace RouteGuideDataModels.Models /// /// Идентификатор водителя /// - int DriverId { get; } + T DriverId { get; } } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs index 1e7873f..56fdd79 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs @@ -74,14 +74,14 @@ namespace RouteGuideDatabaseImplement.Implements /// public DriverViewModel? GetElement(DriverSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Phone)) + if (model.Id == null && string.IsNullOrEmpty(model.Phone)) { return null; } using var context = new RouteGuideDatabase(); return context.Drivers - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Phone) && x.Phone.Contains(model.Phone)) || (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Phone) && x.Phone.Contains(model.Phone)) || (model.Id != null && x.Id.Equals(model.Id))) ?.GetViewModel; } @@ -112,7 +112,7 @@ namespace RouteGuideDatabaseImplement.Implements public DriverViewModel? Update(DriverBindingModel model) { using var context = new RouteGuideDatabase(); - var driver = context.Drivers.FirstOrDefault(x => x.Id == model.Id); + var driver = context.Drivers.FirstOrDefault(x => x.Id.Equals(model.Id)); if (driver == null) { return null; @@ -131,7 +131,7 @@ namespace RouteGuideDatabaseImplement.Implements public DriverViewModel? Delete(DriverBindingModel model) { using var context = new RouteGuideDatabase(); - var driver = context.Drivers.FirstOrDefault(x => x.Id == model.Id); + var driver = context.Drivers.FirstOrDefault(x => x.Id.Equals(model.Id)); if (driver == null) { return null; diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs index ad26756..96e42fd 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs @@ -86,7 +86,7 @@ namespace RouteGuideDatabaseImplement.Implements /// public RouteViewModel? GetElement(RouteSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name)) + if (model.Id == null && string.IsNullOrEmpty(model.Name)) { return null; } @@ -96,7 +96,7 @@ namespace RouteGuideDatabaseImplement.Implements .Include(x => x.Transport) .Include(x => x.Stops) .ThenInclude(x => x.Stop) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id != null && x.Id.Equals(model.Id))) ?.GetViewModel; } @@ -130,7 +130,7 @@ namespace RouteGuideDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var route = context.Routes.FirstOrDefault(x => x.Id == model.Id); + var route = context.Routes.FirstOrDefault(x => x.Id.Equals(model.Id)); if (route == null) { return null; @@ -159,7 +159,7 @@ namespace RouteGuideDatabaseImplement.Implements using var context = new RouteGuideDatabase(); var route = context.Routes .Include(x => x.Stops) - .FirstOrDefault(rec => rec.Id == model.Id); + .FirstOrDefault(rec => rec.Id.Equals(model.Id)); if (route == null) { return null; diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs index 483d2cc..8d9fc8b 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs @@ -37,7 +37,7 @@ namespace RouteGuideDatabaseImplement.Implements /// public List GetFilteredList(ScheduleSearchModel model) { - if (!model.Id.HasValue) + if (model.Id == null) { return new(); } @@ -45,7 +45,7 @@ namespace RouteGuideDatabaseImplement.Implements using var context = new RouteGuideDatabase(); return context.Schedules .Include(x => x.Route) - .Where(x => x.Id == model.Id) + .Where(x => x.Id.Equals(model.Id)) .Select(x => x.GetViewModel) .ToList(); } @@ -77,7 +77,7 @@ namespace RouteGuideDatabaseImplement.Implements /// public ScheduleViewModel? GetElement(ScheduleSearchModel model) { - if (!model.Id.HasValue) + if (model.Id == null) { return null; } @@ -85,7 +85,7 @@ namespace RouteGuideDatabaseImplement.Implements using var context = new RouteGuideDatabase(); return context.Schedules .Include(x => x.Route) - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (model.Id != null && x.Id.Equals(model.Id))) ?.GetViewModel; } @@ -116,7 +116,7 @@ namespace RouteGuideDatabaseImplement.Implements public ScheduleViewModel? Update(ScheduleBindingModel model) { using var context = new RouteGuideDatabase(); - var schedule = context.Schedules.FirstOrDefault(x => x.Id == model.Id); + var schedule = context.Schedules.FirstOrDefault(x => x.Id.Equals(model.Id)); if (schedule == null) { return null; @@ -135,7 +135,7 @@ namespace RouteGuideDatabaseImplement.Implements public ScheduleViewModel? Delete(ScheduleBindingModel model) { using var context = new RouteGuideDatabase(); - var schedule = context.Schedules.FirstOrDefault(x => x.Id == model.Id); + var schedule = context.Schedules.FirstOrDefault(x => x.Id.Equals(model.Id)); if (schedule == null) { return null; diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs index 5b66c72..227fe9b 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs @@ -73,14 +73,14 @@ namespace RouteGuideDatabaseImplement.Implements /// public StopViewModel? GetElement(StopSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name)) + if (model.Id == null && string.IsNullOrEmpty(model.Name)) { return null; } using var context = new RouteGuideDatabase(); return context.Stops - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id != null && x.Id.Equals(model.Id))) ?.GetViewModel; } @@ -111,7 +111,7 @@ namespace RouteGuideDatabaseImplement.Implements public StopViewModel? Update(StopBindingModel model) { using var context = new RouteGuideDatabase(); - var stop = context.Stops.FirstOrDefault(x => x.Id == model.Id); + var stop = context.Stops.FirstOrDefault(x => x.Id.Equals(model.Id)); if (stop == null) { return null; @@ -130,7 +130,7 @@ namespace RouteGuideDatabaseImplement.Implements public StopViewModel? Delete(StopBindingModel model) { using var context = new RouteGuideDatabase(); - var stop = context.Stops.FirstOrDefault(x => x.Id == model.Id); + var stop = context.Stops.FirstOrDefault(x => x.Id.Equals(model.Id)); if (stop == null) { return null; diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs index f2d4f24..8b2e7db 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs @@ -77,7 +77,7 @@ namespace RouteGuideDatabaseImplement.Implements /// public TransportViewModel? GetElement(TransportSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.License)) + if (model.Id == null && string.IsNullOrEmpty(model.License)) { return null; } @@ -85,7 +85,7 @@ namespace RouteGuideDatabaseImplement.Implements using var context = new RouteGuideDatabase(); return context.Transport .Include(x => x.Driver) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.License) && x.License.Contains(model.License)) || (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.License) && x.License.Contains(model.License)) || (model.Id != null && x.Id.Equals(model.Id))) ?.GetViewModel; } @@ -116,7 +116,7 @@ namespace RouteGuideDatabaseImplement.Implements public TransportViewModel? Update(TransportBindingModel model) { using var context = new RouteGuideDatabase(); - var transport = context.Transport.FirstOrDefault(x => x.Id == model.Id); + var transport = context.Transport.FirstOrDefault(x => x.Id.Equals(model.Id)); if (transport == null) { return null; @@ -135,7 +135,7 @@ namespace RouteGuideDatabaseImplement.Implements public TransportViewModel? Delete(TransportBindingModel model) { using var context = new RouteGuideDatabase(); - var transport = context.Transport.FirstOrDefault(x => x.Id == model.Id); + var transport = context.Transport.FirstOrDefault(x => x.Id.Equals(model.Id)); if (transport == null) { return null; diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Driver.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Driver.cs index 2c1df73..8afe779 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Driver.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Driver.cs @@ -13,7 +13,7 @@ namespace RouteGuideDatabaseImplement.Models /// /// Сущность "Водитель" /// - public class Driver : IDriverModel + public class Driver : IDriverModel { /// /// Идентификатор @@ -51,7 +51,7 @@ namespace RouteGuideDatabaseImplement.Models return new Driver() { - Id = model.Id, + Id = (int)model.Id, FullName = model.FullName, Phone = model.Phone, Experience = model.Experience @@ -72,7 +72,7 @@ namespace RouteGuideDatabaseImplement.Models return new Driver() { - Id = model.Id, + Id = (int)model.Id, FullName = model.FullName, Phone = model.Phone, Experience = model.Experience diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs index a55e5b5..16631ad 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs @@ -15,7 +15,7 @@ namespace RouteGuideDatabaseImplement.Models /// /// Сущность "Маршрут" /// - public class Route : IRouteModel + public class Route : IRouteModel { /// /// Идентификатор @@ -42,20 +42,20 @@ namespace RouteGuideDatabaseImplement.Models /// /// Коллекция остановок маршрута /// - private Dictionary? _routeStops = null; + private Dictionary, int)>? _routeStops = null; /// /// Коллекция остановок маршрута /// [NotMapped] - public Dictionary RouteStops + public Dictionary, int)> RouteStops { get { if (_routeStops == null) { _routeStops = Stops - .ToDictionary(recRS => recRS.StopId, recRS => (recRS.Stop as IStopModel, recRS.Number)); + .ToDictionary(recRS => recRS.StopId, recRS => (recRS.Stop as IStopModel, recRS.Number)); } return _routeStops; } @@ -77,14 +77,14 @@ namespace RouteGuideDatabaseImplement.Models { return new Route() { - Id = model.Id, + Id = (int)model.Id, Name = model.Name, - TransportId = model.TransportId, + TransportId = (int)model.TransportId, Transport = context.Transport - .FirstOrDefault(x => x.Id == model.TransportId), + .FirstOrDefault(x => x.Id.Equals(model.TransportId)), Stops = model.RouteStops.Select(x => new RouteStop { - Stop = context.Stops.First(y => y.Id == x.Key), + Stop = context.Stops.First(y => y.Id.Equals(x.Key)), Number = x.Value.Item2 }).ToList() }; @@ -112,7 +112,14 @@ namespace RouteGuideDatabaseImplement.Models Id = Id, Name = Name, TransportId = TransportId, - RouteStops = RouteStops, + RouteStops = RouteStops + .ToDictionary(recRS => (object)recRS.Key, recRS => (new StopViewModel() + { + Id = (object)recRS.Value.Item1.Id, + Name = recRS.Value.Item1.Name, + Street = recRS.Value.Item1.Street, + Number = recRS.Value.Item1.Number + } as IStopModel, recRS.Value.Item2)), TransportLicense = Transport.License }; @@ -123,7 +130,7 @@ namespace RouteGuideDatabaseImplement.Models /// public void UpdateStops(RouteGuideDatabase context, RouteBindingModel model) { - var routeStops = context.RouteStops.Where(rec => rec.RouteId == model.Id).ToList(); + var routeStops = context.RouteStops.Where(rec => rec.RouteId.Equals(model.Id)).ToList(); if (routeStops != null && routeStops.Count > 0) { // Удаление остановок, которых нет в маршруте @@ -144,7 +151,7 @@ namespace RouteGuideDatabaseImplement.Models context.RouteStops.Add(new RouteStop { Route = route, - Stop = context.Stops.First(x => x.Id == rs.Key), + Stop = context.Stops.First(x => x.Id.Equals(rs.Key)), Number = rs.Value.Item2 }); context.SaveChanges(); diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs index 429ad58..a4cac04 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs @@ -15,7 +15,7 @@ namespace RouteGuideDatabaseImplement.Models /// /// Сущность "Расписание" /// - public class Schedule : IScheduleModel + public class Schedule : IScheduleModel { /// /// Идентификатор @@ -71,14 +71,14 @@ namespace RouteGuideDatabaseImplement.Models return new Schedule() { - Id = model.Id, + Id = (int)model.Id, Date = model.Date, DepartureTime = model.DepartureTime, ArrivalTime = model.ArrivalTime, Frequency = model.Frequency, - RouteId = model.RouteId, + RouteId = (int)model.RouteId, Route = context.Routes - .FirstOrDefault(x => x.Id == model.RouteId) + .FirstOrDefault(x => x.Id.Equals(model.RouteId)) }; } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Stop.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Stop.cs index 722b0c7..bdb2b75 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Stop.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Stop.cs @@ -14,7 +14,7 @@ namespace RouteGuideDatabaseImplement.Models /// /// Сущность "Остановка" /// - public class Stop : IStopModel + public class Stop : IStopModel { /// /// Идентификатор @@ -53,7 +53,7 @@ namespace RouteGuideDatabaseImplement.Models return new Stop() { - Id = model.Id, + Id = (int)model.Id, Name = model.Name, Street = model.Street, Number = model.Number @@ -74,7 +74,7 @@ namespace RouteGuideDatabaseImplement.Models return new Stop() { - Id = model.Id, + Id = (int)model.Id, Name = model.Name, Street = model.Street, Number = model.Number diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs index ef1e2b9..64c501c 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs @@ -16,7 +16,7 @@ namespace RouteGuideDatabaseImplement.Models /// /// Сущность "Транспорт" /// - public class Transport : ITransportModel + public class Transport : ITransportModel { /// /// Идентификатор @@ -66,13 +66,13 @@ namespace RouteGuideDatabaseImplement.Models return new Transport() { - Id = model.Id, + Id = (int)model.Id, License = model.License, Type = model.Type, Capacity = model.Capacity, - DriverId = model.DriverId, + DriverId = (int)model.DriverId, Driver = context.Drivers - .FirstOrDefault(x => x.Id == model.DriverId) + .FirstOrDefault(x => x.Id.Equals(model.DriverId)) }; } diff --git a/RouteGuide/RouteGuideMongoDBImplement/Implements/DriverStorage.cs b/RouteGuide/RouteGuideMongoDBImplement/Implements/DriverStorage.cs new file mode 100644 index 0000000..1a6e7ce --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Implements/DriverStorage.cs @@ -0,0 +1,222 @@ +using MongoDB.Driver; +using MongoDB.Bson; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.SearchModels; +using RouteGuideContracts.StoragesContracts; +using RouteGuideContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RouteGuideMongoDBImplement.Models; + +namespace RouteGuideMongoDBImplement.Implements +{ + /// + /// Хранилище для сущности "Водитель" + /// + public class DriverStorage : IDriverStorage + { + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Drivers + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(DriverSearchModel model) + { + if (string.IsNullOrEmpty(model.Phone)) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Phone, model.Phone); + + return context.Drivers + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Drivers + .Find(filter) + .Limit(count) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение элемента + /// + /// + /// + public DriverViewModel? GetElement(DriverSearchModel model) + { + if (string.IsNullOrEmpty(model.Id?.ToString()) && string.IsNullOrEmpty(model.Phone)) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + if (!string.IsNullOrEmpty(model.Phone)) + { + filter &= filterBuilder.Eq(x => x.Phone, model.Phone); + } + if (!string.IsNullOrEmpty(model.Id?.ToString())) + { + filter &= filterBuilder.Eq(x => x.Id, model.Id); + } + + return context.Drivers + .Find(filter) + .FirstOrDefault() + ?.GetViewModel; + } + + /// + /// Добавление элемента + /// + /// + /// + public DriverViewModel? Insert(DriverBindingModel model) + { + var newDriver = Driver.Create(model); + if (newDriver == null) + { + return null; + } + + using var context = new RouteGuideDatabase(); + context.Drivers.InsertOne(newDriver); + return newDriver.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public DriverViewModel? Update(DriverBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var driver = context.Drivers.Find(filter).FirstOrDefault(); + if (driver == null) + { + return null; + } + + driver.Update(model); + context.Drivers.ReplaceOne(filter, driver); + return driver.GetViewModel; + } + + /// + /// Удаление элемента + /// + /// + /// + public DriverViewModel? Delete(DriverBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var driver = context.Drivers.Find(filter).FirstOrDefault(); + if (driver == null) + { + return null; + } + + context.Drivers.FindOneAndDelete(filter); + return driver.GetViewModel; + } + + /// + /// Удаление записи + /// + /// + public DriverViewModel? Delete() + { + if (!GetFullList().Any()) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + var element = context.Drivers.FindOneAndDelete(filter); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = GetFullList().Count; + if (count <= 0) + { + return 0; + } + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + context.Drivers.DeleteMany(filter); + return count; + } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Implements/RouteStorage.cs b/RouteGuide/RouteGuideMongoDBImplement/Implements/RouteStorage.cs new file mode 100644 index 0000000..8cca252 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Implements/RouteStorage.cs @@ -0,0 +1,231 @@ +using MongoDB.Driver; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.SearchModels; +using RouteGuideContracts.StoragesContracts; +using RouteGuideContracts.ViewModels; +using RouteGuideMongoDBImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RouteGuideMongoDBImplement.Implements +{ + /// + /// Хранилище для сущности "Маршрут" + /// + public class RouteStorage : IRouteStorage + { + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Routes + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(RouteSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Name, model.Name); + + return context.Routes + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Routes + .Find(filter) + .Limit(count) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение элемента + /// + /// + /// + public RouteViewModel? GetElement(RouteSearchModel model) + { + if (string.IsNullOrEmpty(model.Id?.ToString()) && string.IsNullOrEmpty(model.Name)) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + if (!string.IsNullOrEmpty(model.Name)) + { + filter &= filterBuilder.Eq(x => x.Name, model.Name); + } + if (!string.IsNullOrEmpty(model.Id?.ToString())) + { + filter &= filterBuilder.Eq(x => x.Id, model.Id); + } + + return context.Routes + .Find(filter) + .FirstOrDefault() + ?.GetViewModel; + } + + /// + /// Добавление элемента + /// + /// + /// + public RouteViewModel? Insert(RouteBindingModel model) + { + using var context = new RouteGuideDatabase(); + var newRoute = Route.Create(context, model); + if (newRoute == null) + { + return null; + } + + context.Routes.InsertOne(newRoute); + return newRoute.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public RouteViewModel? Update(RouteBindingModel model) + { + using var context = new RouteGuideDatabase(); + using var session = context._client.StartSession(); + try + { + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var route = context.Routes.Find(filter).FirstOrDefault(); + if (route == null) + { + return null; + } + + route.Update(model); + route.UpdateStops(context, model); + context.Routes.ReplaceOne(filter, route); + session.CommitTransaction(); + return route.GetViewModel; + } + catch + { + session.AbortTransaction(); + throw; + } + } + + /// + /// Удаление элемента + /// + /// + /// + public RouteViewModel? Delete(RouteBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var route = context.Routes.Find(filter).FirstOrDefault(); + if (route == null) + { + return null; + } + + context.Routes.FindOneAndDelete(filter); + return route.GetViewModel; + } + + /// + /// Удаление записи + /// + /// + public RouteViewModel? Delete() + { + if (!GetFullList().Any()) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + var element = context.Routes.FindOneAndDelete(filter); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = GetFullList().Count; + if (count <= 0) + { + return 0; + } + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + context.Routes.DeleteMany(filter); + return count; + } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Implements/ScheduleStorage.cs b/RouteGuide/RouteGuideMongoDBImplement/Implements/ScheduleStorage.cs new file mode 100644 index 0000000..084f778 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Implements/ScheduleStorage.cs @@ -0,0 +1,213 @@ +using MongoDB.Driver; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.SearchModels; +using RouteGuideContracts.StoragesContracts; +using RouteGuideContracts.ViewModels; +using RouteGuideMongoDBImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RouteGuideMongoDBImplement.Implements +{ + /// + /// Хранилище для сущности "Расписание" + /// + public class ScheduleStorage : IScheduleStorage + { + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Schedules + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(ScheduleSearchModel model) + { + if (string.IsNullOrEmpty(model.Id?.ToString())) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + return context.Schedules + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Schedules + .Find(filter) + .Limit(count) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение элемента + /// + /// + /// + public ScheduleViewModel? GetElement(ScheduleSearchModel model) + { + if (string.IsNullOrEmpty(model.Id?.ToString())) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + return context.Schedules + .Find(filter) + .FirstOrDefault() + ?.GetViewModel; + } + + /// + /// Добавление элемента + /// + /// + /// + public ScheduleViewModel? Insert(ScheduleBindingModel model) + { + using var context = new RouteGuideDatabase(); + var newSchedule = Schedule.Create(context, model); + if (newSchedule == null) + { + return null; + } + + context.Schedules.InsertOne(newSchedule); + return newSchedule.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public ScheduleViewModel? Update(ScheduleBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var schedule = context.Schedules.Find(filter).FirstOrDefault(); + if (schedule == null) + { + return null; + } + + schedule.Update(model); + context.Schedules.ReplaceOne(filter, schedule); + return schedule.GetViewModel; + } + + /// + /// Удаление элемента + /// + /// + /// + public ScheduleViewModel? Delete(ScheduleBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var schedule = context.Schedules.Find(filter).FirstOrDefault(); + if (schedule == null) + { + return null; + } + + context.Schedules.FindOneAndDelete(filter); + return schedule.GetViewModel; + } + + /// + /// Удаление записи + /// + /// + public ScheduleViewModel? Delete() + { + if (!GetFullList().Any()) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + var element = context.Schedules.FindOneAndDelete(filter); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = GetFullList().Count; + if (count <= 0) + { + return 0; + } + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + context.Schedules.DeleteMany(filter); + return count; + } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Implements/StopStorage.cs b/RouteGuide/RouteGuideMongoDBImplement/Implements/StopStorage.cs new file mode 100644 index 0000000..3175acf --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Implements/StopStorage.cs @@ -0,0 +1,221 @@ +using MongoDB.Driver; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.SearchModels; +using RouteGuideContracts.StoragesContracts; +using RouteGuideContracts.ViewModels; +using RouteGuideMongoDBImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RouteGuideMongoDBImplement.Implements +{ + /// + /// Хранилище для сущности "Остановка" + /// + public class StopStorage : IStopStorage + { + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Stops + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(StopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Name, model.Name); + + return context.Stops + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Stops + .Find(filter) + .Limit(count) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение элемента + /// + /// + /// + public StopViewModel? GetElement(StopSearchModel model) + { + if (string.IsNullOrEmpty(model.Id?.ToString()) && string.IsNullOrEmpty(model.Name)) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + if (!string.IsNullOrEmpty(model.Name)) + { + filter &= filterBuilder.Eq(x => x.Name, model.Name); + } + if (!string.IsNullOrEmpty(model.Id?.ToString())) + { + filter &= filterBuilder.Eq(x => x.Id, model.Id); + } + + return context.Stops + .Find(filter) + .FirstOrDefault() + ?.GetViewModel; + } + + /// + /// Добавление элемента + /// + /// + /// + public StopViewModel? Insert(StopBindingModel model) + { + var newStop = Stop.Create(model); + if (newStop == null) + { + return null; + } + + using var context = new RouteGuideDatabase(); + context.Stops.InsertOne(newStop); + return newStop.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public StopViewModel? Update(StopBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var stop = context.Stops.Find(filter).FirstOrDefault(); + if (stop == null) + { + return null; + } + + stop.Update(model); + context.Stops.ReplaceOne(filter, stop); + return stop.GetViewModel; + } + + /// + /// Удаление элемента + /// + /// + /// + public StopViewModel? Delete(StopBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var stop = context.Stops.Find(filter).FirstOrDefault(); + if (stop == null) + { + return null; + } + + context.Stops.FindOneAndDelete(filter); + return stop.GetViewModel; + } + + /// + /// Удаление записи + /// + /// + public StopViewModel? Delete() + { + if (!GetFullList().Any()) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + var element = context.Stops.FindOneAndDelete(filter); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = GetFullList().Count; + if (count <= 0) + { + return 0; + } + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + context.Stops.DeleteMany(filter); + return count; + } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Implements/TransportStorage.cs b/RouteGuide/RouteGuideMongoDBImplement/Implements/TransportStorage.cs new file mode 100644 index 0000000..333d9aa --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Implements/TransportStorage.cs @@ -0,0 +1,221 @@ +using MongoDB.Driver; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.SearchModels; +using RouteGuideContracts.StoragesContracts; +using RouteGuideContracts.ViewModels; +using RouteGuideMongoDBImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RouteGuideMongoDBImplement.Implements +{ + /// + /// Хранилище для сущности "Транспорт" + /// + public class TransportStorage : ITransportStorage + { + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Transport + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(TransportSearchModel model) + { + if (string.IsNullOrEmpty(model.License)) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.License, model.License); + + return context.Transport + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + return context.Transport + .Find(filter) + .Limit(count) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение элемента + /// + /// + /// + public TransportViewModel? GetElement(TransportSearchModel model) + { + if (string.IsNullOrEmpty(model.Id?.ToString()) && string.IsNullOrEmpty(model.License)) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + if (!string.IsNullOrEmpty(model.License)) + { + filter &= filterBuilder.Eq(x => x.License, model.License); + } + if (!string.IsNullOrEmpty(model.Id?.ToString())) + { + filter &= filterBuilder.Eq(x => x.Id, model.Id); + } + + return context.Transport + .Find(filter) + .FirstOrDefault() + ?.GetViewModel; + } + + /// + /// Добавление элемента + /// + /// + /// + public TransportViewModel? Insert(TransportBindingModel model) + { + using var context = new RouteGuideDatabase(); + var newTransport = Transport.Create(context, model); + if (newTransport == null) + { + return null; + } + + context.Transport.InsertOne(newTransport); + return newTransport.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public TransportViewModel? Update(TransportBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var transport = context.Transport.Find(filter).FirstOrDefault(); + if (transport == null) + { + return null; + } + + transport.Update(model); + context.Transport.ReplaceOne(filter, transport); + return transport.GetViewModel; + } + + /// + /// Удаление элемента + /// + /// + /// + public TransportViewModel? Delete(TransportBindingModel model) + { + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Eq(x => x.Id, model.Id); + + var transport = context.Transport.Find(filter).FirstOrDefault(); + if (transport == null) + { + return null; + } + + context.Transport.FindOneAndDelete(filter); + return transport.GetViewModel; + } + + /// + /// Удаление записи + /// + /// + public TransportViewModel? Delete() + { + if (!GetFullList().Any()) + { + return null; + } + + using var context = new RouteGuideDatabase(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + var element = context.Transport.FindOneAndDelete(filter); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = GetFullList().Count; + if (count <= 0) + { + return 0; + } + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + + context.Transport.DeleteMany(filter); + return count; + } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Models/Driver.cs b/RouteGuide/RouteGuideMongoDBImplement/Models/Driver.cs new file mode 100644 index 0000000..0401cd1 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Models/Driver.cs @@ -0,0 +1,113 @@ +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; +using RouteGuideDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.ViewModels; + +namespace RouteGuideMongoDBImplement.Models +{ + /// + /// Сущность "Водитель" + /// + public class Driver : IDriverModel + { + /// + /// Идентификатор + /// + [BsonId] + [BsonElement("_id")] + [BsonRepresentation(BsonType.ObjectId)] + public string? Id { get; private set; } + + /// + /// ФИО водителя + /// + [BsonRequired] + public string FullName { get; private set; } = string.Empty; + + /// + /// Номер телефона водителя + /// + [BsonRequired] + public string Phone { get; private set; } = string.Empty; + + /// + /// Опыт работы водителя + /// + [BsonIgnoreIfNull] + [BsonIgnoreIfDefault] + public int? Experience { get; private set; } + + /// + /// Создание модели + /// + /// + /// + public static Driver? Create(DriverBindingModel model) + { + if (model == null) + { + return null; + } + + return new Driver() + { + FullName = model.FullName, + Phone = model.Phone, + Experience = model.Experience + }; + } + + /// + /// Создание модели + /// + /// + /// + public static Driver? Create(DriverViewModel model) + { + if (model == null) + { + return null; + } + + return new Driver() + { + FullName = model.FullName, + Phone = model.Phone, + Experience = model.Experience + }; + } + + /// + /// Изменение модели + /// + /// + public void Update(DriverBindingModel model) + { + if (model == null) + { + return; + } + + FullName = model.FullName; + Phone = model.Phone; + Experience = model.Experience; + } + + /// + /// Получение модели + /// + public DriverViewModel GetViewModel => new() + { + Id = Id!, + FullName = FullName, + Phone = Phone, + Experience = Experience + }; + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Models/Route.cs b/RouteGuide/RouteGuideMongoDBImplement/Models/Route.cs new file mode 100644 index 0000000..587361f --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Models/Route.cs @@ -0,0 +1,150 @@ +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; +using RouteGuideDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.ViewModels; +using MongoDB.Driver; + +namespace RouteGuideMongoDBImplement.Models +{ + /// + /// Сущность "Маршрут" + /// + public class Route : IRouteModel + { + /// + /// Идентификатор + /// + [BsonId] + [BsonElement("_id")] + [BsonRepresentation(BsonType.ObjectId)] + public string? Id { get; private set; } + + /// + /// Название маршрута + /// + [BsonRequired] + public string Name { get; private set; } = string.Empty; + + /// + /// Идентификатор транспорта + /// + [BsonRequired] + [BsonElement("transport_id")] + public string? TransportId { get; private set; } + + /// + /// Сущность "Транспорт" + /// + [BsonIgnoreIfNull] + [BsonIgnoreIfDefault] + public virtual Transport Transport { get; private set; } = new(); + + /// + /// Коллекция остановок маршрута + /// + [BsonElement("Stops")] + public Dictionary? Stops = new(); + + /// + /// Коллекция остановок маршрута + /// + [BsonIgnore] + private Dictionary, int)>? _routeStops = null; + + /// + /// Коллекция остановок маршрута + /// + [BsonIgnore] + public Dictionary, int)>? RouteStops + { + get + { + if (_routeStops == null) + { + _routeStops = Stops? + .ToDictionary(recRS => recRS.Key, recRS => (recRS.Value.Stop as IStopModel, recRS.Value.Number)); + } + return _routeStops; + } + } + + /// + /// Созданме модели + /// + /// + /// + /// + public static Route Create(RouteGuideDatabase context, RouteBindingModel model) + { + return new Route() + { + Name = model.Name, + TransportId = model.TransportId.ToString(), + Transport = context.Transport + .Find(Builders.Filter.Eq(x => x.Id, model.TransportId)) + .FirstOrDefault(), + Stops = model.RouteStops.ToDictionary( + x => x.Key.ToString()!, + x => (context.Stops + .Find(Builders.Filter.Eq(y => y.Id, x.Key)) + .FirstOrDefault(), + x.Value.Item2)) + }; + } + + /// + /// Изменение модели + /// + /// + public void Update(RouteBindingModel model) + { + if (model == null) + { + return; + } + + Name = model.Name; + } + + /// + /// Получение модели + /// + public RouteViewModel GetViewModel => new() + { + Id = Id!, + Name = Name, + TransportId = TransportId!, + RouteStops = RouteStops? + .ToDictionary(recRS => (object)recRS.Key, recRS => (new StopViewModel() + { + Id = (object)recRS.Value.Item1.Id!, + Name = recRS.Value.Item1.Name, + Street = recRS.Value.Item1.Street, + Number = recRS.Value.Item1.Number + } as IStopModel, recRS.Value.Item2)) ?? new(), + TransportLicense = Transport.License + }; + + /// + /// Обновление списка связей + /// + /// + /// + public void UpdateStops(RouteGuideDatabase context, RouteBindingModel model) + { + Stops = model.RouteStops.ToDictionary( + x => x.Key.ToString()!, + x => (context.Stops + .Find(Builders.Filter.Eq(y => y.Id, x.Key)) + .FirstOrDefault(), + x.Value.Item2)); + _routeStops = null; + } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Models/Schedule.cs b/RouteGuide/RouteGuideMongoDBImplement/Models/Schedule.cs new file mode 100644 index 0000000..ab0baef --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Models/Schedule.cs @@ -0,0 +1,122 @@ +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; +using RouteGuideDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.ViewModels; +using MongoDB.Driver; + +namespace RouteGuideMongoDBImplement.Models +{ + /// + /// Сущность "Расписание" + /// + public class Schedule : IScheduleModel + { + /// + /// Идентификатор + /// + [BsonId] + [BsonElement("_id")] + [BsonRepresentation(BsonType.ObjectId)] + public string? Id { get; private set; } + + /// + /// Дата записи расписания + /// + [BsonRequired] + public DateTime Date { get; private set; } = DateTime.Now; + + /// + /// Время отправления + /// + [BsonRequired] + public DateTime DepartureTime { get; private set; } = DateTime.MinValue; + + /// + /// Время прибытия + /// + [BsonRequired] + public DateTime ArrivalTime { get; private set; } = DateTime.MinValue; + + /// + /// Периодичность движения транспорта + /// + [BsonRequired] + public DateTime Frequency { get; private set; } = DateTime.MinValue; + + /// + /// Идентификатор маршрута + /// + [BsonRequired] + [BsonElement("route_id")] + public string? RouteId { get; private set; } + + /// + /// Сущность "Маршрут" + /// + [BsonIgnoreIfNull] + [BsonIgnoreIfDefault] + public virtual Route Route { get; private set; } = new(); + + /// + /// Создание модели + /// + /// + /// + public static Schedule? Create(RouteGuideDatabase context, ScheduleBindingModel model) + { + if (model == null) + { + return null; + } + + return new Schedule() + { + Date = model.Date, + DepartureTime = model.DepartureTime, + ArrivalTime = model.ArrivalTime, + Frequency = model.Frequency, + RouteId = model.RouteId.ToString(), + Route = context.Routes + .Find(Builders.Filter.Eq(x => x.Id, model.RouteId)) + .FirstOrDefault() + }; + } + + /// + /// Изменение модели + /// + /// + public void Update(ScheduleBindingModel model) + { + if (model == null) + { + return; + } + + Date = model.Date; + DepartureTime = model.DepartureTime; + ArrivalTime = model.ArrivalTime; + Frequency = model.Frequency; + } + + /// + /// Получение модели + /// + public ScheduleViewModel GetViewModel => new() + { + Id = Id!, + Date = Date, + DepartureTime = DepartureTime, + ArrivalTime = ArrivalTime, + Frequency = Frequency, + RouteId = RouteId!, + RouteName = Route.Name + }; + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Models/Stop.cs b/RouteGuide/RouteGuideMongoDBImplement/Models/Stop.cs new file mode 100644 index 0000000..6823be8 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Models/Stop.cs @@ -0,0 +1,112 @@ +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.ViewModels; +using RouteGuideDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RouteGuideMongoDBImplement.Models +{ + /// + /// Сущность "Остановка" + /// + public class Stop : IStopModel + { + /// + /// Идентификатор + /// + [BsonId] + [BsonElement("_id")] + [BsonRepresentation(BsonType.ObjectId)] + public string? Id { get; private set; } + + /// + /// Название остановки + /// + [BsonRequired] + public string Name { get; private set; } = string.Empty; + + /// + /// Название улицы + /// + [BsonRequired] + public string Street { get; private set; } = string.Empty; + + /// + /// Номер дома + /// + [BsonRequired] + public int Number { get; private set; } + + /// + /// Создание модели + /// + /// + /// + public static Stop? Create(StopBindingModel model) + { + if (model == null) + { + return null; + } + + return new Stop() + { + Name = model.Name, + Street = model.Street, + Number = model.Number + }; + } + + /// + /// Создание модели + /// + /// + /// + public static Stop? Create(StopViewModel model) + { + if (model == null) + { + return null; + } + + return new Stop() + { + Name = model.Name, + Street = model.Street, + Number = model.Number + }; + } + + /// + /// Изменение модели + /// + /// + public void Update(StopBindingModel model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Street = model.Street; + Number = model.Number; + } + + /// + /// Получение модели + /// + public StopViewModel GetViewModel => new() + { + Id = Id!, + Name = Name, + Street = Street, + Number = Number + }; + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/Models/Transport.cs b/RouteGuide/RouteGuideMongoDBImplement/Models/Transport.cs new file mode 100644 index 0000000..f4dbbc9 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/Models/Transport.cs @@ -0,0 +1,113 @@ +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.ViewModels; +using RouteGuideDataModels.Enums; +using RouteGuideDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; +using MongoDB.Driver; + +namespace RouteGuideMongoDBImplement.Models +{ + /// + /// Сущность "Транспорт" + /// + public class Transport : ITransportModel + { + /// + /// Идентификатор + /// + [BsonId] + [BsonElement("_id")] + [BsonRepresentation(BsonType.ObjectId)] + public string? Id { get; private set; } + + /// + /// Номерной знак + /// + [BsonRequired] + public string License { get; private set; } = string.Empty; + + /// + /// Тип транспортного средства + /// + [BsonRequired] + public TransportType Type { get; private set; } = TransportType.Автобус; + + /// + /// Вместимость (количество пассажиров) + /// + [BsonRequired] + public int Capacity { get; private set; } + + /// + /// Идентификатор водителя + /// + [BsonRequired] + [BsonElement("driver_id")] + public string? DriverId { get; private set; } + + /// + /// Сущность "Водитель" + /// + [BsonIgnoreIfNull] + [BsonIgnoreIfDefault] + public virtual Driver Driver { get; private set; } = new(); + + /// + /// Создание модели + /// + /// + /// + public static Transport? Create(RouteGuideDatabase context, TransportBindingModel model) + { + if (model == null) + { + return null; + } + + return new Transport() + { + License = model.License, + Type = model.Type, + Capacity = model.Capacity, + DriverId = model.DriverId.ToString(), + Driver = context.Drivers + .Find(Builders.Filter.Eq(x => x.Id, model.DriverId)) + .FirstOrDefault() + }; + } + + /// + /// Изменение модели + /// + /// + public void Update(TransportBindingModel model) + { + if (model == null) + { + return; + } + + License = model.License; + Capacity = model.Capacity; + } + + /// + /// Получение модели + /// + public TransportViewModel GetViewModel => new() + { + Id = Id!, + License = License, + Type = Type, + Capacity = Capacity, + DriverId = DriverId!, + DriverName = Driver.FullName + }; + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/RouteGuideDatabase.cs b/RouteGuide/RouteGuideMongoDBImplement/RouteGuideDatabase.cs new file mode 100644 index 0000000..5be4700 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/RouteGuideDatabase.cs @@ -0,0 +1,68 @@ +using MongoDB.Driver; +using RouteGuideMongoDBImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RouteGuideMongoDBImplement +{ + /// + /// Класс для взаимодействия с базой данных + /// + public class RouteGuideDatabase : IDisposable + { + /// + /// Клиент + /// + public readonly MongoClient _client; + + /// + /// База данных + /// + private readonly IMongoDatabase _database; + + /// + /// Конструктор + /// + /// Параметры подключения к базе данных + /// Название базы данных + public RouteGuideDatabase(string connectionString = "mongodb://localhost:27017", + string databaseName = "RouteGuideDatabase") + { + _client = new MongoClient(connectionString); + _database = _client.GetDatabase(databaseName); + } + + /// + /// Коллекция "Водители" + /// + public IMongoCollection Drivers => _database.GetCollection("Drivers"); + + /// + /// Коллекция "Транспорт" + /// + public IMongoCollection Transport => _database.GetCollection("Transport"); + + /// + /// Коллекция "Маршруты" + /// + public IMongoCollection Routes => _database.GetCollection("Routes"); + + /// + /// Коллекция "Остановки" + /// + public IMongoCollection Stops => _database.GetCollection("Stops"); + + /// + /// Коллекция "Расписания" + /// + public IMongoCollection Schedules => _database.GetCollection("Schedules"); + + /// + /// Освободить ресурсы + /// + public void Dispose() { } + } +} diff --git a/RouteGuide/RouteGuideMongoDBImplement/RouteGuideMongoDBImplement.csproj b/RouteGuide/RouteGuideMongoDBImplement/RouteGuideMongoDBImplement.csproj new file mode 100644 index 0000000..fe800d8 --- /dev/null +++ b/RouteGuide/RouteGuideMongoDBImplement/RouteGuideMongoDBImplement.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/RouteGuide/RouteGuideView/FormDriver.cs b/RouteGuide/RouteGuideView/FormDriver.cs index 06e2c70..36c3b10 100644 --- a/RouteGuide/RouteGuideView/FormDriver.cs +++ b/RouteGuide/RouteGuideView/FormDriver.cs @@ -31,12 +31,12 @@ namespace RouteGuideView /// /// Идентификатор /// - private int? _id; + private object? _id; /// /// Идентификатор /// - public int Id { set { _id = value; } } + public object Id { set { _id = value; } } /// /// Конструктор @@ -55,7 +55,7 @@ namespace RouteGuideView /// private void FormDriver_Load(object sender, EventArgs e) { - if (!_id.HasValue) + if (_id == null) { return; } @@ -65,7 +65,7 @@ namespace RouteGuideView _logger.LogInformation("Получение сущности 'Водитель'"); var view = _driverLogic.ReadElement(new DriverSearchModel { - Id = _id.Value + Id = _id }); if (view != null) { @@ -104,13 +104,13 @@ namespace RouteGuideView { var model = new DriverBindingModel { - Id = _id ?? 0, + Id = _id, FullName = textBoxFullName.Text, Phone = textBoxPhone.Text, Experience = int.TryParse(textBoxExperience.Text, out int experience) ? experience : 0 }; - var operationResult = _id.HasValue ? _driverLogic.Update(model) : _driverLogic.Create(model); + var operationResult = _id != null ? _driverLogic.Update(model) : _driverLogic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении сущности 'Водитель'. Дополнительная информация в логах."); diff --git a/RouteGuide/RouteGuideView/FormDrivers.cs b/RouteGuide/RouteGuideView/FormDrivers.cs index 441e355..4d2e2ca 100644 --- a/RouteGuide/RouteGuideView/FormDrivers.cs +++ b/RouteGuide/RouteGuideView/FormDrivers.cs @@ -75,7 +75,7 @@ namespace RouteGuideView var service = Program.ServiceProvider?.GetService(typeof(FormDriver)); if (service is FormDriver form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = dataGridView.SelectedRows[0].Cells["Id"].Value; if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -95,7 +95,7 @@ namespace RouteGuideView { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + object id = dataGridView.SelectedRows[0].Cells["Id"].Value; _logger.LogInformation("Удаление сущности 'Водитель'"); try diff --git a/RouteGuide/RouteGuideView/FormMain.cs b/RouteGuide/RouteGuideView/FormMain.cs index b5d622b..a826fee 100644 --- a/RouteGuide/RouteGuideView/FormMain.cs +++ b/RouteGuide/RouteGuideView/FormMain.cs @@ -197,7 +197,7 @@ namespace RouteGuideView var service = Program.ServiceProvider?.GetService(typeof(FormSchedule)); if (service is FormSchedule form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = dataGridView.SelectedRows[0].Cells["Id"].Value; if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -217,7 +217,7 @@ namespace RouteGuideView { if (MessageBox.Show(" ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + object id = dataGridView.SelectedRows[0].Cells["Id"].Value; _logger.LogInformation(" ''"); try diff --git a/RouteGuide/RouteGuideView/FormRoute.cs b/RouteGuide/RouteGuideView/FormRoute.cs index da9dd4d..8da9f0d 100644 --- a/RouteGuide/RouteGuideView/FormRoute.cs +++ b/RouteGuide/RouteGuideView/FormRoute.cs @@ -39,17 +39,17 @@ namespace RouteGuideView /// /// Идентификатор /// - private int? _id; + private object? _id; /// /// Идентификатор /// - public int Id { set { _id = value; } } + public object Id { set { _id = value; } } /// /// Список остановок в маршруте /// - private Dictionary _routeStops; + private Dictionary, int)> _routeStops; /// /// Конструктор @@ -62,7 +62,7 @@ namespace RouteGuideView _logger = logger; _routeLogic = routeLogic; _transportLogic = transportLogic; - _routeStops = new Dictionary(); + _routeStops = new Dictionary, int)>(); } /// @@ -91,7 +91,7 @@ namespace RouteGuideView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - if (!_id.HasValue) + if (_id == null) { return; } @@ -101,13 +101,13 @@ namespace RouteGuideView _logger.LogInformation("Получение сущности 'Маршрут'"); var view = _routeLogic.ReadElement(new RouteSearchModel { - Id = _id.Value + Id = _id }); if (view != null) { textBoxName.Text = view.Name; comboBoxTransport.SelectedValue = view.TransportId; - _routeStops = view.RouteStops ?? new Dictionary(); + _routeStops = view.RouteStops ?? new Dictionary, int)>(); LoadData(); } } @@ -161,7 +161,7 @@ namespace RouteGuideView var service = Program.ServiceProvider?.GetService(typeof(FormRouteStop)); if (service is FormRouteStop form) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + object id = dataGridView.SelectedRows[0].Cells[0].Value; form.Id = id; form.Number = _routeStops[id].Item2; @@ -194,7 +194,7 @@ namespace RouteGuideView try { _logger.LogInformation("Удаление остановки.{Id}: {StopName} с позиции в маршруте {Number}", dataGridView.SelectedRows[0].Cells[0].Value, dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); - _routeStops.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _routeStops.Remove(dataGridView.SelectedRows[0].Cells[0].Value); } catch (Exception ex) { @@ -241,11 +241,11 @@ namespace RouteGuideView { Id = _id ?? 0, Name = textBoxName.Text, - TransportId = Convert.ToInt32(comboBoxTransport.SelectedValue), + TransportId = comboBoxTransport.SelectedValue, RouteStops = _routeStops }; - var operationResult = _id.HasValue ? _routeLogic.Update(model) : _routeLogic.Create(model); + var operationResult = _id != null ? _routeLogic.Update(model) : _routeLogic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении сущности 'Маршрут'. Дополнительная информация в логах."); diff --git a/RouteGuide/RouteGuideView/FormRouteStop.cs b/RouteGuide/RouteGuideView/FormRouteStop.cs index 9370a0c..4311d53 100644 --- a/RouteGuide/RouteGuideView/FormRouteStop.cs +++ b/RouteGuide/RouteGuideView/FormRouteStop.cs @@ -26,11 +26,11 @@ namespace RouteGuideView /// /// Идентификатор остановки /// - public int Id + public object Id { get { - return Convert.ToInt32(comboBoxStop.SelectedValue); + return comboBoxStop.SelectedValue; } set { @@ -41,7 +41,7 @@ namespace RouteGuideView /// /// Сущность "Остановка" /// - public IStopModel? StopModel + public IStopModel? StopModel { get { diff --git a/RouteGuide/RouteGuideView/FormRoutes.cs b/RouteGuide/RouteGuideView/FormRoutes.cs index c8476c4..70515dc 100644 --- a/RouteGuide/RouteGuideView/FormRoutes.cs +++ b/RouteGuide/RouteGuideView/FormRoutes.cs @@ -78,7 +78,7 @@ namespace RouteGuideView var service = Program.ServiceProvider?.GetService(typeof(FormRoute)); if (service is FormRoute form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = dataGridView.SelectedRows[0].Cells["Id"].Value; if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -98,7 +98,7 @@ namespace RouteGuideView { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + object id = dataGridView.SelectedRows[0].Cells["Id"].Value; _logger.LogInformation("Удаление сущности 'Маршрут'"); try diff --git a/RouteGuide/RouteGuideView/FormRoutesTests.cs b/RouteGuide/RouteGuideView/FormRoutesTests.cs index e7ecc53..c7bcb97 100644 --- a/RouteGuide/RouteGuideView/FormRoutesTests.cs +++ b/RouteGuide/RouteGuideView/FormRoutesTests.cs @@ -67,7 +67,7 @@ namespace RouteGuideView { double time = 0; var stopwatch = new Stopwatch(); - int transportId = _transportLogic.ReadList(1)![0].Id; + object transportId = _transportLogic.ReadList(1)![0].Id; for (int i = 1; i <= entitiesCount; i++) { var model = new RouteBindingModel diff --git a/RouteGuide/RouteGuideView/FormSchedule.cs b/RouteGuide/RouteGuideView/FormSchedule.cs index 0f2398d..17212a5 100644 --- a/RouteGuide/RouteGuideView/FormSchedule.cs +++ b/RouteGuide/RouteGuideView/FormSchedule.cs @@ -38,12 +38,12 @@ namespace RouteGuideView /// /// Идентификатор /// - private int? _id; + private object? _id; /// /// Идентификатор /// - public int Id { set { _id = value; } } + public object Id { set { _id = value; } } /// /// Констурктор @@ -85,7 +85,7 @@ namespace RouteGuideView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - if (!_id.HasValue) + if (_id == null) { return; } @@ -96,7 +96,7 @@ namespace RouteGuideView _logger.LogInformation("Получение сущности 'Расписание'"); var view = _scheduleLogic.ReadElement(new ScheduleSearchModel { - Id = _id.Value + Id = _id }); if (view != null) { @@ -142,10 +142,10 @@ namespace RouteGuideView DepartureTime = dateTimePickerDepartureTime.Value, ArrivalTime = dateTimePickerArrivalTime.Value, Frequency = dateTimePickerFrequency.Value, - RouteId = Convert.ToInt32(comboBoxRoute.SelectedValue) + RouteId = comboBoxRoute.SelectedValue }; - var operationResult = _id.HasValue ? _scheduleLogic.Update(model) : _scheduleLogic.Create(model); + var operationResult = _id != null ? _scheduleLogic.Update(model) : _scheduleLogic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении сущности 'Расписание'. Дополнительная информация в логах."); diff --git a/RouteGuide/RouteGuideView/FormSchedulesTests.cs b/RouteGuide/RouteGuideView/FormSchedulesTests.cs index 476411e..5a5f1f1 100644 --- a/RouteGuide/RouteGuideView/FormSchedulesTests.cs +++ b/RouteGuide/RouteGuideView/FormSchedulesTests.cs @@ -67,7 +67,7 @@ namespace RouteGuideView { double time = 0; var stopwatch = new Stopwatch(); - int routeId = _routeLogic.ReadList(1)![0].Id; + object routeId = _routeLogic.ReadList(1)![0].Id; for (int i = 1; i <= entitiesCount; i++) { var model = new ScheduleBindingModel diff --git a/RouteGuide/RouteGuideView/FormStop.cs b/RouteGuide/RouteGuideView/FormStop.cs index a22c5d2..5aa0701 100644 --- a/RouteGuide/RouteGuideView/FormStop.cs +++ b/RouteGuide/RouteGuideView/FormStop.cs @@ -33,12 +33,12 @@ namespace RouteGuideView /// /// Идентификатор /// - private int? _id; + private object? _id; /// /// Идентификатор /// - public int Id { set { _id = value; } } + public object Id { set { _id = value; } } /// /// Конструктор @@ -57,7 +57,7 @@ namespace RouteGuideView /// private void FormStop_Load(object sender, EventArgs e) { - if (!_id.HasValue) + if (_id == null) { return; } @@ -67,7 +67,7 @@ namespace RouteGuideView _logger.LogInformation("Получение сущности 'Остановка'"); var view = _stopLogic.ReadElement(new StopSearchModel { - Id = _id.Value + Id = _id }); if (view != null) { @@ -117,7 +117,7 @@ namespace RouteGuideView Number = int.TryParse(textBoxNumber.Text, out int number) ? number : 1 }; - var operationResult = _id.HasValue ? _stopLogic.Update(model) : _stopLogic.Create(model); + var operationResult = _id != null ? _stopLogic.Update(model) : _stopLogic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении сущности 'Остановка'. Дополнительная информация в логах."); diff --git a/RouteGuide/RouteGuideView/FormStops.cs b/RouteGuide/RouteGuideView/FormStops.cs index 6bf2d8d..b8bc378 100644 --- a/RouteGuide/RouteGuideView/FormStops.cs +++ b/RouteGuide/RouteGuideView/FormStops.cs @@ -78,7 +78,7 @@ namespace RouteGuideView var service = Program.ServiceProvider?.GetService(typeof(FormStop)); if (service is FormStop form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = dataGridView.SelectedRows[0].Cells["Id"].Value; if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -98,7 +98,7 @@ namespace RouteGuideView { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + object id = dataGridView.SelectedRows[0].Cells["Id"].Value; _logger.LogInformation("Удаление сущности 'Остановка'"); try diff --git a/RouteGuide/RouteGuideView/FormTransport.cs b/RouteGuide/RouteGuideView/FormTransport.cs index e7ddb6e..1d0b0da 100644 --- a/RouteGuide/RouteGuideView/FormTransport.cs +++ b/RouteGuide/RouteGuideView/FormTransport.cs @@ -39,12 +39,12 @@ namespace RouteGuideView /// /// Идентификатор /// - private int? _id; + private object? _id; /// /// Идентификатор /// - public int Id { set { _id = value; } } + public object Id { set { _id = value; } } /// /// Конструктор @@ -92,7 +92,7 @@ namespace RouteGuideView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - if (!_id.HasValue) + if (_id == null) { return; } @@ -103,7 +103,7 @@ namespace RouteGuideView _logger.LogInformation("Получение сущности 'Транспорт'"); var view = _transportLogic.ReadElement(new TransportSearchModel { - Id = _id.Value + Id = _id }); if (view != null) { @@ -157,10 +157,10 @@ namespace RouteGuideView License = textBoxLicense.Text, Type = (TransportType)comboBoxType.SelectedItem, Capacity = int.TryParse(textBoxCapacity.Text, out var capacity) ? capacity : 1, - DriverId = Convert.ToInt32(comboBoxDriver.SelectedValue) + DriverId = comboBoxDriver.SelectedValue }; - var operationResult = _id.HasValue ? _transportLogic.Update(model) : _transportLogic.Create(model); + var operationResult = _id != null ? _transportLogic.Update(model) : _transportLogic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении сущности 'Транспорт'. Дополнительная информация в логах."); diff --git a/RouteGuide/RouteGuideView/FormTransportTests.cs b/RouteGuide/RouteGuideView/FormTransportTests.cs index baec490..14b222e 100644 --- a/RouteGuide/RouteGuideView/FormTransportTests.cs +++ b/RouteGuide/RouteGuideView/FormTransportTests.cs @@ -67,7 +67,7 @@ namespace RouteGuideView { double time = 0; var stopwatch = new Stopwatch(); - int driverId = _driverLogic.ReadList(1)![0].Id; + object driverId = _driverLogic.ReadList(1)![0].Id; for (int i = 1; i <= entitiesCount; i++) { var model = new TransportBindingModel diff --git a/RouteGuide/RouteGuideView/FormTransports.cs b/RouteGuide/RouteGuideView/FormTransports.cs index 25e1194..dba7d31 100644 --- a/RouteGuide/RouteGuideView/FormTransports.cs +++ b/RouteGuide/RouteGuideView/FormTransports.cs @@ -78,7 +78,7 @@ namespace RouteGuideView var service = Program.ServiceProvider?.GetService(typeof(FormTransport)); if (service is FormTransport form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = dataGridView.SelectedRows[0].Cells["Id"].Value; if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -98,7 +98,7 @@ namespace RouteGuideView { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + object id = dataGridView.SelectedRows[0].Cells["Id"].Value; _logger.LogInformation("Удаление сущности 'Транспорт'"); try diff --git a/RouteGuide/RouteGuideView/Program.cs b/RouteGuide/RouteGuideView/Program.cs index d387d6c..9c33870 100644 --- a/RouteGuide/RouteGuideView/Program.cs +++ b/RouteGuide/RouteGuideView/Program.cs @@ -4,7 +4,7 @@ using NLog.Extensions.Logging; using RouteGuideBusinessLogics.BusinessLogics; using RouteGuideContracts.BusinessLogicsContracts; using RouteGuideContracts.StoragesContracts; -using RouteGuideDatabaseImplement.Implements; +using RouteGuideMongoDBImplement.Implements; namespace RouteGuideView { diff --git a/RouteGuide/RouteGuideView/RouteGuideView.csproj b/RouteGuide/RouteGuideView/RouteGuideView.csproj index 64da0a9..b7dc7a2 100644 --- a/RouteGuide/RouteGuideView/RouteGuideView.csproj +++ b/RouteGuide/RouteGuideView/RouteGuideView.csproj @@ -32,6 +32,7 @@ + \ No newline at end of file