diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj
new file mode 100644
index 0000000..0b64d35
--- /dev/null
+++ b/BusinessLogic/BusinessLogic.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/BusinessLogic/BusinessLogic/RouteLogic.cs b/BusinessLogic/BusinessLogic/RouteLogic.cs
new file mode 100644
index 0000000..e4b150c
--- /dev/null
+++ b/BusinessLogic/BusinessLogic/RouteLogic.cs
@@ -0,0 +1,119 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TransportGuideContracts.BindingModels;
+using TransportGuideContracts.BusinessLogicsContracts;
+using TransportGuideContracts.SearchModels;
+using TransportGuideContracts.StoragesContracts;
+using TransportGuideContracts.ViewModels;
+
+namespace BusinessLogic.BusinessLogic
+{
+ public class RouteLogic : IRouteLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IRouteStorage _routeStorage;
+
+ public RouteLogic(ILogger logger, IRouteStorage routeStorage)
+ {
+ _logger = logger;
+ _routeStorage = routeStorage;
+ }
+
+ public bool Create(RouteBindingModel model)
+ {
+ CheckModel(model);
+ if (_routeStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(RouteBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_routeStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public RouteViewModel? ReadElement(RouteSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. RouteName:{RouteName}.Id:{ Id}", model.Name, model.Id);
+ var element = _routeStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(RouteSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. RouteName:{RoutetName}.Id:{ Id}", model?.Name, model?.Id);
+ var list = model == null ? _routeStorage.GetFullList() : _routeStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool Update(RouteBindingModel model)
+ {
+ CheckModel(model);
+ if (_routeStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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 (string.IsNullOrEmpty(model.IP))
+ {
+ throw new ArgumentNullException("No IP", nameof(model.IP));
+ }
+ _logger.LogInformation("Route. Name:{Name}. IP:{ IP}. Id: { Id}", model.Name, model.IP, model.Id);
+ var element = _routeStorage.GetElement(new RouteSearchModel
+ {
+ Name = model.Name
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Route с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/BusinessLogic/BusinessLogic/StopLogic.cs b/BusinessLogic/BusinessLogic/StopLogic.cs
new file mode 100644
index 0000000..c17e999
--- /dev/null
+++ b/BusinessLogic/BusinessLogic/StopLogic.cs
@@ -0,0 +1,116 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TransportGuideContracts.BindingModels;
+using TransportGuideContracts.BusinessLogicsContracts;
+using TransportGuideContracts.SearchModels;
+using TransportGuideContracts.StoragesContracts;
+using TransportGuideContracts.ViewModels;
+
+namespace BusinessLogic.BusinessLogic
+{
+ public class StopLogic : IStopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IStopStorage _stopStorage;
+
+ public StopLogic(ILogger logger, IStopStorage stopStorage)
+ {
+ _logger = logger;
+ _stopStorage = stopStorage;
+ }
+
+ public bool Create(StopBindingModel model)
+ {
+ CheckModel(model);
+ if (_stopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(StopBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_stopStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public StopViewModel? ReadElement(StopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id);
+ var element = _stopStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(StopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
+ var list = model == null ? _stopStorage.GetFullList() : _stopStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool Update(StopBindingModel model)
+ {
+ CheckModel(model);
+ if (_stopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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));
+ }
+
+ _logger.LogInformation("Stop. Name:{Name}. Id: { Id}", model.Name,model.Id);
+ var element = _stopStorage.GetElement(new StopSearchModel
+ {
+ Name = model.Name
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Stop с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/BusinessLogic/BusinessLogic/TransportTypeLogic.cs b/BusinessLogic/BusinessLogic/TransportTypeLogic.cs
new file mode 100644
index 0000000..34325c3
--- /dev/null
+++ b/BusinessLogic/BusinessLogic/TransportTypeLogic.cs
@@ -0,0 +1,119 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TransportGuideContracts.BindingModels;
+using TransportGuideContracts.BusinessLogicsContracts;
+using TransportGuideContracts.SearchModels;
+using TransportGuideContracts.StoragesContracts;
+using TransportGuideContracts.ViewModels;
+
+namespace BusinessLogic.BusinessLogic
+{
+ public class TransportTypeLogic : ITransportTypeLogic
+ {
+ private readonly ILogger _logger;
+ private readonly ITransportTypeStorage _transportTypeStorage;
+
+ public TransportTypeLogic(ILogger logger, ITransportTypeStorage transportTypeStorage)
+ {
+ _logger = logger;
+ _transportTypeStorage = transportTypeStorage;
+ }
+
+ public bool Create(TransportTypeBindingModel model)
+ {
+ CheckModel(model);
+ if (_transportTypeStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(TransportTypeBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_transportTypeStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public TransportTypeViewModel? ReadElement(TransportTypeSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id);
+ var element = _transportTypeStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(TransportTypeSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
+ var list = model == null ? _transportTypeStorage.GetFullList() : _transportTypeStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool Update(TransportTypeBindingModel model)
+ {
+ CheckModel(model);
+ if (_transportTypeStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(TransportTypeBindingModel 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.Price <= 0)
+ {
+ throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price));
+ }
+ _logger.LogInformation("TransportType. Name:{Name}. Price:{ Price}. Id: { Id}", model.Name, model.Price, model.Id);
+ var element = _transportTypeStorage.GetElement(new TransportTypeSearchModel
+ {
+ Name = model.Name
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Type с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/TransportGuide/TransportGuide.sln b/TransportGuide/TransportGuide.sln
index 97ded1d..ffb9b15 100644
--- a/TransportGuide/TransportGuide.sln
+++ b/TransportGuide/TransportGuide.sln
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportGuideDatabaseImple
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportGuideContracts", "..\TransportGuideContracts\TransportGuideContracts.csproj", "{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "..\BusinessLogic\BusinessLogic.csproj", "{09F7C041-606C-4D60-AF2F-14B030954930}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {09F7C041-606C-4D60-AF2F-14B030954930}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {09F7C041-606C-4D60-AF2F-14B030954930}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {09F7C041-606C-4D60-AF2F-14B030954930}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {09F7C041-606C-4D60-AF2F-14B030954930}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/TransportGuideContracts/BindingModels/TransportTypeBindingModel.cs b/TransportGuideContracts/BindingModels/TransportTypeBindingModel.cs
index d7c65b5..f64919e 100644
--- a/TransportGuideContracts/BindingModels/TransportTypeBindingModel.cs
+++ b/TransportGuideContracts/BindingModels/TransportTypeBindingModel.cs
@@ -9,9 +9,9 @@ namespace TransportGuideContracts.BindingModels
{
public class TransportTypeBindingModel : ITransportTypeModel
{
- public double price { get; set; }
+ public double Price { get; set; }
- public string name { get; set; } = string.Empty;
+ public string Name { get; set; } = string.Empty;
public int Id { get; set; }
}
diff --git a/TransportGuideContracts/ViewModels/TransportTypeViewModel.cs b/TransportGuideContracts/ViewModels/TransportTypeViewModel.cs
index 6e4dbed..5661744 100644
--- a/TransportGuideContracts/ViewModels/TransportTypeViewModel.cs
+++ b/TransportGuideContracts/ViewModels/TransportTypeViewModel.cs
@@ -11,9 +11,9 @@ namespace TransportGuideContracts.ViewModels
public class TransportTypeViewModel : ITransportTypeModel
{
[DisplayName("Ticket's Price")]
- public double price { get; set; }
+ public double Price { get; set; }
[DisplayName("Transport type name")]
- public string name { get; set; } = string.Empty;
+ public string Name { get; set; } = string.Empty;
public int Id { get; set; }
}
diff --git a/TransportGuideDataModels/Models/ITransportTypeModel.cs b/TransportGuideDataModels/Models/ITransportTypeModel.cs
index de6715a..4ac415c 100644
--- a/TransportGuideDataModels/Models/ITransportTypeModel.cs
+++ b/TransportGuideDataModels/Models/ITransportTypeModel.cs
@@ -8,8 +8,8 @@ namespace TransportGuideDataModels.Models
{
public interface ITransportTypeModel : IId
{
- double price { get;}
- string name { get;}
+ double Price { get;}
+ string Name { get;}
}
}