From 8945da0c2aa4e4daea15be10cad4548be1ebdb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Sun, 28 Apr 2024 12:09:39 +0400 Subject: [PATCH 1/4] BundlingLogic --- .../BusinessLogics/BundlingLogic.cs | 107 ++++++++++++++++++ .../CarCenterBusinessLogic.csproj | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs new file mode 100644 index 0000000..9e195ca --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs @@ -0,0 +1,107 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class BundlingLogic : IBundlingLogic + { + private readonly ILogger _logger; + private readonly IBundlingStorage _bundlingStorage; + public BundlingLogic(ILogger logger, IBundlingStorage bundlingStorage) + { + _logger = logger; + _bundlingStorage = bundlingStorage; + } + + public List? ReadList(BundlingSearchModel? model) + { + _logger.LogInformation("ReadList. BundlingId:Id:{ Id}", model?.Id); + var list = model == null ? _bundlingStorage.GetFullList() : _bundlingStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public BundlingViewModel? ReadElement(BundlingSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + var element = _bundlingStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(BundlingBindingModel model) + { + CheckModel(model); + if (_bundlingStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(BundlingBindingModel model) + { + CheckModel(model); + if (_bundlingStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(BundlingBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_bundlingStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(BundlingBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Component. Bundling:Id:{ Id}.Price:{ Price}", model.Id, model.Price); + } + + } +} diff --git a/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj b/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj index 3daf2c3..2f2461b 100644 --- a/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj +++ b/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj @@ -7,7 +7,7 @@ - + -- 2.25.1 From 58629c909033c8e52deba52eb861d461a702f702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Sun, 28 Apr 2024 12:22:44 +0400 Subject: [PATCH 2/4] CarLogic + fix --- .../BusinessLogics/BundlingLogic.cs | 2 +- .../BusinessLogics/CarLogic.cs | 114 ++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs index 9e195ca..02ec3d1 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs @@ -100,7 +100,7 @@ namespace CarCenterBusinessLogic.BusinessLogics { throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Component. Bundling:Id:{ Id}.Price:{ Price}", model.Id, model.Price); + _logger.LogInformation("Bundling. Bundling:Id:{ Id}.Price:{ Price}", model.Id, model.Price); } } diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs new file mode 100644 index 0000000..62ebf09 --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs @@ -0,0 +1,114 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class CarLogic : ICarLogic + { + private readonly ILogger _logger; + private readonly ICarStorage _carStorage; + public CarLogic(ILogger logger, ICarStorage carStorage) + { + _logger = logger; + _carStorage = carStorage; + } + + public List? ReadList(CarSearchModel? model) + { + _logger.LogInformation("ReadList. VINnumber:{VINnumber}.Id:{ Id}", model?.VINnumber, model?.Id); + var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public CarViewModel? ReadElement(CarSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. VINnumber:{VINnumber}.Id:{ Id}", model?.VINnumber, model?.Id); + var element = _carStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(CarBindingModel model) + { + CheckModel(model); + if (_carStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(CarBindingModel model) + { + CheckModel(model); + if (_carStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(CarBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_carStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(CarBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.VINnumber <= 0) + { + throw new ArgumentNullException("Нет VIN-номера", nameof(model.VINnumber)); + } + _logger.LogInformation("Car. VINnumber:{VINnumber}. Id: { Id}", model.VINnumber, model.Id); + var element = _carStorage.GetElement(new CarSearchModel + { + VINnumber = model.VINnumber, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким VIN-номером уже есть"); + } + } + } +} -- 2.25.1 From c377580e98c522c3c6ea04272a5bfca80fea639d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Sun, 28 Apr 2024 12:25:58 +0400 Subject: [PATCH 3/4] FeatureLogic --- .../BusinessLogics/FeatureLogic.cs | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs new file mode 100644 index 0000000..245313c --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs @@ -0,0 +1,106 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class FeatureLogic : IFeatureLogic + { + private readonly ILogger _logger; + private readonly IFeatureStorage _fatureStorage; + public FeatureLogic(ILogger logger, IFeatureStorage fatureStorage) + { + _logger = logger; + _fatureStorage = fatureStorage; + } + + public List? ReadList(FeatureSearchModel? model) + { + _logger.LogInformation("ReadList. FeatureId:Id:{ Id}", model?.Id); + var list = model == null ? _fatureStorage.GetFullList() : _fatureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public FeatureViewModel? ReadElement(FeatureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + var element = _fatureStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(FeatureBindingModel model) + { + CheckModel(model); + if (_fatureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(FeatureBindingModel model) + { + CheckModel(model); + if (_fatureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(FeatureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_fatureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(FeatureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Feature. Feature:Id:{ Id}.Price:{ Price}", model.Id, model.Price); + } + } +} -- 2.25.1 From 030b918bacdd1870929416e507b3e6061b8399e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Sun, 28 Apr 2024 12:28:30 +0400 Subject: [PATCH 4/4] StorekeeperStorage. All BusinessLogics done --- .../BusinessLogics/StorekeeperLogic.cs | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs new file mode 100644 index 0000000..a23e0e1 --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs @@ -0,0 +1,106 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class StorekeeperLogic : IStorekeeperLogic + { + private readonly ILogger _logger; + private readonly IStorekeeperStorage _storekeeperStorage; + public StorekeeperLogic(ILogger logger, IStorekeeperStorage storekeeperStorage) + { + _logger = logger; + _storekeeperStorage = storekeeperStorage; + } + + public List? ReadList(StorekeeperSearchModel? model) + { + _logger.LogInformation("ReadList. StorekeeperId:Id:{ Id}", model?.Id); + var list = model == null ? _storekeeperStorage.GetFullList() : _storekeeperStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public StorekeeperViewModel? ReadElement(StorekeeperSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + var element = _storekeeperStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(StorekeeperBindingModel model) + { + CheckModel(model); + if (_storekeeperStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(StorekeeperBindingModel model) + { + CheckModel(model); + if (_storekeeperStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(StorekeeperBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_storekeeperStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(StorekeeperBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PhoneNumber <= 0) + { + throw new ArgumentNullException("Нет телефона", nameof(model.PhoneNumber)); + } + _logger.LogInformation("Storekeeper. Storekeeper:Id:{ Id}.Price:{ Price}", model.Id, model.PhoneNumber); + } + } +} -- 2.25.1