From 7b7ced25dd0f88a60c1446c9596054ccdc44ac0b Mon Sep 17 00:00:00 2001 From: bocchanskyy Date: Tue, 27 Aug 2024 21:51:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=20=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=84=D0=B8=D0=BA=D1=81=D0=BE=D0=B2...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeautyStudio/BeautyStudio.sln | 10 +- .../BusinessLogic/LaborCostLogic.cs | 9 + .../BusinessLogic/OrderLogic.cs | 161 +++++++------ .../BusinessLogic/ReportLogic.cs | 8 +- .../BindingModels/CosmeticBindingModel.cs | 6 +- .../BindingModels/LaborCostBindingModel.cs | 2 - .../BindingModels/OrderBindingModel.cs | 9 +- .../BindingModels/ProcedureBindingModel.cs | 6 +- .../BindingModels/ServiceBindingModel.cs | 7 +- .../SearchModels/CosmeticSearchModel.cs | 1 + .../SearchModels/OrderSearchModel.cs | 8 +- .../SearchModels/ProcedureSearchModel.cs | 1 + .../SearchModels/ServiceSearchModel.cs | 2 + .../ViewModels/CosmeticViewModel.cs | 7 +- .../ViewModels/OrderViewModel.cs | 9 +- .../ViewModels/ProcedureCount.cs | 14 -- .../ViewModels/ProcedureViewModel.cs | 7 +- .../ViewModels/ServiceViewModel.cs | 5 +- .../Enums/OrderStatus.cs | 3 +- .../Models/IOrderModel.cs | 9 +- .../Models/IProcedureModel.cs | 1 + .../Models/IServiceModel.cs | 4 +- .../BeautyStudioDatabase.cs | 1 + .../BeautyStudioDatabaseImplement.csproj | 4 + .../Implements/CosmeticStorage.cs | 37 ++- .../Implements/LaborCostStorage.cs | 43 ++-- .../Implements/OrderStorage.cs | 31 ++- .../Implements/ProcedureStorage.cs | 107 +++++---- .../Implements/StoreKeeperStorage.cs | 145 +++++++----- ...s => 20240827175011_SecondMig.Designer.cs} | 156 ++++++++++--- ...lCreate.cs => 20240827175011_SecondMig.cs} | 217 +++++++++++++----- .../BeautyStudioDatabaseModelSnapshot.cs | 152 +++++++++--- .../Models/Cosmetic.cs | 62 ++++- .../Models/LaborCost.cs | 3 +- .../Models/Order.cs | 174 ++++++++------ .../Models/OrderCosmetic.cs | 3 + .../Models/Procedure.cs | 78 ++++--- .../Models/ProcedureCosmetic.cs | 27 +++ .../Models/Service.cs | 137 ++++++----- .../Controllers/ReportController.cs | 4 - .../Controllers/CosmeticController.cs | 161 +++++++++++++ .../Controllers/LaborCostController.cs | 179 +++++++++++++++ .../Controllers/ServiceController.cs | 164 +++++++++++++ BeautyStudio/StoreKeeperWebApp/Program.cs | 63 ++++- .../Views/Cosmetic/Cosmetics.cshtml | 69 ++++++ .../Views/Cosmetic/Create.cshtml | 57 +++-- .../Views/Cosmetic/Update.cshtml | 75 +++--- .../Views/LaborCosts/Create.cshtml | 43 +++- .../Views/LaborCosts/LaborCosts.cshtml | 68 ++++++ .../Views/LaborCosts/Update.cshtml | 37 ++- .../Views/Service/Bind.cshtml | 51 ---- .../Views/Service/Create.cshtml | 52 ++++- .../Views/Service/Services.cshtml | 67 ++++++ .../Views/Service/Update.cshtml | 62 +++-- BeautyStudio/StoreKeeperWebApp/libman.json | 5 + BeautyStudio/StoreKeeperWebApp/nlog.config | 15 ++ 56 files changed, 2095 insertions(+), 743 deletions(-) delete mode 100644 BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCount.cs rename BeautyStudio/BeautyStudioDatabaseImplement/Migrations/{20240526191135_InitialCreate.Designer.cs => 20240827175011_SecondMig.Designer.cs} (81%) rename BeautyStudio/BeautyStudioDatabaseImplement/Migrations/{20240526191135_InitialCreate.cs => 20240827175011_SecondMig.cs} (81%) create mode 100644 BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs create mode 100644 BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs create mode 100644 BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs create mode 100644 BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs create mode 100644 BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml create mode 100644 BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/LaborCosts.cshtml delete mode 100644 BeautyStudio/StoreKeeperWebApp/Views/Service/Bind.cshtml create mode 100644 BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml create mode 100644 BeautyStudio/StoreKeeperWebApp/libman.json create mode 100644 BeautyStudio/StoreKeeperWebApp/nlog.config diff --git a/BeautyStudio/BeautyStudio.sln b/BeautyStudio/BeautyStudio.sln index f9d39b0..afd8a1d 100644 --- a/BeautyStudio/BeautyStudio.sln +++ b/BeautyStudio/BeautyStudio.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioView", "BeautyStudioView\BeautyStudioView.csproj", "{DCC3ADED-6BBE-4B54-AADB-59237361F601}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioDataModels", "BeautyStudioDataModels\BeautyStudioDataModels.csproj", "{7C1604C6-4223-47A7-B651-687BBF19704B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioContracts", "BeautyStudioContracts\BeautyStudioContracts.csproj", "{BD48E4B8-A4A1-4A80-97AE-8599BDD41892}" @@ -13,9 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioBusinessLogic", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioDatabaseImplement", "BeautyStudioDatabaseImplement\BeautyStudioDatabaseImplement.csproj", "{8BEBC76F-F7B5-46CB-A42B-28E133452D52}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautyStudioRestAPI", "BeautyStudioRestAPI\BeautyStudioRestAPI.csproj", "{F430F87B-4339-47E4-8C23-3FBED1F74867}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioRestAPI", "BeautyStudioRestAPI\BeautyStudioRestAPI.csproj", "{F430F87B-4339-47E4-8C23-3FBED1F74867}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StoreKeeperWebApp", "StoreKeeperWebApp\StoreKeeperWebApp.csproj", "{93AF7F9C-675F-444E-BD5D-11FA4D516561}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StoreKeeperWebApp", "StoreKeeperWebApp\StoreKeeperWebApp.csproj", "{93AF7F9C-675F-444E-BD5D-11FA4D516561}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -23,10 +21,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DCC3ADED-6BBE-4B54-AADB-59237361F601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DCC3ADED-6BBE-4B54-AADB-59237361F601}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DCC3ADED-6BBE-4B54-AADB-59237361F601}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DCC3ADED-6BBE-4B54-AADB-59237361F601}.Release|Any CPU.Build.0 = Release|Any CPU {7C1604C6-4223-47A7-B651-687BBF19704B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7C1604C6-4223-47A7-B651-687BBF19704B}.Debug|Any CPU.Build.0 = Debug|Any CPU {7C1604C6-4223-47A7-B651-687BBF19704B}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs index 8ef8cec..954af34 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs @@ -102,6 +102,15 @@ namespace BeautyStudioBusinessLogic.BusinessLogic { throw new ArgumentNullException("Не указана сложность трудозатраты", nameof(model.Difficulty)); } + var element = _laborCostsStorage.GetElement(new LaborCostSearchModel + { + TimeSpent = model.TimeSpent, + Difficulty = model.Difficulty, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такая трудозатрата уже уже есть"); + } _logger.LogInformation("LaborCost. TimeSpent: {TimeSpent}. Difficulty: {Difficulty}. Id: {Id}", model.TimeSpent, model.Difficulty, model.Id); } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs index a01f53c..487c02f 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,4 +1,5 @@ -using BeautyStudioContracts.BindingModels; +using BeautyStudioBusinessLogic.MailWorker; +using BeautyStudioContracts.BindingModels; using BeautyStudioContracts.BusinessLogicContracts; using BeautyStudioContracts.SearchModels; using BeautyStudioContracts.StoragesContracts; @@ -17,54 +18,63 @@ namespace BeautyStudioBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly AbstractMailWorker _mailWorker; + private readonly IStoreKeeperLogic _clientLogic; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IStoreKeeperLogic clientLogic) { _logger = logger; _orderStorage = orderStorage; + _mailWorker = mailWorker; + _clientLogic = clientLogic; } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("Order. OrderID:{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. DateCreate: {DateCreate}. DateComplete: {DateComplete}. Id: {Id}", - model.DateCreate, model.DateComplete, model.Id); + _logger.LogInformation("ReadElement. DateFrom:{DateFrom}. DateTo:{DateTo}. Id:{Id}", model.DateCreate, model.DateComplete, 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); + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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 bool Create(OrderBindingModel model) { CheckModel(model); + model.Status = OrderStatus.Принято; if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; } return true; + } public bool Update(OrderBindingModel model) { - CheckModel(model); + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } if (_orderStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -75,14 +85,61 @@ namespace BeautyStudioBusinessLogic.BusinessLogic public bool Delete(OrderBindingModel model) { CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); + _logger.LogInformation("Delete. Id:{Id}", model.Id); if (_orderStorage.Delete(model) == null) { - _logger.LogWarning("Delete operation failed"); + _logger.LogWarning("Delete order operation failed"); return false; } return true; } + + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + throw new InvalidOperationException(); + } + model.Status = newStatus; + if (model.Status == OrderStatus.Выполнено) + { + model.DateComplete = DateTime.Now; + } + else + { + model.DateComplete = viewModel.DateComplete; + } + CheckModel(model, false); + var result = _orderStorage.Update(model); + if (result == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + //Отсылка письма при изменении статуса + SendOrderStatusMail(result.StoreKeeperId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}"); + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public bool FinishOrder(OrderBindingModel model) + { + model.DateComplete = DateTime.Now; + return StatusUpdate(model, OrderStatus.Выполнено); + } + public bool DeliveryOrder(OrderBindingModel model) + { + + return StatusUpdate(model, OrderStatus.Выдан); + } private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -95,59 +152,29 @@ namespace BeautyStudioBusinessLogic.BusinessLogic } if (model.Sum <= 0) { - throw new ArgumentNullException("Cумма заказа должна быть больше 0", - nameof(model.Sum)); + throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}.", model.Id, model.Sum); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким номером уже есть"); } } - public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + private bool SendOrderStatusMail(int clientId, string subject, string text) { - var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); - - if (vmodel == null) + var client = _clientLogic.ReadElement(new() { Id = clientId }); + if (client == null) { - throw new ArgumentNullException(nameof(model)); - } - - if ((int)vmodel.Status + 1 != (int)newStatus) - { - throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " + - $"Текущий статус: {vmodel.Status} \n" + - $"Планируемый статус: {newStatus} \n" + - $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}"); - } - - model.Status = newStatus; - model.DateCreate = vmodel.DateCreate; - - model.ServiceId = vmodel.ServiceId; - model.Sum = vmodel.Sum; - - var result = _orderStorage.Update(model); - - if (result == null) - { - _logger.LogWarning("Update operation failed"); - return false; } + _mailWorker.MailSendAsync(new() + { + MailAddress = client.StoreKeeperEmail, + Subject = subject, + Text = text + }); return true; } - - //Перевод заказа в состояние принятого на выполнение - public bool TakeOrderInWork(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Принято); - } - - //Перевод заказа в состояние выполнения заказа - public bool FinishOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выполняется); - } - //Перевод заказа в состояние выполненности (окончательное завершение) - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выполнено); - } } } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs index dca40db..83ebe62 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs @@ -65,10 +65,10 @@ namespace BeautyStudioBusinessLogic.BusinessLogic { Id = x.Id, ServiceName = x.ServiceName, - Cosmetics = x.ServiceCosmetic, - Procedures = x.ServiceProcedure, - ServicePrice = x.ServiceProcedure.Sum(kv => kv.Value.Item1.ProcedurePrice) + - x.ServiceCosmetic.Sum(kv => kv.Value.Item1.CosmeticPrice) + Cosmetics = x.ServiceCosmetics, + Procedures = x.ServiceProcedures, + ServicePrice = x.ServiceProcedures.Sum(kv => kv.Value.Item1.ProcedureCost) + + x.ServiceCosmetics.Sum(kv => kv.Value.Item1.CosmeticPrice) }).ToList(); return r; } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs index 80e171e..cdafdfa 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs @@ -14,9 +14,7 @@ namespace BeautyStudioContracts.BindingModels public string CosmeticName { get; set; } = string.Empty; public double CosmeticPrice { get; set; } public int LaborCostId { get; set; } - - public List ServiceCosmetic { get; set; } = new(); - public List ServiceProcedure { get; set; } = new(); - public List OrderService { get; set; } = new(); + public int StoreKeeperId { get; set; } + public Dictionary CosmeticProcedure { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs index 2fefdeb..57693c1 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs @@ -10,9 +10,7 @@ namespace BeautyStudioContracts.BindingModels public class LaborCostBindingModel : ILaborCostModel { public int Id { get ; set; } - public int TimeSpent { get; set; } - public string Difficulty { get; set; } = string.Empty; public int StoreKeeperId { get; set; } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs index 71be19a..479a3b0 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs @@ -16,11 +16,10 @@ namespace BeautyStudioContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateComplete { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public int ServiceId { get; set; } - public int CosmeticId { get; set; } + public int StoreKeeperId { get; set; } - public List OrderService { get; set; } = new(); - public List OrderCosmetic { get; set; } = new(); - public List OrderProcedure { get; set; } = new(); + public Dictionary OrderServices { get; set; } = new(); + public Dictionary OrderCosmetics { get; set; } = new(); + public Dictionary OrderProcedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs index e34cdd2..04316f4 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs @@ -14,9 +14,7 @@ namespace BeautyStudioContracts.BindingModels public string ProcedureName { get; set; } = string.Empty; public double ProcedureCost { get; set; } public string ProcedureDescription { get; set; } = string.Empty; - - public List ProcedureCosmetics { get; set; } = new(); - public List ServiceProcedure { get; set; } = new(); - public List OrderProcedure { get; set; } = new(); + public int StoreKeeperId { get; set; } + public Dictionary ProcedureCosmetics { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs index 9ed2044..0ed868a 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs @@ -12,10 +12,9 @@ namespace BeautyStudioContracts.BindingModels { public int Id { get; set; } public string ServiceName { get; set; } = string.Empty; - public double ServicePrice { get; set; } + public double ServicePrice { get; set; } public int StoreKeeperId { get; set; } - public List ServiceCosmetic { get; set; } = new(); - public List ServiceProcedure { get; set; } = new(); - public List OrderService { get; set; } = new(); + public Dictionary ServiceCosmetics { get; set; } = new(); + public Dictionary ServiceProcedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs index a61ba90..f715d5f 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs @@ -11,5 +11,6 @@ namespace BeautyStudioContracts.SearchModels public int? Id { get; set; } public string? CosmeticName { get; set; } public int? LaborCostId { get; set; } + public int? StoreKeeperId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs index 5e71b64..d17fb62 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs @@ -14,8 +14,10 @@ namespace BeautyStudioContracts.SearchModels public double? Sum { get; set; } public DateTime? DateCreate { get; set; } public DateTime? DateComplete { get; set; } - public OrderStatus? Status { get; set; } - public int? ServiceId { get; set; } - public int? CosmeticId { get; set; } + public List? Statuses { get; set; } + public List? CosmeticIds { get; set; } + public List? ProcedureIds { get; set; } + public List? ServiceIds { get; set; } + public int? StoreKeeperId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs index 567e9d1..d789b1d 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs @@ -11,6 +11,7 @@ namespace BeautyStudioContracts.SearchModels public int? Id { get; set; } public string? ProcedureName { get; set; } public string? ProcedureDescription { get; set; } + public int? StoreKeeperId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs index bd70a14..f99d098 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs @@ -11,5 +11,7 @@ namespace BeautyStudioContracts.SearchModels public int? Id { get; set; } public string? ServiceName { get; set; } public int? StoreKeeperId { get; set; } + public List? CosmeticIds { get; set; } + public List? ProcedureIds { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs index 80e55b2..d081cbb 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs @@ -18,11 +18,12 @@ namespace BeautyStudioContracts.ViewModels [DisplayName("Цена косметики")] public double CosmeticPrice { get; set; } - public int StoreKeeperId { get; set; } - public int LaborCostId { get; set; } - //public List ServiceCosmetic { get; set; } = new(); + public int StoreKeeperId { get; set; } + + public string StoreKeeperName { get; set; } = string.Empty; + public Dictionary CosmeticProcedure { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs index 6039b51..3a64ea5 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs @@ -31,8 +31,11 @@ namespace BeautyStudioContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateComplete { get; set; } - public List OrderService { get; set; } = new(); - public List OrderCosmetic { get; set; } = new(); - public List OrderProcedure { get; set; } = new(); + [DisplayName("Клиент")] + public int StoreKeeperId { get; set; } + + public Dictionary OrderServices { get; set; } = new(); + public Dictionary OrderCosmetics { get; set; } = new(); + public Dictionary OrderProcedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCount.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCount.cs deleted file mode 100644 index c56e468..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCount.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class ProcedureCount - { - public ProcedureViewModel Procedure { get; set; } - public int Count { get; set; } = new(); - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs index b215f50..bdabafc 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs @@ -18,9 +18,8 @@ namespace BeautyStudioContracts.ViewModels public double ProcedureCost { get; set; } [DisplayName("Описание процедуры")] public string ProcedureDescription { get; set; } = string.Empty; - - public List CosmeticProcedures { get; set; } = new(); - public List OrderProcedures { get; set; } = new(); - public List ServiceProcedure { get; set; } = new(); + public int StoreKeeperId { get; set; } + public string StoreKeeperName { get; set; } = string.Empty; + public Dictionary ProcedureCosmetics { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs index d6fee74..ddf72ec 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs @@ -20,8 +20,7 @@ namespace BeautyStudioContracts.ViewModels [DisplayName("Сотрудник")] public int StoreKeeperId { get; set; } - public Dictionary ServiceCosmetic { get; set; } = new(); - public Dictionary ServiceProcedure { get; set; } = new(); - public List OrderService { get; set; } = new(); + public Dictionary ServiceCosmetics { get; set; } = new(); + public Dictionary ServiceProcedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioDataModels/Enums/OrderStatus.cs b/BeautyStudio/BeautyStudioDataModels/Enums/OrderStatus.cs index 1908775..9bea5de 100644 --- a/BeautyStudio/BeautyStudioDataModels/Enums/OrderStatus.cs +++ b/BeautyStudio/BeautyStudioDataModels/Enums/OrderStatus.cs @@ -11,6 +11,7 @@ namespace BeautyStudioDataModels.Enums Неизвестен = -1, Принято = 0, Выполняется = 1, - Выполнено = 2 + Выполнено = 2, + Выдан = 3 } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs index 84945ba..bb6f08d 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs @@ -13,11 +13,10 @@ namespace BeautyStudioDataModels.Models DateTime DateCreate { get; } DateTime? DateComplete { get; } OrderStatus Status { get; } - int ServiceId { get; } - int CosmeticId { get; } - Dictionary OrderCosmetic { get; } - Dictionary OrderProcedureCosmetic { get; } - Dictionary OrderService { get; } + int StoreKeeperId { get; } + Dictionary OrderCosmetics { get; } // список косметики "участвующей" в заказе + Dictionary OrderProcedures { get; } // список процедур "участвующих" в заказе + Dictionary OrderServices { get; } // список услуг "участвующих" в заказе } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs index c255acf..ec6a233 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs @@ -11,6 +11,7 @@ namespace BeautyStudioDataModels.Models string ProcedureName { get; } double ProcedureCost { get; } string ProcedureDescription { get; } + int StoreKeeperId { get; } Dictionary ProcedureCosmetics { get; } } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs index 4a5656a..208d90b 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs @@ -12,7 +12,7 @@ namespace BeautyStudioDataModels.Models string ServiceName { get; } double ServicePrice { get; } int StoreKeeperId { get; set; } - Dictionary ServiceCosmetic { get; } - Dictionary ServiceProcedure { get; } + Dictionary ServiceCosmetics { get; } + Dictionary ServiceProcedures { get; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs index b9bd6b5..5babffa 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs @@ -26,6 +26,7 @@ namespace BeautyStudioDatabaseImplement public virtual DbSet OrderServices { set; get; } public virtual DbSet OrderProcedures { set; get; } public virtual DbSet CosmeticProcedures { set; get; } + public virtual DbSet ProcedureCosmetics { set; get; } public virtual DbSet StoreKeepers { set; get; } public virtual DbSet MessageInfos { set; get; } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabaseImplement.csproj b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabaseImplement.csproj index cdbdb5e..9d64e6b 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabaseImplement.csproj +++ b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabaseImplement.csproj @@ -22,4 +22,8 @@ + + + + diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs index 855b9e2..416402d 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs @@ -16,6 +16,9 @@ namespace BeautyStudioDatabaseImplement.Implements { using var context = new BeautyStudioDatabase(); return context.Cosmetics + .Include(x => x.StoreKeeper) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) .Select(x => x.GetViewModel) .ToList(); } @@ -25,14 +28,16 @@ namespace BeautyStudioDatabaseImplement.Implements if (model.Id.HasValue) { return context.Cosmetics + .Include(x => x.StoreKeeper) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); } - if (model.LaborCostId.HasValue) + if (model.StoreKeeperId.HasValue) { return context.Cosmetics - .Where(x => x.LaborCostId == model.LaborCostId) + .Include(x => x.StoreKeeper) + .Where(x => x.StoreKeeperId == model.StoreKeeperId) .Select(x => x.GetViewModel) .ToList(); } @@ -48,19 +53,22 @@ namespace BeautyStudioDatabaseImplement.Implements } using var context = new BeautyStudioDatabase(); return context.Cosmetics - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.CosmeticName) && x.CosmeticName == model.CosmeticName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.CosmeticName) && x.CosmeticName == model.CosmeticName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public CosmeticViewModel? Insert(CosmeticBindingModel model) { - var newCosmetic = Cosmetic.Create(model); + using var context = new BeautyStudioDatabase(); + var newCosmetic = Cosmetic.Create(context, model); if (newCosmetic == null) { return null; } - using var context = new BeautyStudioDatabase(); + context.Cosmetics.Add(newCosmetic); context.SaveChanges(); return newCosmetic.GetViewModel; @@ -69,20 +77,25 @@ namespace BeautyStudioDatabaseImplement.Implements public CosmeticViewModel? Update(CosmeticBindingModel model) { using var context = new BeautyStudioDatabase(); - var сosmetic = context.Cosmetics.FirstOrDefault(x => x.Id == model.Id); - if (сosmetic == null) + var element = context.Cosmetics + .Include(x => x.LaborCost) + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (element == null) { return null; } - сosmetic.Update(model); + + element.Update(context, model); context.SaveChanges(); - return сosmetic.GetViewModel; + return element.GetViewModel; } public CosmeticViewModel? Delete(CosmeticBindingModel model) { using var context = new BeautyStudioDatabase(); - var element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Cosmetics + .Include(x => x.LaborCost) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Cosmetics.Remove(element); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs index f405b4b..66568ba 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs @@ -3,11 +3,6 @@ using BeautyStudioContracts.SearchModels; using BeautyStudioContracts.StoragesContracts; using BeautyStudioContracts.ViewModels; using BeautyStudioDatabaseImplement.Models; -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.StoragesContracts; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDatabaseImplement.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -22,12 +17,16 @@ namespace BeautyStudioDatabaseImplement.Implements public LaborCostViewModel? Delete(LaborCostBindingModel model) { using var context = new BeautyStudioDatabase(); + var element = context.LaborCost.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { + var deletedElement = context.LaborCost + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; context.LaborCost.Remove(element); context.SaveChanges(); - return element.GetViewModel; + return deletedElement; } return null; } @@ -36,12 +35,20 @@ namespace BeautyStudioDatabaseImplement.Implements { if (!model.Id.HasValue) { - return null; + using var context = new BeautyStudioDatabase(); + return context.LaborCost + .FirstOrDefault(x => x.TimeSpent == model.TimeSpent + && x.Difficulty == model.Difficulty + && x.StoreKeeperId == model.StoreKeeperId) + ?.GetViewModel; + } + else + { + using var context = new BeautyStudioDatabase(); + return context.LaborCost + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; } - using var context = new BeautyStudioDatabase(); - return context.LaborCost - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; } public List GetFilteredList(LaborCostSearchModel model) @@ -82,20 +89,24 @@ namespace BeautyStudioDatabaseImplement.Implements using var context = new BeautyStudioDatabase(); context.LaborCost.Add(newLaborCost); context.SaveChanges(); - return newLaborCost.GetViewModel; + return context.LaborCost + .FirstOrDefault(x => x.Id == newLaborCost.Id) + ?.GetViewModel; } public LaborCostViewModel? Update(LaborCostBindingModel model) { using var context = new BeautyStudioDatabase(); - var laborCost = context.LaborCost.FirstOrDefault(x => x.Id == model.Id); - if (laborCost == null) + var order = context.LaborCost.FirstOrDefault(x => x.Id == model.Id); + if (order == null) { return null; } - laborCost.Update(model); + order.Update(model); context.SaveChanges(); - return laborCost.GetViewModel; + return context.LaborCost + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs index ec84864..3dc7fe6 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -46,7 +45,7 @@ namespace BeautyStudioDatabaseImplement.Implements .ThenInclude(x => x.Procedure) .Include(x => x.Cosmetics) .ThenInclude(x => x.Cosmetic) - .FirstOrDefault(x => x.Id == model.Id) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -57,16 +56,31 @@ namespace BeautyStudioDatabaseImplement.Implements return new(); } using var context = new BeautyStudioDatabase(); - if (model.DateCreate.HasValue) + if (model.Id.HasValue) { return context.Orders .Include(x => x.Services) .ThenInclude(x => x.Service) .Include(x => x.Procedures) .ThenInclude(x => x.Procedure) - .Include(x => x.Cosmetics) + .Include(x => x.Cosmetics) .ThenInclude(x => x.Cosmetic) - .Where(x => x.DateCreate == model.DateCreate).ToList() + .Where(x => x.Id == model.Id) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.StoreKeeperId.HasValue) + { + return context.Orders + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Include(x => x.Cosmetics) + .ThenInclude(x => x.Cosmetic) + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .ToList() .Select(x => x.GetViewModel) .ToList(); } @@ -77,13 +91,12 @@ namespace BeautyStudioDatabaseImplement.Implements { using var context = new BeautyStudioDatabase(); return context.Orders - .Include(x => x.Services) + .Include(x => x.Services) .ThenInclude(x => x.Service) .Include(x => x.Procedures) .ThenInclude(x => x.Procedure) .Include(x => x.Cosmetics) .ThenInclude(x => x.Cosmetic) - .ToList() .Select(x => x.GetViewModel) .ToList(); } @@ -114,9 +127,9 @@ namespace BeautyStudioDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - order.UpdateServices(context, model); - order.UpdateProcedures(context, model); order.UpdateCosmetics(context, model); + order.UpdateProcedures(context, model); + order.UpdateServices(context, model); transaction.Commit(); return order.GetViewModel; } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs index f0e8baf..ea42875 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs @@ -14,21 +14,41 @@ namespace BeautyStudioDatabaseImplement.Implements { public class ProcedureStorage : IProcedureStorage { - public ProcedureViewModel? Delete(ProcedureBindingModel model) + public List GetFullList() { using var context = new BeautyStudioDatabase(); - var element = context.Procedures - .Include(x => x.Cosmetics) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Procedures.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.Procedures + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .ThenInclude(x => x.Cosmetic) + .Select(x => x.GetViewModel) + .ToList(); } + public List GetFilteredList(ProcedureSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (model.Id.HasValue) + { + return context.Procedures + .Include(x => x.StoreKeeper) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.StoreKeeperId.HasValue) + { + return context.Procedures + .Include(x => x.StoreKeeper) + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public ProcedureViewModel? GetElement(ProcedureSearchModel model) { if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue) @@ -44,29 +64,6 @@ namespace BeautyStudioDatabaseImplement.Implements ?.GetViewModel; } - public List GetFilteredList(ProcedureSearchModel model) - { - using var context = new BeautyStudioDatabase(); - if (model.Id.HasValue) - { - return context.Procedures - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); - } - - public List GetFullList() - { - using var context = new BeautyStudioDatabase(); - return context.Procedures - .Include(x => x.Cosmetics) - .ThenInclude(x => x.Cosmetic) - .Select(x => x.GetViewModel) - .ToList(); - } - public ProcedureViewModel? Insert(ProcedureBindingModel model) { using var context = new BeautyStudioDatabase(); @@ -75,33 +72,40 @@ namespace BeautyStudioDatabaseImplement.Implements { return null; } + context.Procedures.Add(newProcedure); context.SaveChanges(); return newProcedure.GetViewModel; } + public ProcedureViewModel? Update(ProcedureBindingModel model) { using var context = new BeautyStudioDatabase(); - using var transaction = context.Database.BeginTransaction(); - try + var element = context.Procedures + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (element == null) { - var procedure = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id); - if (procedure == null) - { - return null; - } - procedure.Update(model); + return null; + } + + element.Update(model); + context.SaveChanges(); + return element.GetViewModel; + } + + public ProcedureViewModel? Delete(ProcedureBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var element = context.Procedures + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Procedures.Remove(element); context.SaveChanges(); - procedure.UpdateCosmetics(context, model); - transaction.Commit(); - return procedure.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; + return element.GetViewModel; } + return null; } public List GetProcedureCosmetics(ProcedureSearchModel model) @@ -111,11 +115,12 @@ namespace BeautyStudioDatabaseImplement.Implements return new(); } using var context = new BeautyStudioDatabase(); - var cosmetics = context.CosmeticProcedures + var cosmetics = context.ProcedureCosmetics .Where(x => x.ProcedureId == model.Id) .Select(x => x.Cosmetic.GetViewModel) .ToList(); return cosmetics; } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs index 53f14d2..1483e77 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs @@ -1,97 +1,118 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.StoragesContracts; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Numerics; +using BeautyStudioContracts.StoragesContracts; +using BeautyStudioContracts.ViewModels; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.BindingModels; +using BeautyStudioDatabaseImplement.Models; namespace BeautyStudioDatabaseImplement.Implements { public class StoreKeeperStorage : IStoreKeeperStorage { - public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model) - { - using var context = new BeautyStudioDatabase(); - - var element = context.StoreKeepers.FirstOrDefault(rec => rec.Id == model.Id); - - if (element != null) - { - context.StoreKeepers.Remove(element); - context.SaveChanges(); - - return element.GetViewModel; - } - - return null; - } - - public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model) - { - using var context = new BeautyStudioDatabase(); - if (model.Id.HasValue) - return context.StoreKeepers - .FirstOrDefault(x => x.Id == model.Id)? - .GetViewModel; - - if (!string.IsNullOrEmpty(model.StoreKeeperPassword) && - !string.IsNullOrEmpty(model.StoreKeeperLogin)) - return context.StoreKeepers - .FirstOrDefault(x => - x.StoreKeeperPassword.Equals(model.StoreKeeperPassword) && - x.StoreKeeperLogin.Equals(model.StoreKeeperLogin))? - .GetViewModel; - - return null; - } - - public List GetFilteredList(StoreKeeperSearchModel model) - { - throw new NotImplementedException(); - } - public List GetFullList() { using var context = new BeautyStudioDatabase(); return context.StoreKeepers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(StoreKeeperSearchModel model) + { + using var context = new BeautyStudioDatabase(); + // Фильтрация по ФИО + if (!string.IsNullOrEmpty(model.StoreKeeperFIO)) + { + return context.StoreKeepers + .Where(x => x.StoreKeeperFIO.Contains(model.StoreKeeperFIO)) .Select(x => x.GetViewModel) .ToList(); - } + } + // Фильтрация по логину + if (!string.IsNullOrEmpty(model.StoreKeeperLogin)) + { + return context.StoreKeepers + .Where(x => x.StoreKeeperLogin.Contains(model.StoreKeeperLogin)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model) + { + using var context = new BeautyStudioDatabase(); + // Поиск по идентификатору + if (model.Id.HasValue) + { + return context.StoreKeepers + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + // Поиск по логину и паролю + if (!string.IsNullOrEmpty(model.StoreKeeperLogin) && !string.IsNullOrEmpty(model.StoreKeeperPassword)) + { + return context.StoreKeepers + .FirstOrDefault(x => x.StoreKeeperLogin.Equals(model.StoreKeeperLogin) && x.StoreKeeperPassword.Equals(model.StoreKeeperPassword)) + ?.GetViewModel; + } + + //// Поиск по логину + if (!string.IsNullOrEmpty(model.StoreKeeperLogin)) + { + return context.StoreKeepers + .FirstOrDefault(x => x.StoreKeeperLogin.Equals(model.StoreKeeperLogin)) + ?.GetViewModel; + } + + return null; + } public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model) { using var context = new BeautyStudioDatabase(); - - var newStoreKeepers = StoreKeeper.Create(model); - - if (newStoreKeepers == null) + var newStoreKeeper = StoreKeeper.Create(model); + if (newStoreKeeper == null) { return null; } - context.StoreKeepers.Add(newStoreKeepers); + context.StoreKeepers.Add(newStoreKeeper); context.SaveChanges(); - - return newStoreKeepers.GetViewModel; + return newStoreKeeper.GetViewModel; } - public StoreKeeperViewModel? Update(StoreKeeperBindingModel model) { using var context = new BeautyStudioDatabase(); - - var StoreKeepers = context.StoreKeepers.FirstOrDefault(x => x.Id == model.Id); - - if (StoreKeepers == null) + var storekeeper = context.StoreKeepers + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (storekeeper == null) { return null; } - StoreKeepers.Update(model); + storekeeper.Update(model); context.SaveChanges(); + return storekeeper.GetViewModel; + } + public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var storekeeper = context.StoreKeepers + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (storekeeper == null) + { + return null; + } - return StoreKeepers.GetViewModel; + context.StoreKeepers.Remove(storekeeper); + context.SaveChanges(); + return storekeeper.GetViewModel; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240526191135_InitialCreate.Designer.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240827175011_SecondMig.Designer.cs similarity index 81% rename from BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240526191135_InitialCreate.Designer.cs rename to BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240827175011_SecondMig.Designer.cs index 183adbd..2595bd7 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240526191135_InitialCreate.Designer.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240827175011_SecondMig.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BeautyStudioDatabaseImplement.Migrations { [DbContext(typeof(BeautyStudioDatabase))] - [Migration("20240526191135_InitialCreate")] - partial class InitialCreate + [Migration("20240827175011_SecondMig")] + partial class SecondMig { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -106,6 +106,36 @@ namespace BeautyStudioDatabaseImplement.Migrations b.ToTable("LaborCost"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("text"); + + b.Property("Body") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateDelivery") + .HasColumnType("timestamp with time zone"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("text"); + + b.Property("StorekeeperId") + .HasColumnType("integer"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("MessageId"); + + b.HasIndex("StorekeeperId"); + + b.ToTable("MessageInfos"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -114,23 +144,16 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("CosmeticId") - .HasColumnType("integer"); - b.Property("DateComplete") .HasColumnType("timestamp with time zone"); b.Property("DateCreate") .HasColumnType("timestamp with time zone"); - b.Property("ServiceId") - .HasColumnType("integer"); - b.Property("Status") .HasColumnType("integer"); - b.Property("StoreKeeperId") - .IsRequired() + b.Property("StoreKeeperId") .HasColumnType("integer"); b.Property("Sum") @@ -138,6 +161,8 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("StoreKeeperId"); + b.ToTable("Orders"); }); @@ -152,6 +177,9 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("CosmeticId") .HasColumnType("integer"); + b.Property("Count") + .HasColumnType("integer"); + b.Property("OrderId") .HasColumnType("integer"); @@ -235,11 +263,42 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); + b.Property("StoreKeeperId") + .HasColumnType("integer"); + b.HasKey("Id"); + b.HasIndex("StoreKeeperId"); + b.ToTable("Procedures"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetic", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CosmeticId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProcedureId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CosmeticId"); + + b.HasIndex("ProcedureId"); + + b.ToTable("ProcedureCosmetics"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { b.Property("Id") @@ -358,13 +417,15 @@ namespace BeautyStudioDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", null) - .WithMany("Cosmetics") + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") + .WithMany() .HasForeignKey("StoreKeeperId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("LaborCost"); + + b.Navigation("StoreKeeper"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticProcedure", b => @@ -397,10 +458,30 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("StoreKeeper"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "Storekeeper") + .WithMany() + .HasForeignKey("StorekeeperId"); + + b.Navigation("Storekeeper"); + }); + + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") + .WithMany() + .HasForeignKey("StoreKeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StoreKeeper"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderCosmetic", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany("Orders") + .WithMany() .HasForeignKey("CosmeticId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -425,7 +506,7 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Orders") + .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -444,7 +525,7 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany("Orders") + .WithMany() .HasForeignKey("ServiceId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -454,6 +535,36 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("Service"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") + .WithMany() + .HasForeignKey("StoreKeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StoreKeeper"); + }); + + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetic", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") + .WithMany() + .HasForeignKey("CosmeticId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") + .WithMany() + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Cosmetic"); + + b.Navigation("Procedure"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") @@ -487,7 +598,7 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Services") + .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -505,8 +616,6 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b => { - b.Navigation("Orders"); - b.Navigation("Procedures"); b.Navigation("Services"); @@ -529,25 +638,14 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => { b.Navigation("Cosmetics"); - - b.Navigation("Orders"); - - b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { b.Navigation("Cosmetics"); - b.Navigation("Orders"); - b.Navigation("Procedures"); }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b => - { - b.Navigation("Cosmetics"); - }); #pragma warning restore 612, 618 } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240526191135_InitialCreate.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240827175011_SecondMig.cs similarity index 81% rename from BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240526191135_InitialCreate.cs rename to BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240827175011_SecondMig.cs index 64aa86d..c61ba7a 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240526191135_InitialCreate.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240827175011_SecondMig.cs @@ -7,45 +7,11 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BeautyStudioDatabaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class SecondMig : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - DateCreate = table.Column(type: "timestamp with time zone", nullable: false), - DateComplete = table.Column(type: "timestamp with time zone", nullable: true), - Status = table.Column(type: "integer", nullable: false), - Sum = table.Column(type: "double precision", nullable: false), - StoreKeeperId = table.Column(type: "integer", nullable: false), - ServiceId = table.Column(type: "integer", nullable: false), - CosmeticId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Procedures", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ProcedureName = table.Column(type: "text", nullable: false), - ProcedureCost = table.Column(type: "double precision", nullable: false), - ProcedureDescription = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Procedures", x => x.Id); - }); - migrationBuilder.CreateTable( name: "StoreKeepers", columns: table => new @@ -63,33 +29,6 @@ namespace BeautyStudioDatabaseImplement.Migrations table.PrimaryKey("PK_StoreKeepers", x => x.Id); }); - migrationBuilder.CreateTable( - name: "OrderProcedures", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - OrderId = table.Column(type: "integer", nullable: false), - ProcedureId = table.Column(type: "integer", nullable: false), - OrderProcedureCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderProcedures", x => x.Id); - table.ForeignKey( - name: "FK_OrderProcedures_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrderProcedures_Procedures_ProcedureId", - column: x => x.ProcedureId, - principalTable: "Procedures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "LaborCost", columns: table => new @@ -111,6 +50,72 @@ namespace BeautyStudioDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "MessageInfos", + columns: table => new + { + MessageId = table.Column(type: "text", nullable: false), + StorekeeperId = table.Column(type: "integer", nullable: true), + SenderName = table.Column(type: "text", nullable: false), + DateDelivery = table.Column(type: "timestamp with time zone", nullable: false), + Subject = table.Column(type: "text", nullable: false), + Body = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MessageInfos", x => x.MessageId); + table.ForeignKey( + name: "FK_MessageInfos_StoreKeepers_StorekeeperId", + column: x => x.StorekeeperId, + principalTable: "StoreKeepers", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DateCreate = table.Column(type: "timestamp with time zone", nullable: false), + DateComplete = table.Column(type: "timestamp with time zone", nullable: true), + Status = table.Column(type: "integer", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + StoreKeeperId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_StoreKeepers_StoreKeeperId", + column: x => x.StoreKeeperId, + principalTable: "StoreKeepers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Procedures", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ProcedureName = table.Column(type: "text", nullable: false), + ProcedureCost = table.Column(type: "double precision", nullable: false), + ProcedureDescription = table.Column(type: "text", nullable: false), + StoreKeeperId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Procedures", x => x.Id); + table.ForeignKey( + name: "FK_Procedures_StoreKeepers_StoreKeeperId", + column: x => x.StoreKeeperId, + principalTable: "StoreKeepers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "Services", columns: table => new @@ -160,6 +165,33 @@ namespace BeautyStudioDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "OrderProcedures", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OrderId = table.Column(type: "integer", nullable: false), + ProcedureId = table.Column(type: "integer", nullable: false), + OrderProcedureCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderProcedures", x => x.Id); + table.ForeignKey( + name: "FK_OrderProcedures_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_OrderProcedures_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "OrderServices", columns: table => new @@ -248,7 +280,8 @@ namespace BeautyStudioDatabaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), OrderId = table.Column(type: "integer", nullable: false), - CosmeticId = table.Column(type: "integer", nullable: false) + CosmeticId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -267,6 +300,33 @@ namespace BeautyStudioDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ProcedureCosmetics", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CosmeticId = table.Column(type: "integer", nullable: false), + ProcedureId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProcedureCosmetics", x => x.Id); + table.ForeignKey( + name: "FK_ProcedureCosmetics_Cosmetics_CosmeticId", + column: x => x.CosmeticId, + principalTable: "Cosmetics", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ProcedureCosmetics_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "ServiceCosmetics", columns: table => new @@ -319,6 +379,11 @@ namespace BeautyStudioDatabaseImplement.Migrations table: "LaborCost", column: "StoreKeeperId"); + migrationBuilder.CreateIndex( + name: "IX_MessageInfos_StorekeeperId", + table: "MessageInfos", + column: "StorekeeperId"); + migrationBuilder.CreateIndex( name: "IX_OrderCosmetics_CosmeticId", table: "OrderCosmetics", @@ -339,6 +404,11 @@ namespace BeautyStudioDatabaseImplement.Migrations table: "OrderProcedures", column: "ProcedureId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_StoreKeeperId", + table: "Orders", + column: "StoreKeeperId"); + migrationBuilder.CreateIndex( name: "IX_OrderServices_OrderId", table: "OrderServices", @@ -349,6 +419,21 @@ namespace BeautyStudioDatabaseImplement.Migrations table: "OrderServices", column: "ServiceId"); + migrationBuilder.CreateIndex( + name: "IX_ProcedureCosmetics_CosmeticId", + table: "ProcedureCosmetics", + column: "CosmeticId"); + + migrationBuilder.CreateIndex( + name: "IX_ProcedureCosmetics_ProcedureId", + table: "ProcedureCosmetics", + column: "ProcedureId"); + + migrationBuilder.CreateIndex( + name: "IX_Procedures_StoreKeeperId", + table: "Procedures", + column: "StoreKeeperId"); + migrationBuilder.CreateIndex( name: "IX_ServiceCosmetics_CosmeticId", table: "ServiceCosmetics", @@ -381,6 +466,9 @@ namespace BeautyStudioDatabaseImplement.Migrations migrationBuilder.DropTable( name: "CosmeticProcedures"); + migrationBuilder.DropTable( + name: "MessageInfos"); + migrationBuilder.DropTable( name: "OrderCosmetics"); @@ -390,6 +478,9 @@ namespace BeautyStudioDatabaseImplement.Migrations migrationBuilder.DropTable( name: "OrderServices"); + migrationBuilder.DropTable( + name: "ProcedureCosmetics"); + migrationBuilder.DropTable( name: "ServiceCosmetics"); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs index c7b8235..d24b62c 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs @@ -103,6 +103,36 @@ namespace BeautyStudioDatabaseImplement.Migrations b.ToTable("LaborCost"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("text"); + + b.Property("Body") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateDelivery") + .HasColumnType("timestamp with time zone"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("text"); + + b.Property("StorekeeperId") + .HasColumnType("integer"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("MessageId"); + + b.HasIndex("StorekeeperId"); + + b.ToTable("MessageInfos"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -111,23 +141,16 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("CosmeticId") - .HasColumnType("integer"); - b.Property("DateComplete") .HasColumnType("timestamp with time zone"); b.Property("DateCreate") .HasColumnType("timestamp with time zone"); - b.Property("ServiceId") - .HasColumnType("integer"); - b.Property("Status") .HasColumnType("integer"); - b.Property("StoreKeeperId") - .IsRequired() + b.Property("StoreKeeperId") .HasColumnType("integer"); b.Property("Sum") @@ -135,6 +158,8 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("StoreKeeperId"); + b.ToTable("Orders"); }); @@ -149,6 +174,9 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("CosmeticId") .HasColumnType("integer"); + b.Property("Count") + .HasColumnType("integer"); + b.Property("OrderId") .HasColumnType("integer"); @@ -232,11 +260,42 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); + b.Property("StoreKeeperId") + .HasColumnType("integer"); + b.HasKey("Id"); + b.HasIndex("StoreKeeperId"); + b.ToTable("Procedures"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetic", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CosmeticId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProcedureId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CosmeticId"); + + b.HasIndex("ProcedureId"); + + b.ToTable("ProcedureCosmetics"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { b.Property("Id") @@ -355,13 +414,15 @@ namespace BeautyStudioDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", null) - .WithMany("Cosmetics") + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") + .WithMany() .HasForeignKey("StoreKeeperId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("LaborCost"); + + b.Navigation("StoreKeeper"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticProcedure", b => @@ -394,10 +455,30 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("StoreKeeper"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "Storekeeper") + .WithMany() + .HasForeignKey("StorekeeperId"); + + b.Navigation("Storekeeper"); + }); + + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") + .WithMany() + .HasForeignKey("StoreKeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StoreKeeper"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderCosmetic", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany("Orders") + .WithMany() .HasForeignKey("CosmeticId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -422,7 +503,7 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Orders") + .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -441,7 +522,7 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany("Orders") + .WithMany() .HasForeignKey("ServiceId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -451,6 +532,36 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("Service"); }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") + .WithMany() + .HasForeignKey("StoreKeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StoreKeeper"); + }); + + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetic", b => + { + b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") + .WithMany() + .HasForeignKey("CosmeticId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") + .WithMany() + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Cosmetic"); + + b.Navigation("Procedure"); + }); + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") @@ -484,7 +595,7 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Services") + .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -502,8 +613,6 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b => { - b.Navigation("Orders"); - b.Navigation("Procedures"); b.Navigation("Services"); @@ -526,25 +635,14 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => { b.Navigation("Cosmetics"); - - b.Navigation("Orders"); - - b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { b.Navigation("Cosmetics"); - b.Navigation("Orders"); - b.Navigation("Procedures"); }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b => - { - b.Navigation("Cosmetics"); - }); #pragma warning restore 612, 618 } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs index 23e5dd0..19e6d1c 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs @@ -23,7 +23,7 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int StoreKeeperId { get; set; } - + public virtual StoreKeeper StoreKeeper { get; set; } [Required] public int LaborCostId { get; set; } public virtual LaborCost LaborCost { get; set; } = new(); @@ -34,44 +34,86 @@ namespace BeautyStudioDatabaseImplement.Models // связь многие-ко-многим косметики с процедурами [ForeignKey("CosmeticId")] + private Dictionary? _cosmeticProcedures = null; + + [NotMapped] + public Dictionary CosmeticProcedure + { + get + { + if (_cosmeticProcedures == null) + { + _cosmeticProcedures = Procedures.ToDictionary(recPC => recPC.ProcedureId, recPC => (recPC.Procedure as IProcedureModel)); + } + return _cosmeticProcedures; + } + } + // список косметики в закаче public virtual List Procedures { get; set; } = new(); // связь многие-ко-многим косметики с процедурами [ForeignKey("CosmeticId")] public virtual List Services { get; set; } = new(); - public static Cosmetic Create(CosmeticBindingModel model) + public static Cosmetic Create(BeautyStudioDatabase context, CosmeticBindingModel model) { if (model == null) { return null; } - return new Cosmetic() + var cosmetic = new Cosmetic() { Id = model.Id, CosmeticName = model.CosmeticName, CosmeticPrice = model.CosmeticPrice, - LaborCostId = model.LaborCostId + LaborCostId = model.LaborCostId, + StoreKeeperId = model.StoreKeeperId }; + return cosmetic; } - public void Update(CosmeticBindingModel model) + public void Update(BeautyStudioDatabase context, CosmeticBindingModel model) { - if (model == null) - { - return; - } CosmeticName = model.CosmeticName; CosmeticPrice = model.CosmeticPrice; LaborCostId = model.LaborCostId; } + public void UpdateProcedures(BeautyStudioDatabase context, CosmeticBindingModel model) + { + var cosmeticProcedures = context.CosmeticProcedures.Where(rec => rec.CosmeticId == model.Id).ToList(); + if (cosmeticProcedures != null && cosmeticProcedures.Count > 0) + { + context.CosmeticProcedures.RemoveRange(cosmeticProcedures.Where(rec => !model.CosmeticProcedure.ContainsKey(rec.ProcedureId))); + context.SaveChanges(); + + foreach (var updateProcedure in cosmeticProcedures) + { + model.CosmeticProcedure.Remove(updateProcedure.CosmeticId); + } + context.SaveChanges(); + } + var cosmetic = context.Cosmetics.First(x => x.Id == Id); + foreach (var rp in model.CosmeticProcedure) + { + context.CosmeticProcedures.Add(new CosmeticProcedure + { + Cosmetic = cosmetic, + Procedure = context.Procedures.First(x => x.Id == rp.Key), + }); + context.SaveChanges(); + } + _cosmeticProcedures = null; + } + public CosmeticViewModel GetViewModel => new() { Id = Id, CosmeticName = CosmeticName, CosmeticPrice = CosmeticPrice, - LaborCostId = LaborCostId + LaborCostId = LaborCostId, + CosmeticProcedure = CosmeticProcedure, + StoreKeeperId = StoreKeeperId }; } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs index 11623e3..052a0a3 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs @@ -35,7 +35,8 @@ namespace BeautyStudioDatabaseImplement.Models { Id = model.Id, StoreKeeperId = model.StoreKeeperId, - TimeSpent = model.TimeSpent + TimeSpent = model.TimeSpent, + Difficulty = model.Difficulty }; } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs index f6fb269..a1e8aff 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs @@ -28,91 +28,98 @@ namespace BeautyStudioDatabaseImplement.Models public double Sum { get; set; } [Required] - public int? StoreKeeperId { get; set; } - [Required] - public int ServiceId { get; set; } - [Required] - public int CosmeticId { get; set; } - - private List? _orderServices = null; - - private List? _orderCosmetics = null; - - private List? _orderProcedures = null; + public int StoreKeeperId { get; set; } + public virtual StoreKeeper? StoreKeeper { get; set; } + private Dictionary? _orderCosmetics = null; // поле для [NotMapped] - public List OrderServices + public Dictionary? OrderCosmetics { get { - _orderServices ??= Services - .Select(pc => new OrderServiceViewModel(pc.Service.GetViewModel, pc.OrderServiceCount)) - .ToList(); - return _orderServices; + if (_orderCosmetics == null) + { + _orderCosmetics = Cosmetics.ToDictionary(recPC => recPC.CosmeticId, recPC => (recPC.Cosmetic as ICosmeticModel, recPC.Count)); + } + return _orderCosmetics; } } + [ForeignKey("OrderId")] + public virtual List Cosmetics { get; set; } = new(); // список косметических товаров для данного заказа. + + private Dictionary? _orderProcedures = null; // поле для хранения словаря OrderCosmetics. + [NotMapped] - public List OrderProcedures + public Dictionary OrderProcedures // список косметики используемых в заказе. { get { - _orderProcedures ??= Procedures - .Select(pc => new OrderProcedureViewModel(pc.Procedure.GetViewModel, pc.OrderProcedureCount)) - .ToList(); + if (_orderProcedures == null) + { + _orderProcedures = Procedures + .ToDictionary(recPC => recPC.ProcedureId, recPC => + (recPC.Procedure as IProcedureModel, recPC.OrderProcedureCount)); + } return _orderProcedures; } } + [ForeignKey("OrderId")] + public virtual List Procedures { get; set; } = new(); // представляет список процедур для данного заказа. + + private Dictionary? _orderServices = null; // поле для хранения словаря OrderServices. [NotMapped] - public List OrderCosmetics + public Dictionary OrderServices { get { - _orderCosmetics ??= Cosmetics - .Select(pc => new OrderCosmeticViewModel(pc.Cosmetic.GetViewModel)) - .ToList(); - return _orderCosmetics; + if (_orderServices == null) + { + _orderServices = Services.ToDictionary(recPC => recPC.ServiceId, recPC => (recPC.Service as IServiceModel, recPC.OrderServiceCount)); + } + return _orderServices; } } + // связь услуги и заказов многие - ко - многим [ForeignKey("OrderId")] public virtual List Services { get; set; } = new(); - - [ForeignKey("OrderId")] - public virtual List Cosmetics { get; set; } = new(); - - [ForeignKey("OrderId")] - public virtual List Procedures { get; set; } = new(); - public static Order Create(BeautyStudioDatabase context, OrderBindingModel model) { - return new Order() + if (model == null) + { + return null; + } + var order = new Order() { Id = model.Id, - DateCreate = model.DateCreate, Sum = model.Sum, - Services = model.OrderService.Select(x => new OrderService() + DateCreate = model.DateCreate, + DateComplete = model.DateComplete, + Status = model.Status, + StoreKeeperId = model.StoreKeeperId, + Cosmetics = model.OrderCosmetics.Select(x => new OrderCosmetic { - Service = context.Services.First(y => y.Id == x.Service.Id), - OrderServiceCount = x.Count + Cosmetic = context.Cosmetics.First(y => y.Id == x.Key) }).ToList(), - Procedures = model.OrderProcedure.Select(x => new OrderProcedure() + Procedures = model.OrderProcedures.Select(x => new OrderProcedure { - Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id), - OrderProcedureCount = x.Count + Procedure = context.Procedures.First(y => y.Id == x.Key) }).ToList(), - Cosmetics = model.OrderCosmetic.Select(x => new OrderCosmetic() + Services = model.OrderServices.Select(x => new OrderService { - Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), + Service = context.Services.First(y => y.Id == x.Key) }).ToList() }; + + return order; } public void Update(OrderBindingModel model) { + Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateComplete = model.DateComplete; } @@ -122,71 +129,88 @@ namespace BeautyStudioDatabaseImplement.Models DateCreate = DateCreate, DateComplete = DateComplete, Sum = Sum, - OrderService = OrderServices, - OrderProcedure = OrderProcedures, - OrderCosmetic = OrderCosmetics + Status = Status }; - public void UpdateServices(BeautyStudioDatabase context, OrderBindingModel model) + public void UpdateCosmetics(BeautyStudioDatabase context, OrderBindingModel model) { - var orderServices = context.OrderServices - .Where(x => x.OrderId == model.Id) - .ToList(); - context.OrderServices - .RemoveRange(orderServices); + var orderCosmetics = context.OrderCosmetics.Where(rec => rec.OrderId == model.Id).ToList(); + if (orderCosmetics != null && orderCosmetics.Count > 0) + { // удалили те, которых нет в модели + context.OrderCosmetics.RemoveRange(orderCosmetics.Where(rec => !model.OrderCosmetics.ContainsKey(rec.CosmeticId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateCosmetic in orderCosmetics) + { + model.OrderCosmetics.Remove(updateCosmetic.CosmeticId); + } + context.SaveChanges(); + } var order = context.Orders.First(x => x.Id == Id); - foreach (var record in model.OrderService) + foreach (var rp in model.OrderCosmetics) { - context.OrderServices.Add(new OrderService + context.OrderCosmetics.Add(new OrderCosmetic { Order = order, - Service = context.Services.First(x => x.Id == record.Service.Id), - OrderServiceCount = record.Count + Cosmetic = context.Cosmetics.First(x => x.Id == rp.Key), }); context.SaveChanges(); } - _orderServices = null; + _orderCosmetics = null; } public void UpdateProcedures(BeautyStudioDatabase context, OrderBindingModel model) { - var orderProcedures = context.OrderProcedures - .Where(x => x.OrderId == model.Id) - .ToList(); - context.OrderProcedures - .RemoveRange(orderProcedures); + var orderProcedures = context.OrderProcedures.Where(rec => rec.OrderId == model.Id).ToList(); + if (orderProcedures != null && orderProcedures.Count > 0) + { // удалили те, которых нет в модели + context.OrderProcedures.RemoveRange(orderProcedures.Where(rec => !model.OrderProcedures.ContainsKey(rec.ProcedureId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateProcedure in orderProcedures) + { + model.OrderProcedures.Remove(updateProcedure.ProcedureId); + } + context.SaveChanges(); + } var order = context.Orders.First(x => x.Id == Id); - foreach (var record in model.OrderProcedure) + foreach (var rp in model.OrderProcedures) { context.OrderProcedures.Add(new OrderProcedure { Order = order, - Procedure = context.Procedures.First(x => x.Id == record.Procedure.Id), - OrderProcedureCount = record.Count + Procedure = context.Procedures.First(x => x.Id == rp.Key), }); context.SaveChanges(); } _orderProcedures = null; } - public void UpdateCosmetics(BeautyStudioDatabase context, OrderBindingModel model) + public void UpdateServices(BeautyStudioDatabase context, OrderBindingModel model) { - var orderCosmetic = context.OrderCosmetics - .Where(x => x.OrderId == model.Id) - .ToList(); - context.OrderCosmetics - .RemoveRange(orderCosmetic); + var orderServices = context.OrderServices.Where(rec => rec.OrderId == model.Id).ToList(); + if (orderServices != null && orderServices.Count > 0) + { // удалили те, которых нет в модели + context.OrderServices.RemoveRange(orderServices.Where(rec => !model.OrderServices.ContainsKey(rec.ServiceId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateService in orderServices) + { + model.OrderServices.Remove(updateService.ServiceId); + } + context.SaveChanges(); + } var order = context.Orders.First(x => x.Id == Id); - foreach (var record in model.OrderCosmetic) + foreach (var rp in model.OrderServices) { - context.OrderCosmetics.Add(new OrderCosmetic + context.OrderServices.Add(new OrderService { Order = order, - Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id), + Service = context.Services.First(x => x.Id == rp.Key), }); context.SaveChanges(); } - _orderCosmetics = null; + _orderServices = null; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs index 9e38d9b..acac6c6 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs @@ -17,6 +17,9 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int CosmeticId { get; set; } + [Required] + public int Count { get; set; } + public virtual Order Order { get; set; } = new(); public virtual Cosmetic Cosmetic { get; set; } = new(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs index bed96b7..8959807 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs @@ -24,48 +24,50 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public string ProcedureDescription { get; set; } = string.Empty; - // связь процедур и косметики многие - ко - многим - [ForeignKey("ProcedureId")] - public virtual List Cosmetics { get; set; } = new(); - - private List? _cosmeticProcedures = null; + [Required] + public int StoreKeeperId { get; set; } + public virtual StoreKeeper StoreKeeper { get; set; } + private Dictionary? _procedureCosmetics = null;//Это поле для хранения словаря OrderCosmetics. + [NotMapped] - public List CosmeticProcedures + public Dictionary ProcedureCosmetics //представляет список косметики, участвующей в заказе. Не присутствует в базе данных. { get { - _cosmeticProcedures ??= Cosmetics - .Select(pc => new CosmeticProcedureViewModel(pc.Cosmetic.GetViewModel, pc.Procedure.GetViewModel, pc.ProcedureCosmeticCount)) - .ToList(); - return _cosmeticProcedures; + if (_procedureCosmetics == null) + { + _procedureCosmetics = Cosmetics + .ToDictionary(recPC => recPC.CosmeticId, recPC => (recPC.Cosmetic as ICosmeticModel, recPC.ProcedureCosmeticCount)); + } + return _procedureCosmetics; } } - // связь процедур и услуг многие - ко - многим - [ForeignKey("ProcedureId")] - public virtual List Services { get; set; } = new(); - - // связь процедур и заказов многие - ко - многим - [ForeignKey("ProcedureId")] - public virtual List Orders { get; set; } = new(); + public virtual List Cosmetics { get; set; } = new();//представляет список косметических товаров для данного заказа. public static Procedure Create(BeautyStudioDatabase context, ProcedureBindingModel model) { - return new Procedure() + if (model == null) + { + return null; + } + var procedure = new Procedure() { Id = model.Id, ProcedureName = model.ProcedureName, ProcedureCost = model.ProcedureCost, ProcedureDescription = model.ProcedureDescription, - Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure() + StoreKeeperId = model.StoreKeeperId, + Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure { - Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), - ProcedureCosmeticCount = x.Count - }).ToList() - }; - } + Cosmetic = context.Cosmetics.First(y => y.Id == x.Key) + }).ToList(), + }; + + return procedure; + } public void Update(ProcedureBindingModel model) { ProcedureName = model.ProcedureName; @@ -79,28 +81,36 @@ namespace BeautyStudioDatabaseImplement.Models ProcedureName = ProcedureName, ProcedureCost = ProcedureCost, ProcedureDescription = ProcedureDescription, - CosmeticProcedures = CosmeticProcedures + ProcedureCosmetics = ProcedureCosmetics, + StoreKeeperId = StoreKeeperId, + StoreKeeperName = StoreKeeper.StoreKeeperFIO, }; public void UpdateCosmetics(BeautyStudioDatabase context, ProcedureBindingModel model) { - var procedureCosmetics = context.CosmeticProcedures - .Where(x => x.ProcedureId == model.Id) - .ToList(); - context.CosmeticProcedures - .RemoveRange(procedureCosmetics); + var procedureCosmetics = context.CosmeticProcedures.Where(rec => rec.ProcedureId == model.Id).ToList(); + if (procedureCosmetics != null && procedureCosmetics.Count > 0) + { // удалили те, которых нет в модели + context.CosmeticProcedures.RemoveRange(procedureCosmetics.Where(rec => !model.ProcedureCosmetics.ContainsKey(rec.CosmeticId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateCosmetic in procedureCosmetics) + { + model.ProcedureCosmetics.Remove(updateCosmetic.ProcedureId); + } + context.SaveChanges(); + } var procedure = context.Procedures.First(x => x.Id == Id); - foreach (var record in model.ProcedureCosmetics) + foreach (var rp in model.ProcedureCosmetics) { context.CosmeticProcedures.Add(new CosmeticProcedure { Procedure = procedure, - Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id), - ProcedureCosmeticCount = record.Count + Cosmetic = context.Cosmetics.First(x => x.Id == rp.Key), }); context.SaveChanges(); } - _cosmeticProcedures = null; + _procedureCosmetics = null; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs new file mode 100644 index 0000000..b045a49 --- /dev/null +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautyStudioDatabaseImplement.Models +{ + public class ProcedureCosmetic + { + public int Id { get; set; } + + [Required] + public int CosmeticId { get; set; } + + [Required] + public int ProcedureId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Procedure Procedure { get; set; } = new(); + public virtual Cosmetic Cosmetic { get; set; } = new(); + + } +} diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs index 5d930d6..404d16d 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs @@ -27,66 +27,70 @@ namespace BeautyStudioDatabaseImplement.Models public int StoreKeeperId { get; set; } public virtual StoreKeeper StoreKeeper { get; set; } - // связь услуги и заказов многие - ко - многим - [ForeignKey("ServiceId")] - public virtual List Orders { get; set; } = new(); - - // связь услуги и косметки многие - ко - многим - [ForeignKey("ServiceId")] - public virtual List Cosmetics { get; set; } = new(); - - // связь услуги и косметки многие - ко - многим - [ForeignKey("ServiceId")] - public virtual List Procedures { get; set; } = new(); - - private List? _serviceProcedures = null; - + private Dictionary? _serviceCosmetics = null;//Это поле для хранения словаря OrderCosmetics. [NotMapped] - public List ServiceProcedures + public Dictionary ServiceCosmetics //представляет список косметики, участвующей в заказе. Не присутствует в базе данных. { get { - _serviceProcedures ??= Procedures - .Select(pc => new ServiceProcedureViewModel(pc.Procedure.GetViewModel, pc.ServiceProcedureCount)) - .ToList(); - return _serviceProcedures; - } - } - - private List? _serviceCosmetics = null; - [NotMapped] - public List ServiceCosmetics - { - get - { - _serviceCosmetics ??= Cosmetics - .Select(pc => new ServiceCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.Service.GetViewModel, pc.ServiceCosmeticCount)) - .ToList(); + if (_serviceCosmetics == null) + { + _serviceCosmetics = Cosmetics + .ToDictionary(recPC => recPC.CosmeticId, recPC => + (recPC.Cosmetic as ICosmeticModel, recPC.ServiceCosmeticCount)); + } return _serviceCosmetics; } } + [ForeignKey("ServiceId")] + public virtual List Cosmetics { get; set; } = new();//представляет список косметических товаров для данного заказа. + + + + private Dictionary? _serviceProcedures = null;//Это поле для хранения словаря OrderCosmetics. + [NotMapped] + public Dictionary ServiceProcedures//представляет список косметики, участвующей в заказе. Не присутствует в базе данных. + { + get + { + if (_serviceProcedures == null) + { + _serviceProcedures = Procedures + .ToDictionary(recPC => recPC.ProcedureId, recPC => + (recPC.Procedure as IProcedureModel, recPC.ServiceProcedureCount)); + } + return _serviceProcedures; + } + } + [ForeignKey("ServiceId")] + public virtual List Procedures { get; set; } = new();//представляет список косметических товаров для данного заказа. public static Service Create(BeautyStudioDatabase context, ServiceBindingModel model) { - return new Service() + if (model == null) + { + return null; + } + var service = new Service() { Id = model.Id, ServiceName = model.ServiceName, ServicePrice = model.ServicePrice, - Cosmetics = model.ServiceCosmetic.Select(x => new ServiceCosmetic() + StoreKeeperId = model.StoreKeeperId, + Cosmetics = model.ServiceCosmetics.Select(x => new ServiceCosmetic { - Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), - ServiceCosmeticCount = x.Count + Cosmetic = context.Cosmetics.First(y => y.Id == x.Key) }).ToList(), - Procedures = model.ServiceProcedure.Select(x => new ServiceProcedure() + Procedures = model.ServiceProcedures.Select(x => new ServiceProcedure { - Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id), - ServiceProcedureCount = x.Count - }).ToList(), - StoreKeeperId = model.StoreKeeperId + Procedure = context.Procedures.First(y => y.Id == x.Key) + }).ToList() }; + + return service; } + public void Update(ServiceBindingModel model) { ServiceName = model.ServiceName; @@ -99,47 +103,62 @@ namespace BeautyStudioDatabaseImplement.Models Id = Id, ServiceName = ServiceName, ServicePrice = ServicePrice, - ServiceCosmetic = ServiceCosmetics, - ServiceProcedure = ServiceProcedures, - StoreKeeperId = StoreKeeperId + ServiceCosmetics = ServiceCosmetics, + ServiceProcedures = ServiceProcedures, + StoreKeeperId = StoreKeeperId, }; + + public void UpdateCosmetics(BeautyStudioDatabase context, ServiceBindingModel model) { - var serviceCosmetics = context.ServiceCosmetics - .Where(x => x.ServiceId == model.Id) - .ToList(); - context.ServiceCosmetics - .RemoveRange(serviceCosmetics); + var serviceCosmetics = context.ServiceCosmetics.Where(rec => rec.ServiceId == model.Id).ToList(); + if (serviceCosmetics != null && serviceCosmetics.Count > 0) + { // удалили те, которых нет в модели + context.ServiceCosmetics.RemoveRange(serviceCosmetics.Where(rec => !model.ServiceCosmetics.ContainsKey(rec.CosmeticId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateCosmetic in serviceCosmetics) + { + model.ServiceCosmetics.Remove(updateCosmetic.CosmeticId); + } + context.SaveChanges(); + } var service = context.Services.First(x => x.Id == Id); - foreach (var record in model.ServiceCosmetic) + foreach (var rp in model.ServiceCosmetics) { context.ServiceCosmetics.Add(new ServiceCosmetic { Service = service, - Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id), - ServiceCosmeticCount = record.Count + Cosmetic = context.Cosmetics.First(x => x.Id == rp.Key), }); context.SaveChanges(); } _serviceCosmetics = null; } + public void UpdateProcedures(BeautyStudioDatabase context, ServiceBindingModel model) { - var serviceProcedures = context.ServiceProcedures - .Where(x => x.ServiceId == model.Id) - .ToList(); - context.ServiceProcedures - .RemoveRange(serviceProcedures); + var serviceProcedures = context.ServiceProcedures.Where(rec => rec.ServiceId == model.Id).ToList(); + if (serviceProcedures != null && serviceProcedures.Count > 0) + { // удалили те, которых нет в модели + context.ServiceProcedures.RemoveRange(serviceProcedures.Where(rec => !model.ServiceProcedures.ContainsKey(rec.ProcedureId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateCosmetic in serviceProcedures) + { + model.ServiceProcedures.Remove(updateCosmetic.ProcedureId); + } + context.SaveChanges(); + } var service = context.Services.First(x => x.Id == Id); - foreach (var record in model.ServiceProcedure) + foreach (var rp in model.ServiceProcedures) { context.ServiceProcedures.Add(new ServiceProcedure { Service = service, - Procedure = context.Procedures.First(x => x.Id == record.Procedure.Id), - ServiceProcedureCount = record.Count + Procedure = context.Procedures.First(x => x.Id == rp.Key), }); context.SaveChanges(); } diff --git a/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs b/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs index b7857e4..22df385 100644 --- a/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs +++ b/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs @@ -26,8 +26,6 @@ namespace BeautyStudioRestAPI.Controllers { _reportLogic.SaveServicesToPdfFile(new ReportServiceBindingModel { - DateFrom = report.DateFrom, - DateTo = report.DateTo, FileName = "C:\\reports\\pdfservicesreport.pdf", }); } @@ -70,8 +68,6 @@ namespace BeautyStudioRestAPI.Controllers { _reportLogic.SaveServicesToPdfFile(new ReportServiceBindingModel { - DateFrom = report.DateFrom, - DateTo = report.DateTo, FileName = report.FileName, StorekeeperId = report.StorekeeperId, Email = report.Email, diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs new file mode 100644 index 0000000..f7d5a56 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs @@ -0,0 +1,161 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.BusinessLogicContracts; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.ViewModels; +using BeautyStudioDatabaseImplement.Models; +using BeautyStudioDataModels.Models; +using DocumentFormat.OpenXml.Spreadsheet; +using Microsoft.AspNetCore.Mvc; +using StoreKeeperWebApp; + +namespace StoreKeeperWebApp.Controllers +{ + public class CosmeticController : Controller + { + private readonly ILogger logger; + + private readonly ICosmeticLogic cosmetic; + private readonly ILaborCostLogic laborCost; + private readonly IProcedureLogic procedure; + + public CosmeticController(ILogger logger, ICosmeticLogic cosmetic, IProcedureLogic procedure, ILaborCostLogic laborCost) + { + this.logger = logger; + this.cosmetic = cosmetic; + this.procedure = procedure; + this.laborCost = laborCost; + } + + [HttpGet] + public CosmeticViewModel? GetCosmetic(int id) + { + try + { + return cosmetic.ReadElement(new CosmeticSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка получения косметики"); + throw; + } + } + + [HttpGet] + public IActionResult Cosmetics() + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + return View(cosmetic.ReadList(null)); + } + + [HttpGet] + public IActionResult CreateCosmetics() + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.LaborCost = laborCost.ReadList(new LaborCostSearchModel + { + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + }); + + return View(); + } + + [HttpPost] + public void CreateCosmetics(string name, string brand, double price, int laborCost) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(brand) || price <= 0 || laborCost <= 0) + { + throw new Exception("Введены не все данные!"); + } + + cosmetic.Create(new CosmeticBindingModel + { + CosmeticName = name, + CosmeticPrice = price, + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + LaborCostId = laborCost + }); + + Response.Redirect("/Cosmetic/Cosmetics"); + } + + + [HttpGet] + public IActionResult UpdateCosmetics(int id) + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.LaborCost = laborCost.ReadList(new LaborCostSearchModel + { + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + }); + + return View(cosmetic.ReadElement(new CosmeticSearchModel + { + Id = id + })); + } + + [HttpPost] + public void UpdateCosmetics(int id, string name, string brand, double price, int laborCost) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || laborCost <= 0) + { + throw new Exception("Введены не все данные!"); + } + + cosmetic.Update(new CosmeticBindingModel + { + Id = id, + CosmeticName = name, + CosmeticPrice = price, + LaborCostId = laborCost + }); + + Response.Redirect("/Cosmetic/Cosmetics"); + } + + /// + /// Удалить косметику + /// + /// + [HttpPost] + public void DeleteCosmetics(int id) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + cosmetic.Delete(new CosmeticBindingModel + { + Id = id + }); + + Response.Redirect("/Cosmetic/Cosmetics"); + } + } +} diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs new file mode 100644 index 0000000..32526d7 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs @@ -0,0 +1,179 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.BusinessLogicContracts; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.ViewModels; +using BeautyStudioDatabaseImplement.Models; +using BeautyStudioDataModels.Models; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; +using Microsoft.AspNetCore.Mvc; +using StoreKeeperWebApp; + +namespace StoreKeeperWebApp.Controllers +{ + public class LaborCostController : Controller + { + private readonly ILogger logger; + + private readonly ILaborCostLogic laborCost; + private readonly ICosmeticLogic cosmetic; + + public LaborCostController(ILogger logger, ILaborCostLogic laborCost, ICosmeticLogic cosmetic) + { + this.logger = logger; + this.laborCost = laborCost; + this.cosmetic = cosmetic; + } + + [HttpGet] + public LaborCostViewModel? GetLaborCost(int id) + { + try + { + return laborCost.ReadElement(new LaborCostSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка получения трудозатраты"); + throw; + } + } + + [HttpGet] + public IActionResult LaborCost() + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + return View(laborCost.ReadList(null)); + } + + [HttpGet] + public IActionResult CreateLaborCost() + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel + { + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + }); + + return View(); + } + + [HttpPost] + public void CreateLaborCost(int hours, string difficulty, int cosmeticId) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (hours <= 0 || string.IsNullOrEmpty(difficulty) || cosmeticId <= 0) + { + throw new Exception("Введены не все данные!"); + } + + laborCost.Create(new LaborCostBindingModel + { + TimeSpent = hours, + Difficulty = difficulty, + StoreKeeperId = APIStoreKeeper.Storekeeper.Id + }); + + var labor = laborCost.ReadElement(new LaborCostSearchModel { + TimeSpent = hours, + Difficulty = difficulty, + StoreKeeperId = APIStoreKeeper.Storekeeper.Id + }); + + var cosm = cosmetic.ReadElement(new CosmeticSearchModel{ Id = cosmeticId }); + if (cosm != null && labor != null) + { + cosm.LaborCostId = labor.Id; // Присваиваем айди трудозатраты к объекту косметики + cosmetic.Update(new CosmeticBindingModel + { + Id = cosm.Id, + CosmeticName = cosm.CosmeticName, + CosmeticPrice = cosm.CosmeticPrice, + LaborCostId = cosm.LaborCostId + }); + } + + Response.Redirect("/LaborCost/LaborCost"); + } + + + [HttpGet] + public IActionResult UpdateLaborCost(int id) + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel + { + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + }); + + return View(laborCost.ReadElement(new LaborCostSearchModel + { + Id = id + })); + } + + [HttpPost] + public void UpdateLaborCost(int hours, string difficulty) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(difficulty) || hours <= 0) + { + throw new Exception("Введены не все данные!"); + } + + laborCost.Update(new LaborCostBindingModel + { + TimeSpent = hours, + Difficulty = difficulty, + StoreKeeperId = APIStoreKeeper.Storekeeper.Id + }); + + Response.Redirect("/LaborCost/LaborCost"); + } + + /// + /// Удалить косметику + /// + /// + [HttpPost] + public void DeleteLaborCost(int id) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + laborCost.Delete(new LaborCostBindingModel + { + Id = id + }); + + Response.Redirect("/LaborCost/LaborCost"); + } + } +} diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs new file mode 100644 index 0000000..58430d8 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs @@ -0,0 +1,164 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.BusinessLogicContracts; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.ViewModels; +using BeautyStudioDataModels.Models; +using Microsoft.AspNetCore.Mvc; +using System.Numerics; + +namespace StoreKeeperWebApp.Controllers +{ + /// + /// Контроллер для сущности "Рецепт" + /// + public class ServiceController : Controller + { + private readonly ILogger _logger; + private readonly IServiceLogic _serviceLogic; + private readonly ICosmeticLogic _cosmeticLogic; + private readonly IProcedureLogic _procedureLogic; + + public ServiceController(ILogger logger, IServiceLogic serviceLogic, ICosmeticLogic cosmeticLogic, IProcedureLogic procedurecLogic) + { + _logger = logger; + _serviceLogic = serviceLogic; + _cosmeticLogic = cosmeticLogic; + _procedureLogic = procedurecLogic; + } + + [HttpGet] + public IActionResult Services() + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_serviceLogic.ReadList(new ServiceSearchModel + { + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + })); + } + + [HttpGet] + public IActionResult CreateServices() + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cosmetics = _cosmeticLogic.ReadList(null); + ViewBag.Procedures = _procedureLogic.ReadList(null); + return View(); + } + + [HttpPost] + public void CreateServices(string name, double price, int count, List cosmetics, List procedures) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || price <= 0 || cosmetics == null || procedures == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary serviceCosmetics = new Dictionary(); + foreach (var cosmeticId in cosmetics) + { + serviceCosmetics.Add(cosmeticId, (_cosmeticLogic.ReadElement(new CosmeticSearchModel { Id = cosmeticId })!, count)); + } + + Dictionary serviceProcedures = new Dictionary(); + foreach (var procedureId in cosmetics) + { + serviceProcedures.Add(procedureId, (_procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId })!, count)); + } + + _serviceLogic.Create(new ServiceBindingModel + { + ServiceName = name, + ServicePrice = price, + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + ServiceCosmetics = serviceCosmetics, + ServiceProcedures = serviceProcedures + }); + + Response.Redirect("/Service/Services"); + } + + [HttpGet] + public IActionResult UpdateServices(int id) + { + if (APIStoreKeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cosmetics = _cosmeticLogic.ReadList(null); + ViewBag.Procedures = _procedureLogic.ReadList(null); + + return View(_serviceLogic.ReadElement(new ServiceSearchModel + { + Id = id + })); + } + + [HttpPost] + public void UpdateServices(int id, string name, double price, List cosmetics, List procedures) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || price <= 0 || cosmetics == null || procedures == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary serviceCosmetics = new Dictionary(); + foreach (var cosmeticId in cosmetics) + { + serviceCosmetics.Add(cosmeticId, (_cosmeticLogic.ReadElement(new CosmeticSearchModel { Id = cosmeticId })!, 1)); + } + + Dictionary serviceProcedures = new Dictionary(); + foreach (var procedureId in cosmetics) + { + serviceProcedures.Add(procedureId, (_procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId })!, 1)); + } + + _serviceLogic.Update(new ServiceBindingModel + { + Id = id, + ServiceName = name, + ServicePrice = price, + StoreKeeperId = APIStoreKeeper.Storekeeper.Id, + ServiceCosmetics = serviceCosmetics, + ServiceProcedures = serviceProcedures + }); + + Response.Redirect("/Service/Services"); + } + + [HttpPost] + public void DeleteService(int id) + { + if (APIStoreKeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + _serviceLogic.Delete(new ServiceBindingModel + { + Id = id + }); + + Response.Redirect("/Service/Services"); + } + } +} diff --git a/BeautyStudio/StoreKeeperWebApp/Program.cs b/BeautyStudio/StoreKeeperWebApp/Program.cs index 0727468..c69b8a4 100644 --- a/BeautyStudio/StoreKeeperWebApp/Program.cs +++ b/BeautyStudio/StoreKeeperWebApp/Program.cs @@ -1,16 +1,69 @@ +using BeautyStudioBusinessLogic.BusinessLogic; +using BeautyStudioBusinessLogic.MailWorker; +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.BusinessLogicContracts; +using BeautyStudioContracts.StoragesContracts; +using BeautyStudioBusinessLogic.OfficePackage.Implements; +using BeautyStudioBusinessLogic.OfficePackage; +using System.Reflection.PortableExecutable; +using BeautyStudioDatabaseImplement.Implements; + + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +// Logger service +builder.Logging.SetMinimumLevel(LogLevel.Trace); + +// Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSingleton(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); + var app = builder.Build(); +// Configuration for MailService +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); @@ -21,7 +74,7 @@ app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml new file mode 100644 index 0000000..ba5487e --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml @@ -0,0 +1,69 @@ +@using BeautyStudioContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Косметика"; +} + +
+

Косметика

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать косметику +

+ + + + + + + + + + + + + + + @foreach (var cosmetics in Model) + { + + + + + + + + } + +
НомерНазваниеБрендЦена
@cosmetics.Id@cosmetics.CosmeticName@cosmetics.CosmeticPrice +

+
+

+
+ } +
+ +@section scripts { + +} + + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Create.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Create.cshtml index 7969d2e..678d2db 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Create.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Create.cshtml @@ -1,26 +1,41 @@ @{ - ViewData["Title"] = "Косметика"; + ViewData["Title"] = "Создание косметики"; } -

Создать косметику

+
+

Создание косметики

+
-
-

Бренд:

- -

Наименование косметики:

- -

Стоимость:

- -

Выбрать трудозатрату для привязки:

- - + + +
+
Название:
+
+
+ + +
+
Цена:
+
+
+ + +
+
Трудозатрата:
+
+ +
+
+ + +
+
+
+
+ diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Update.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Update.cshtml index ce73463..019ec02 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Update.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Update.cshtml @@ -1,36 +1,45 @@ -@{ - ViewData["Title"] = "Косметика"; +@using BeautyStudioContracts.ViewModels + +@model CosmeticViewModel + +@{ + ViewData["Title"] = "Редактирование косметики"; } -

Обновить косметику

+
+

Редактирование косметики

+
-
- -

Бренд:

- -

Наименование косметики:

- -

Стоимость:

- -

Трудозатраты:

- - -
\ No newline at end of file +
+ +
+
Название:
+
+
+ + +
+
Цена:
+
+
+ + +
+
Трудозатрата:
+
+ +
+
+ + +
+
+
+
+
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Create.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Create.cshtml index 8fcbc40..b21c0f3 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Create.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Create.cshtml @@ -1,15 +1,38 @@ @{ - ViewData["Title"] = "Трудозатраты"; + ViewData["Title"] = "Трудозатраты"; } -

Создать трудозатрату

+
+

Создание трудозатрат

+
-
-

Количество часов:

- -

Сложность:

- - + +
+
Количество часов:
+
+
+ +
+
Сложность:
+
+
+ +
+
Косметика:
+
+ +
+
+ + +
+
+
+
+ diff --git a/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/LaborCosts.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/LaborCosts.cshtml new file mode 100644 index 0000000..5649d9b --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/LaborCosts.cshtml @@ -0,0 +1,68 @@ +@using BeautyStudioContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Трудозатраты"; +} + +
+

Трудозатраты

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать Трудозатрату +

+ + + + + + + + + + + + + + @foreach (var laborCosts in Model) + { + + + + + + + + } + +
НомерКоличество часовСложность
@laborCosts.Id@laborCosts.TimeSpent@laborCosts.Difficulty +

+
+

+
+ } +
+ +@section scripts { + +} + + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Update.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Update.cshtml index cc25bc3..3c9a647 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Update.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/LaborCosts/Update.cshtml @@ -1,16 +1,29 @@ -@{ - ViewData["Title"] = "Трудозатраты"; +@using BeautyStudioContracts.ViewModels + +@model LaborCostViewModel + +@{ + ViewData["Title"] = "Редактирование трудозатраты"; } -

Обновить трудозатраты

+
+

Редактирование трудозатраты

+
-
- -

Количество часов:

- -

Сложность:

- - + +
+
Количество часов:
+
+
+ +
+
Сложность:
+
+
+ + +
+
+
+
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Service/Bind.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/Bind.cshtml deleted file mode 100644 index 3e57875..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Service/Bind.cshtml +++ /dev/null @@ -1,51 +0,0 @@ -@{ - ViewData["Title"] = "Binding"; -} - -

Связать услугу с косметикой

- -

- Id услуги:  - @ViewBag.ServiceId -

-

- Наименование услуги:  - -

-

Привязанная косметика:

-
- - - - - - - - - - - - - - - - - - -
НаименованиеСтоимостьКоличество
Не выбрано
-
- -

Добавить косметику:

-

Наименование:

- -

Количество:

- - - - - - diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Service/Create.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/Create.cshtml index 50ac208..0d1697a 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Service/Create.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Service/Create.cshtml @@ -1,15 +1,47 @@ @{ - ViewData["Title"] = "Услуги"; + ViewData["Title"] = "Создание услуг"; } -

Создать услугу

+
+

Создание услуги

+
-
-

Наименование услуги:

- -

Стоимость услуги:

- - + +
+
Название:
+
+
+
+
Цена:
+
+
+ +
+
Процедуры:
+
+ +
+
+
+
Косметика:
+
+ +
+
+ + +
+
+
+
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml new file mode 100644 index 0000000..ad0f2fc --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml @@ -0,0 +1,67 @@ +@using BeautyStudioContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Услуги"; +} + +
+

Услуги

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать Услугу +

+ + + + + + + + + + + + + + @foreach (var service in Model) + { + + + + + + + + } + +
НомерНазваниеЦена
@service.Id@service.ServiceName@service.ServicePrice +

+
+

+
+ } +
+ +@section scripts { + +} + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Service/Update.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/Update.cshtml index 6eb7c26..5e13baa 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Service/Update.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Service/Update.cshtml @@ -1,18 +1,54 @@ -@{ - ViewData["Title"] = "Услуга"; +@using BeautyStudioContracts.ViewModels + +@model ServiceViewModel + +@{ + ViewData["Title"] = "Создание услуги"; } -

Обновить услугу

+
+

Редактирование услуги

+
-
- -

Наименование услуги:

- -

Стоимость услуги:

- - + +
+
Название:
+
+
+
+
Цена:
+
+
+ +
+
Процедуры:
+
+ +
+
+
+
Косметика:
+
+ +
+
+ + +
+
+
+
diff --git a/BeautyStudio/StoreKeeperWebApp/libman.json b/BeautyStudio/StoreKeeperWebApp/libman.json new file mode 100644 index 0000000..ceee271 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/libman.json @@ -0,0 +1,5 @@ +{ + "version": "1.0", + "defaultProvider": "cdnjs", + "libraries": [] +} \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/nlog.config b/BeautyStudio/StoreKeeperWebApp/nlog.config new file mode 100644 index 0000000..700fddf --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file