diff --git a/RouteGuide/RouteGuide.sln b/RouteGuide/RouteGuide.sln index d51dd79..99b0ab2 100644 --- a/RouteGuide/RouteGuide.sln +++ b/RouteGuide/RouteGuide.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideDataModels", "Rou EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideContracts", "RouteGuideContracts\RouteGuideContracts.csproj", "{895094AD-E3AC-4E1F-83DC-283E65EB072F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideDatabaseImplement", "RouteGuideDatabaseImplement\RouteGuideDatabaseImplement.csproj", "{5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}" +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}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}.Debug|Any CPU.Build.0 = Debug|Any CPU {5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C2BBCAA-01A8-4B4C-B296-E7CF8DFBA884}.Release|Any CPU.Build.0 = Release|Any CPU + {7B6C15DA-C491-4EE1-BEC8-C7FE580C2BA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs new file mode 100644 index 0000000..555310a --- /dev/null +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs @@ -0,0 +1,177 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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; + +namespace RouteGuideBusinessLogics.BusinessLogics +{ + /// + /// Бизнес-логика для сущности "Водитель" + /// + public class DriverLogic : IDriverLogic + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly IDriverStorage _driverStorage; + + /// + /// Конструктор + /// + /// + /// + public DriverLogic(ILogger logger, IDriverStorage driverStorage) + { + _logger = logger; + _driverStorage = driverStorage; + } + + /// + /// Получение списка + /// + /// + /// + public List? ReadList(DriverSearchModel? model) + { + _logger.LogInformation("ReadList. Driver.Id: {Id}", model?.Id); + + var list = model == null ? _driverStorage.GetFullList() : _driverStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + /// + /// Получение отдельной записи + /// + /// + /// + /// + public DriverViewModel? ReadElement(DriverSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Driver.Id: {Id}", model?.Id); + + var element = _driverStorage.GetElement(model!); + if (element == null) + { + _logger.LogWarning("ReadElement. Element not found"); + return null; + } + + _logger.LogInformation("ReadElement. Find Driver.Id: {Id}", element.Id); + return element; + } + + /// + /// Создание записи + /// + /// + /// + public bool Create(DriverBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Create. Driver.Id: {Id}", model.Id); + + if (_driverStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Изменение записи + /// + /// + /// + public bool Update(DriverBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Update. Driver.Id: {Id}", model.Id); + + if (_driverStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + /// + /// Удаление записи + /// + /// + /// + public bool Delete(DriverBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Driver.Id: {Id}", model.Id); + + if (_driverStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Проверка модели + /// + /// + /// + private void CheckModel(DriverBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FullName)) + { + throw new ArgumentNullException("Не указано ФИО водителя", nameof(model.FullName)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Не указан номер телефона водителя", nameof(model.Phone)); + } + + _logger.LogInformation("CheckModel. Driver.Id: {Id}", model.Id); + + var element = _driverStorage.GetElement(new DriverSearchModel + { + Phone = model.Phone + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Водитель с таким номером телефона уже существует"); + } + } + } +} diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs new file mode 100644 index 0000000..7cef2bd --- /dev/null +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs @@ -0,0 +1,177 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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; + +namespace RouteGuideBusinessLogics.BusinessLogics +{ + /// + /// Бизнес-логика для сущности "Маршрут" + /// + public class RouteLogic : IRouteLogic + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly IRouteStorage _routeStorage; + + /// + /// Конструктор + /// + /// + /// + public RouteLogic(ILogger logger, IRouteStorage routeStorage) + { + _logger = logger; + _routeStorage = routeStorage; + } + + /// + /// Получение списка + /// + /// + /// + public List? ReadList(RouteSearchModel? model) + { + _logger.LogInformation("ReadList. Route: {Name}.{Id}", model?.Id, model?.Name); + + var list = model == null ? _routeStorage.GetFullList() : _routeStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + /// + /// Получение отдельной записи + /// + /// + /// + /// + public RouteViewModel? ReadElement(RouteSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Route: {Name}.{Id}", model?.Id, model?.Name); + + var element = _routeStorage.GetElement(model!); + if (element == null) + { + _logger.LogWarning("ReadElement. Element not found"); + return null; + } + + _logger.LogInformation("ReadElement. Find Route.Id: {Id}", element.Id); + return element; + } + + /// + /// Создание записи + /// + /// + /// + public bool Create(RouteBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Create. Route.Id: {Id}", model.Id); + + if (_routeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Изменение записи + /// + /// + /// + public bool Update(RouteBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Update. Route.Id: {Id}", model.Id); + + if (_routeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + /// + /// Удаление записи + /// + /// + /// + public bool Delete(RouteBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Route.Id: {Id}", model.Id); + + if (_routeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Проверка модели + /// + /// + /// + private void CheckModel(RouteBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Не указано название маршрута", nameof(model.Name)); + } + if (model.TransportId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор транспортного средства", nameof(model.TransportId)); + } + + _logger.LogInformation("CheckModel. Route.Id: {Id}", model.Id); + + var element = _routeStorage.GetElement(new RouteSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Маршрут с таким названием уже существует"); + } + } + } +} diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs new file mode 100644 index 0000000..00e9f52 --- /dev/null +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs @@ -0,0 +1,164 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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; + +namespace RouteGuideBusinessLogics.BusinessLogics +{ + /// + /// Бизнес-логика для сущности "Расписание" + /// + public class ScheduleLogic : IScheduleLogic + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly IScheduleStorage _scheduleStorage; + + /// + /// Конструктор + /// + /// + /// + public ScheduleLogic(ILogger logger, IScheduleStorage scheduleStorage) + { + _logger = logger; + _scheduleStorage = scheduleStorage; + } + + /// + /// Получение списка + /// + /// + /// + public List? ReadList(ScheduleSearchModel? model) + { + _logger.LogInformation("ReadList. Schedule.{Id}", model?.Id); + + var list = model == null ? _scheduleStorage.GetFullList() : _scheduleStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + /// + /// Получение отдельной записи + /// + /// + /// + /// + public ScheduleViewModel? ReadElement(ScheduleSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Schedule.{Id}", model?.Id); + + var element = _scheduleStorage.GetElement(model!); + if (element == null) + { + _logger.LogWarning("ReadElement. Element not found"); + return null; + } + + _logger.LogInformation("ReadElement. Find Schedule.Id: {Id}", element.Id); + return element; + } + + /// + /// Создание записи + /// + /// + /// + public bool Create(ScheduleBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Create. Schedule.Id: {Id}", model.Id); + + if (_scheduleStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Изменение записи + /// + /// + /// + public bool Update(ScheduleBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Update. Schedule.Id: {Id}", model.Id); + + if (_scheduleStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + /// + /// Удаление записи + /// + /// + /// + public bool Delete(ScheduleBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Schedule.Id: {Id}", model.Id); + + if (_scheduleStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Проверка модели + /// + /// + /// + private void CheckModel(ScheduleBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.RouteId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор маршрута", nameof(model.RouteId)); + } + + _logger.LogInformation("CheckModel. Schedule.Id: {Id}", model.Id); + } + } +} diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs new file mode 100644 index 0000000..afa080f --- /dev/null +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs @@ -0,0 +1,181 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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; + +namespace RouteGuideBusinessLogics.BusinessLogics +{ + /// + /// Бизнес-логика для сущности "Остановка" + /// + public class StopLogic : IStopLogic + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly IStopStorage _stopStorage; + + /// + /// Конструктор + /// + /// + /// + public StopLogic(ILogger logger, IStopStorage stopStorage) + { + _logger = logger; + _stopStorage = stopStorage; + } + + /// + /// Получение списка + /// + /// + /// + public List? ReadList(StopSearchModel? model) + { + _logger.LogInformation("ReadList. Stop: {Name}.{Id}", model?.Id, model?.Name); + + var list = model == null ? _stopStorage.GetFullList() : _stopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + /// + /// Получение отдельной записи + /// + /// + /// + /// + public StopViewModel? ReadElement(StopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Stop: {Name}.{Id}", model?.Id, model?.Name); + + var element = _stopStorage.GetElement(model!); + if (element == null) + { + _logger.LogWarning("ReadElement. Element not found"); + return null; + } + + _logger.LogInformation("ReadElement. Find Stop.Id: {Id}", element.Id); + return element; + } + + /// + /// Создание записи + /// + /// + /// + public bool Create(StopBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Create. Stop.Id: {Id}", model.Id); + + if (_stopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Изменение записи + /// + /// + /// + public bool Update(StopBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Update. Stop.Id: {Id}", model.Id); + + if (_stopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + /// + /// Удаление записи + /// + /// + /// + public bool Delete(StopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Stop.Id: {Id}", model.Id); + + if (_stopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Проверка модели + /// + /// + /// + private void CheckModel(StopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Не указано название остановки", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Street)) + { + throw new ArgumentNullException("Не указано название улицы", nameof(model.Street)); + } + if (model.Number <= 0) + { + throw new ArgumentNullException("Не указан номер дома", nameof(model.Number)); + } + + _logger.LogInformation("CheckModel. Stop.Id: {Id}", model.Id); + + var element = _stopStorage.GetElement(new StopSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Остановка с таким названием уже существует"); + } + } + } +} diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs new file mode 100644 index 0000000..d7a6714 --- /dev/null +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs @@ -0,0 +1,181 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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; + +namespace RouteGuideBusinessLogics.BusinessLogics +{ + /// + /// Бизнес-логика для сущности "Транспорт" + /// + public class TransportLogic : ITransportLogic + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly ITransportStorage _transportStorage; + + /// + /// Конструктор + /// + /// + /// + public TransportLogic(ILogger logger, ITransportStorage transportStorage) + { + _logger = logger; + _transportStorage = transportStorage; + } + + /// + /// Получение списка + /// + /// + /// + public List? ReadList(TransportSearchModel? model) + { + _logger.LogInformation("ReadList. Transport: {Id}.{License}", model?.Id, model?.License); + + var list = model == null ? _transportStorage.GetFullList() : _transportStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + /// + /// Получение отдельной записи + /// + /// + /// + /// + public TransportViewModel? ReadElement(TransportSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Transport: {Id}.{License}", model?.Id, model?.License); + + var element = _transportStorage.GetElement(model!); + if (element == null) + { + _logger.LogWarning("ReadElement. Element not found"); + return null; + } + + _logger.LogInformation("ReadElement. Find Transport.Id: {Id}", element.Id); + return element; + } + + /// + /// Создание записи + /// + /// + /// + public bool Create(TransportBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Create. Transport.Id: {Id}", model.Id); + + if (_transportStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Изменение записи + /// + /// + /// + public bool Update(TransportBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Update. Transport.Id: {Id}", model.Id); + + if (_transportStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + /// + /// Удаление записи + /// + /// + /// + public bool Delete(TransportBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Transport.Id: {Id}", model.Id); + + if (_transportStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Проверка модели + /// + /// + /// + private void CheckModel(TransportBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.License)) + { + throw new ArgumentNullException("Не указан номерной знак транспортного средства", nameof(model.License)); + } + if (model.Capacity <= 0) + { + throw new ArgumentNullException("Вместимость транспортного средства должна быть положительным числом", nameof(model.Capacity)); + } + if (model.DriverId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор водителя", nameof(model.DriverId)); + } + + _logger.LogInformation("CheckModel. Transport.Id: {Id}", model.Id); + + var element = _transportStorage.GetElement(new TransportSearchModel + { + License = model.License + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Транспортное средство с таким номерным знаком уже есть"); + } + } + } +} diff --git a/RouteGuide/RouteGuideBusinessLogics/Class1.cs b/RouteGuide/RouteGuideBusinessLogics/Class1.cs deleted file mode 100644 index b9837c8..0000000 --- a/RouteGuide/RouteGuideBusinessLogics/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace RouteGuideBusinessLogics -{ - public class Class1 - { - - } -} diff --git a/RouteGuide/RouteGuideBusinessLogics/RouteGuideBusinessLogics.csproj b/RouteGuide/RouteGuideBusinessLogics/RouteGuideBusinessLogics.csproj index 132c02c..dfa310e 100644 --- a/RouteGuide/RouteGuideBusinessLogics/RouteGuideBusinessLogics.csproj +++ b/RouteGuide/RouteGuideBusinessLogics/RouteGuideBusinessLogics.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs index 84aeb86..25da1ec 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs @@ -15,44 +15,38 @@ namespace RouteGuideContracts.BusinessLogicsContracts public interface IStopLogic { /// - /// Получение полного списка - /// - /// - List GetFullList(); - - /// - /// Получение фильтрованного списка + /// Получение списка /// /// /// - List GetFilteredList(StopSearchModel model); + List? ReadList(StopSearchModel? model); /// - /// Получение элемента + /// Получение отдельной записи /// /// /// - StopViewModel? GetElement(StopSearchModel model); + StopViewModel? ReadElement(StopSearchModel model); /// - /// Добавление элемента + /// Создание записи /// /// /// - StopViewModel? Insert(StopBindingModel model); + bool Create(StopBindingModel model); /// - /// Редактирование элемента + /// Изменение записи /// /// /// - StopViewModel? Update(StopBindingModel model); + bool Update(StopBindingModel model); /// - /// Удаление элемента + /// Удаление записи /// /// /// - StopViewModel? Delete(StopBindingModel model); + bool Delete(StopBindingModel model); } } diff --git a/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs b/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs index acb97df..c9d079c 100644 --- a/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs +++ b/RouteGuide/RouteGuideContracts/SearchModels/DriverSearchModel.cs @@ -16,5 +16,10 @@ namespace RouteGuideContracts.SearchModels /// Идентификатор /// public int? Id { get; set; } + + /// + /// Номер телефона водителя + /// + public string? Phone { get; set; } } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs index 948576e..56da60c 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs @@ -35,14 +35,14 @@ namespace RouteGuideDatabaseImplement.Implements /// public List GetFilteredList(DriverSearchModel model) { - if (!model.Id.HasValue) + if (string.IsNullOrEmpty(model.Phone)) { return new(); } using var context = new RouteGuideDatabase(); return context.Drivers - .Where(x => x.Id == model.Id) + .Where(x => x.Phone.Contains(model.Phone)) .Select(x => x.GetViewModel) .ToList(); } @@ -54,14 +54,14 @@ namespace RouteGuideDatabaseImplement.Implements /// public DriverViewModel? GetElement(DriverSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Phone)) { return null; } using var context = new RouteGuideDatabase(); return context.Drivers - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Phone) && x.Phone.Contains(model.Phone)) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs index 0ae8099..4e7463d 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs @@ -40,7 +40,7 @@ namespace RouteGuideDatabaseImplement.Implements /// public List GetFilteredList(RouteSearchModel model) { - if (!model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name)) { return new(); } @@ -51,7 +51,7 @@ namespace RouteGuideDatabaseImplement.Implements .Include(x => x.Stops) .ThenInclude(x => x.Stop) .ToList() - .Where(x => x.Id == model.Id) + .Where(x => x.Name.Contains(model.Name)) .Select(x => x.GetViewModel) .ToList(); } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs index 46914ba..246caaa 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs @@ -35,14 +35,14 @@ namespace RouteGuideDatabaseImplement.Implements /// public List GetFilteredList(StopSearchModel model) { - if (!model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name)) { return new(); } using var context = new RouteGuideDatabase(); return context.Stops - .Where(x => x.Id == model.Id) + .Where(x => x.Name.Contains(model.Name)) .Select(x => x.GetViewModel) .ToList(); } @@ -54,14 +54,14 @@ namespace RouteGuideDatabaseImplement.Implements /// public StopViewModel? GetElement(StopSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name)) { return null; } using var context = new RouteGuideDatabase(); return context.Stops - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/RouteGuide/RouteGuideView/RouteGuideView.csproj b/RouteGuide/RouteGuideView/RouteGuideView.csproj index b57c89e..508eab8 100644 --- a/RouteGuide/RouteGuideView/RouteGuideView.csproj +++ b/RouteGuide/RouteGuideView/RouteGuideView.csproj @@ -8,4 +8,10 @@ enable + + + + + + \ No newline at end of file