diff --git a/FurnitureFactory/FurnitureContracts/BindingModels/HeadsetBindingModel.cs b/FurnitureFactory/FurnitureContracts/BindingModels/HeadsetBindingModel.cs index 4afb4ff..57c303e 100644 --- a/FurnitureFactory/FurnitureContracts/BindingModels/HeadsetBindingModel.cs +++ b/FurnitureFactory/FurnitureContracts/BindingModels/HeadsetBindingModel.cs @@ -4,6 +4,7 @@ namespace FurnitureContracts.BindingModels { public class HeadsetBindingModel : IHeadsetModel { + public string Title { get; set; } = string.Empty; public string Size { get; set; } = string.Empty; public int Cost { get; set; } public int Id { get; set; } diff --git a/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetModuleSearchModel.cs b/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetModuleSearchModel.cs index fbefb85..9d98bac 100644 --- a/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetModuleSearchModel.cs +++ b/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetModuleSearchModel.cs @@ -8,6 +8,7 @@ namespace FurnitureContracts.SearchModels { public class HeadsetModuleSearchModel { + public string? Title { get; set; } public string? Name { get; set; } public int? Id { get; set; } } diff --git a/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs b/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs index 5d67e7f..9e9d18a 100644 --- a/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs +++ b/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs @@ -8,6 +8,7 @@ namespace FurnitureContracts.SearchModels { public class HeadsetSearchModel { + public string? Title { get; set; } public int? Id { get; set; } public int? ManagerId { get; set; } public string? Size { get; set; } diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs index abd101b..2a543a9 100644 --- a/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs +++ b/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs @@ -10,6 +10,8 @@ namespace FurnitureContracts.ViewModel { public class HeadsetViewModel : IHeadsetModel { + [DisplayName("Название")] + public string? Title { get; set; } = string.Empty; [DisplayName("Цена")] public int Cost { get; set; } diff --git a/FurnitureFactory/FurnitureFactory.sln b/FurnitureFactory/FurnitureFactory.sln index 472e8f3..4192f79 100644 --- a/FurnitureFactory/FurnitureFactory.sln +++ b/FurnitureFactory/FurnitureFactory.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureFactoryDataModels" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureContracts", "FurnitureContracts\FurnitureContracts.csproj", "{E269E4B8-5EAD-4BB2-A8BA-44FE9D202FB6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryDataBaseImplement", "FurnitureFactoryDataBaseImplement\FurnitureFactoryDataBaseImplement.csproj", "{833913DB-1F3F-4700-A200-90759788B1A9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureFactoryDataBaseImplement", "FurnitureFactoryDataBaseImplement\FurnitureFactoryDataBaseImplement.csproj", "{833913DB-1F3F-4700-A200-90759788B1A9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryBusinessLogic", "FurnitureFactoryBusinessLogic\FurnitureFactoryBusinessLogic.csproj", "{F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {833913DB-1F3F-4700-A200-90759788B1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU {833913DB-1F3F-4700-A200-90759788B1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU {833913DB-1F3F-4700-A200-90759788B1A9}.Release|Any CPU.Build.0 = Release|Any CPU + {F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/HeadsetLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/HeadsetLogic.cs new file mode 100644 index 0000000..b6b91f6 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/HeadsetLogic.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using FurnitureContracts.BindingModels; +using FurnitureContracts.BusinessLogicsContracts; +using FurnitureContracts.SearchModels; +using FurnitureContracts.StoragesContracts; +using FurnitureContracts.ViewModel; +using FurnitureFactoryDataBaseImplements.Implements; + +namespace FurnitureFactoryBusinessLogic.BusinessLogic +{ + internal class HeadsetLogic + { + private readonly ILogger _logger; + private readonly IHeadsetStorage _headsetStorage; + public HeadsetLogic(ILogger logger, IHeadsetStorage headsetStorage) + { + _logger = logger; + _headsetStorage = headsetStorage; + } + public List? ReadList(HeadsetSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _headsetStorage.GetFullList() : _headsetStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public HeadsetViewModel? ReadElement(HeadsetSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id); + var element = _headsetStorage.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(HeadsetBindingModel model) + { + CheckModel(model); + if (_headsetStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(HeadsetBindingModel model) + { + CheckModel(model); + if (_headsetStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(HeadsetBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_headsetStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(HeadsetBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Неверно задана цена", nameof(model.Cost)); + } + if (string.IsNullOrEmpty(model.Size)) + { + throw new ArgumentNullException("Не задан размер", nameof(model.Size)); + } + if (model.ManagerId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор менеджера", nameof(model.ManagerId)); + } + if (model.HeadsetModuleId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор гарнитура", nameof(model.HeadsetModuleId)); + } + + _logger.LogInformation("Headset. Title:{Title}.Size{Size}.Cost{Cost}.StudentId:{StudentId}.TaskId{TaskId} Id: {Id}", model.Title, model.Size, model.Cost, model.ManagerId, model.HeadsetModuleId, model.Id); + var element = _headsetStorage.GetElement(new HeadsetSearchModel + { + Title = model.Title, + ManagerId = model.ManagerId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Гарнитур с таким названием уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ManagerLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ManagerLogic.cs new file mode 100644 index 0000000..b00e5c9 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ManagerLogic.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.Logging; +using FurnitureContracts.BindingModels; +using FurnitureContracts.BusinessLogicsContracts; +using FurnitureContracts.SearchModels; +using FurnitureContracts.StoragesContracts; +using FurnitureContracts.ViewModel; +using FurnitureFactoryDataBaseImplements.Implements; + + +namespace FurnitureFactoryBusinessLogic.BusinessLogic +{ + internal class ManagerLogic + { + private readonly ILogger _logger; + private readonly IManagerStorage _managerStorage; + public ManagerLogic(ILogger logger, IManagerStorage managerStorage) + { + _logger = logger; + _managerStorage = managerStorage; + } + public List? ReadList(ManagerSearchModel? model) + { + _logger.LogInformation("ReadList. Login:{Login}.Id:{ Id}", model?.Login, model?.Id); + var list = model == null ? _managerStorage.GetFullList() : _managerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ManagerViewModel? ReadElement(ManagerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Login:{Login}. Id:{ Id}", model.Login, model.Id); + var element = _managerStorage.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(ManagerBindingModel model) + { + CheckModel(model); + if (_managerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ManagerBindingModel model) + { + CheckModel(model); + if (_managerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ManagerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_managerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ManagerBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Не задан логин", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Не задан пароль", nameof(model.Password)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Не задана почта", nameof(model.Email)); + } + + if (string.IsNullOrEmpty(model.UserName)) + { + throw new ArgumentNullException("Не задано ФИО", nameof(model.UserName)); + } + _logger.LogInformation("Student. Name:{Name}. Email{Email}.Login{Login} .Password{Password} Id: {Id}", model.UserName, model.Email, model.Login, model.Password, model.Id); + var element = _managerStorage.GetElement(new ManagerSearchModel + { + Login = model.Login + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Школьник с таким логином уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..21aa8eb --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using FurnitureContracts.BindingModels; +using FurnitureContracts.BusinessLogicsContracts; +using FurnitureContracts.SearchModels; +using FurnitureContracts.StoragesContracts; +using FurnitureContracts.ViewModel; +using FurnitureFactoryDataBaseImplements.Implements; + +namespace FurnitureFactoryBusinessLogic.BusinessLogic +{ + internal class OrderLogic + { + private readonly ILogger _logger; + private readonly IOrdersStorage _orderStorage; + public OrderLogic(ILogger logger, IOrdersStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, 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 OrdersViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, 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(OrdersBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(OrdersBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(OrdersBindingModel 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(OrdersBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Не задано название", nameof(model.Title)); + } + if (string.IsNullOrEmpty(model.Status)) + { + throw new ArgumentNullException("Не задано описание", nameof(model.Status)); + } + if (model.ManagerId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор школьника", nameof(model.ManagerId)); + } + + + _logger.LogInformation("Product. Titel:{Title}.Status{Status}.ManagerId:{ManagerId}. Id: {Id}", model.Title, model.Status, model.ManagerId, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Title = model.Title, + ManagerId = model.ManagerId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs new file mode 100644 index 0000000..628a35f --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using FurnitureContracts.BindingModels; +using FurnitureContracts.BusinessLogicsContracts; +using FurnitureContracts.SearchModels; +using FurnitureContracts.StoragesContracts; +using FurnitureContracts.ViewModel; +using FurnitureFactoryDataBaseImplements.Implements; + +namespace FurnitureFactoryBusinessLogic.BusinessLogic +{ + internal class SalesSalonLogic + { + private readonly ILogger _logger; + private readonly ISalesSalonsStorage _salesSalonStorage; + public SalesSalonLogic(ILogger logger, ISalesSalonsStorage salesSalonStorage) + { + _logger = logger; + _salesSalonStorage = salesSalonStorage; + } + public List? ReadList(SalesSalonsSearchModel? model) + { + _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _salesSalonStorage.GetFullList() : _salesSalonStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public SalesSalonsViewModel? ReadElement(SalesSalonsSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id); + var element = _salesSalonStorage.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(SalesSalonsBindingModel model) + { + CheckModel(model); + if (_salesSalonStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(SalesSalonsBindingModel model) + { + CheckModel(model); + if (_salesSalonStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(SalesSalonsBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_salesSalonStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(SalesSalonsBindingModel 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.Address)) + { + throw new ArgumentNullException("Не задан адресс", nameof(model.Address)); + } + if (model.ManagerId <= 0) + { + throw new ArgumentNullException("Неверно задан идентификатор менеджера", nameof(model.ManagerId)); + } + _logger.LogInformation("Interest. Name:{Name}.Address{Address}.ManagerId:{ManagerId}. Id: {Id}", model.Name, model.Address, model.ManagerId, model.Id); + var element = _salesSalonStorage.GetElement(new SalesSalonsSearchModel + { + Name = model.Name, + ManagerId = model.ManagerId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Салон с таким названием уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/Class1.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/Class1.cs deleted file mode 100644 index 2dfbad1..0000000 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace FurnitureFactoryBusinessLogic -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj b/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj index 132c02c..1b1970b 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj @@ -6,4 +6,10 @@ enable + + + + + + diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Headset.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Headset.cs index f5ad514..c8a4d5d 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Headset.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Headset.cs @@ -14,6 +14,9 @@ namespace FurnitureFactoryDataBaseImplement.Models { public class Headset { + [Required] + public string Title { get; set; } = string.Empty; + [Required] public string Size { get; set; } = string.Empty; [Required] @@ -48,6 +51,7 @@ namespace FurnitureFactoryDataBaseImplement.Models return new Headset() { Id = model.Id, + Title = model.Title, Size = model.Size, HeadsetModuleId = model.HeadsetModuleId, ManagerId = model.ManagerId, @@ -67,6 +71,7 @@ namespace FurnitureFactoryDataBaseImplement.Models public HeadsetViewModel GetViewModel => new() { Id = Id, + Title = Title, Size = Size, Cost = Cost, HeadsetModuleId = HeadsetModuleId, diff --git a/FurnitureFactory/FurnitureFactoryDataModels/Models/IHeadsetModel.cs b/FurnitureFactory/FurnitureFactoryDataModels/Models/IHeadsetModel.cs index b6bf794..9fe00df 100644 --- a/FurnitureFactory/FurnitureFactoryDataModels/Models/IHeadsetModel.cs +++ b/FurnitureFactory/FurnitureFactoryDataModels/Models/IHeadsetModel.cs @@ -8,6 +8,7 @@ namespace FurnitureFactoryDataModels.Models { public interface IHeadsetModel : IId { + string Title { get; } int Cost { get;} string Size { get; } public Dictionary HeadsetSalesSalons { get; }