diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs index 02ec3d1..45e6334 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BundlingLogic.cs @@ -41,7 +41,7 @@ namespace CarCenterBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + _logger.LogInformation("ReadElement. BundlingId:Id:{ Id}", model.Id); var element = _bundlingStorage.GetElement(model); if (element == null) { diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs index 245313c..b7ede06 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/FeatureLogic.cs @@ -41,7 +41,7 @@ namespace CarCenterBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + _logger.LogInformation("ReadElement. FeatureId:Id:{ Id}", model.Id); var element = _fatureStorage.GetElement(model); if (element == null) { diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/OrderLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..7fddbdd --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,110 @@ +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 OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. OrderId:Id:{ Id}", model.Id); + var element = _orderStorage.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(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(OrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_orderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.BuyerFCS == string.Empty) + { + throw new ArgumentNullException("Нет покупателя", nameof(model.BuyerFCS)); + } + if(model.Sum < 0) + { + throw new ArgumentOutOfRangeException("Сумма меньше нуля",nameof(model.Sum)); + } + _logger.LogInformation("Order. Order:Id:{ Id}.Sum:{ Sum}", model.Id, model.Sum); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs new file mode 100644 index 0000000..651cfc0 --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs @@ -0,0 +1,110 @@ +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 PresaleLogic : IPresaleLogic + { + private readonly ILogger _logger; + private readonly IPresaleStorage _presaleStorage; + public PresaleLogic(ILogger logger, IPresaleStorage presaleStorage) + { + _logger = logger; + _presaleStorage = presaleStorage; + } + + public List? ReadList(PresaleSearchModel? model) + { + _logger.LogInformation("ReadList. PresaleId:Id:{ Id}", model?.Id); + var list = model == null ? _presaleStorage.GetFullList() : _presaleStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public PresaleViewModel? ReadElement(PresaleSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PresaleId:Id:{ Id}", model.Id); + var element = _presaleStorage.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(PresaleBindingModel model) + { + CheckModel(model); + if (_presaleStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(PresaleBindingModel model) + { + CheckModel(model); + if (_presaleStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(PresaleBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_presaleStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PresaleBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Description == string.Empty) + { + throw new ArgumentNullException("Нет описания", nameof(model.Description)); + } + if (model.DueTill < DateTime.Now) + { + throw new InvalidOperationException("Срок выполнения раньше текущего времени"); + } + _logger.LogInformation("Presale. Presale:Id:{ Id}.Price:{ Price}", model.Id, model.Description); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/RequestLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/RequestLogic.cs new file mode 100644 index 0000000..ede807a --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/RequestLogic.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 RequestLogic : IRequestLogic + { + private readonly ILogger _logger; + private readonly IRequestStorage _requestStorage; + public RequestLogic(ILogger logger, IRequestStorage requestStorage) + { + _logger = logger; + _requestStorage = requestStorage; + } + + public List? ReadList(RequestSearchModel? model) + { + _logger.LogInformation("ReadList. RequestId:Id:{ Id}", model?.Id); + var list = model == null ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public RequestViewModel? ReadElement(RequestSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. RequestId:Id:{ Id}", model.Id); + var element = _requestStorage.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(RequestBindingModel model) + { + CheckModel(model); + if (_requestStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(RequestBindingModel model) + { + CheckModel(model); + if (_requestStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(RequestBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_requestStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(RequestBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Description == string.Empty) + { + throw new ArgumentNullException("Нет описания", nameof(model.Description)); + } + _logger.LogInformation("Request. Request:Id:{ Id}.Description:{ Description}", model.Id, model.Description); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs index a23e0e1..f56940a 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/StorekeeperLogic.cs @@ -41,7 +41,7 @@ namespace CarCenterBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + _logger.LogInformation("ReadElement. StorekeeperId:Id:{ Id}", model.Id); var element = _storekeeperStorage.GetElement(model); if (element == null) { @@ -100,7 +100,7 @@ namespace CarCenterBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет телефона", nameof(model.PhoneNumber)); } - _logger.LogInformation("Storekeeper. Storekeeper:Id:{ Id}.Price:{ Price}", model.Id, model.PhoneNumber); + _logger.LogInformation("Storekeeper. Storekeeper:Id:{ Id}.PhoneNumber:{ PhoneNumber}", model.Id, model.PhoneNumber); } } } diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/WorkerLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/WorkerLogic.cs new file mode 100644 index 0000000..4e15bf1 --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/WorkerLogic.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 WorkerLogic : IWorkerLogic + { + private readonly ILogger _logger; + private readonly IWorkerStorage _workerStorage; + public WorkerLogic(ILogger logger, IWorkerStorage workerStorage) + { + _logger = logger; + _workerStorage = workerStorage; + } + + public List? ReadList(WorkerSearchModel? model) + { + _logger.LogInformation("ReadList. WorkerId:Id:{ Id}", model?.Id); + var list = model == null ? _workerStorage.GetFullList() : _workerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public WorkerViewModel? ReadElement(WorkerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id); + var element = _workerStorage.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(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(WorkerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_workerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(WorkerBindingModel 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("Worker. Worker:Id:{ Id}.PhoneNumber:{ PhoneNumber}", model.Id, model.PhoneNumber); + } + } +} diff --git a/CarCenter/CarCenterContracts/SearchModels/OrderSearchModel.cs b/CarCenter/CarCenterContracts/SearchModels/OrderSearchModel.cs index 03f8ad2..9087f3a 100644 --- a/CarCenter/CarCenterContracts/SearchModels/OrderSearchModel.cs +++ b/CarCenter/CarCenterContracts/SearchModels/OrderSearchModel.cs @@ -9,7 +9,5 @@ namespace CarCenterContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } - - public string? BuyerFCS { get; set; } } }