From 4f48beb8c933eb3f48705ec385754fe481c34700 Mon Sep 17 00:00:00 2001 From: K Date: Wed, 29 May 2024 14:21:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=BE=D0=BC=D0=B0=D0=B5=D0=BC=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ReportLogic.cs | 129 +++++++---- .../BindingModels/OrderBindingModel.cs | 23 +- .../BusinessLogicContracts/IOrderLogic.cs | 11 +- .../BusinessLogicContracts/IReportLogic.cs | 27 ++- .../SearchModels/OrderSearchModel.cs | 12 +- .../ViewModels/OrderViewModel.cs | 34 ++- .../ReportCosmeticProceduresViewModel.cs | 15 ++ .../ViewModels/ReportOrdersViewModel.cs | 2 +- .../ReportProcedureCosmeticsViewModel.cs | 16 ++ .../ViewModels/ReportServicesViewModel.cs | 17 ++ .../Models/IOrderModel.cs | 10 +- .../BeautySalonDatabase.cs | 2 +- .../Implements/CosmeticStorage.cs | 2 - .../Implements/OrderStorage.cs | 155 +++++++------ .../Models/Order_.cs | 218 ++++++++++-------- .../ClientWebApp/Views/Shared/_Layout.cshtml | 97 ++++---- 16 files changed, 485 insertions(+), 285 deletions(-) create mode 100644 BeautySalonView/BeautySalonContracts/ViewModels/ReportCosmeticProceduresViewModel.cs create mode 100644 BeautySalonView/BeautySalonContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs create mode 100644 BeautySalonView/BeautySalonContracts/ViewModels/ReportServicesViewModel.cs diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ReportLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ReportLogic.cs index 85b271f..f849581 100644 --- a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ReportLogic.cs @@ -1,9 +1,5 @@ using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels; using PrecastConcretePlantBusinessLogic.OfficePackage; -using PrecastConcretePlantContracts.BindingModels; -using PrecastConcretePlantContracts.BusinessLogicsContracts; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; using System; using System.Collections.Generic; @@ -12,92 +8,147 @@ using System.Text; using System.Threading.Tasks; using BeautySalonContracts.BusinessLogicsContracts; using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.BindingModels; namespace BeautySalonBusinessLogic.BusinessLogic { public class ReportLogic : IReportLogic { - private readonly IProcedureStorage _componentStorage; - private readonly ICosmeticStorage _reinforcedStorage; + private readonly IProcedureStorage _procedureStorage; + private readonly ICosmeticStorage _cosmeticStorage; private readonly IOrderStorage _orderStorage; + private readonly IServiceStorage _serviceStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ICosmeticStorage reinforcedStorage, IProcedureStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(ICosmeticStorage cosmeticStorage, IProcedureStorage procedureStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { - _reinforcedStorage = reinforcedStorage; - _componentStorage = componentStorage; + _cosmeticStorage = cosmeticStorage; + _procedureStorage = procedureStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } - public List GetReinforcedComponents() + //Получение процедур по косметике + public List GetCosmeticProcedures() { - var components = _componentStorage.GetFullList(); - var reinforceds = _reinforcedStorage.GetFullList(); - var list = new List(); - foreach (var reinforced in reinforceds) + var procedures = _procedureStorage.GetFullList(); + var cosmetics = _cosmeticStorage.GetFullList(); + var list = new List(); + + foreach (var cosmetic in cosmetics) { - var record = new ReportReinforcedComponentViewModel + var record = new ReportCosmeticProceduresViewModel { - ReinforcedName = reinforced.ReinforcedName, - Components = new List<(string Component, int Count)>(), - TotalCount = 0 + CosmeticName = cosmetic.CosmeticName, + Procedures = new List(), }; - foreach (var component in components) + + foreach (var procedure in procedures) { - if (reinforced.ReinforcedComponents.ContainsKey(component.Id)) + // Проверяем соответствие процедуры данному косметическому продукту + if (cosmetic.CosmeticProcedure.Any(cp => cp.Procedure.Id == procedure.Id)) { - record.Components.Add(new(component.ComponentName, reinforced.ReinforcedComponents[component.Id].Item2)); - record.TotalCount += reinforced.ReinforcedComponents[component.Id].Item2; + // Добавляем информацию о процедуре в список Procedures + record.Procedures.Add($"{procedure.ProcedureName} - {cosmetic.CosmeticProcedure.Find(cp => cp.Procedure.Id == procedure.Id)}"); // Вы можете использовать нужные вам свойства из CosmeticProcedureViewModel } } + list.Add(record); } + + return list; + } + //Получение косметики по процедуре + public List GetProcedureCosmetics() + { + var procedures = _procedureStorage.GetFullList(); + var cosmetics = _cosmeticStorage.GetFullList(); + var list = new List(); + + foreach (var procedure in procedures) + { + var record = new ReportProcedureCosmeticsViewModel + { + ProcedureName = procedure.ProcedureName, + Cosmetics = new List<(string Cosmetic, int Count)>(), + }; + + foreach (var cosmetic in cosmetics) + { + if (procedure.CosmeticProcedures.Any(cp => cp.Cosmetic.Id == cosmetic.Id)) + { + var cosmeticProcedure = procedure.CosmeticProcedures.Find(cp => cp.Cosmetic.Id == cosmetic.Id); + + if (cosmeticProcedure != null) + { + record.Cosmetics.Add((cosmetic.CosmeticName, cosmeticProcedure.Count)); + } + } + } + + // Вычисляем общее количество для данной процедуры + record.TotalCount = record.Cosmetics.Sum(c => c.Count); + + list.Add(record); + } + return list; } - public List GetOrders(ReportBindingModel model) + + + + + + public List GetServices(ReportBindingModel model) { - List r = _orderStorage.GetFilteredList(new OrderSearchModel - { - DateFrom = model.DateFrom, - DateTo = model.DateTo - }) - .Select(x => new ReportOrdersViewModel + List r = _serviceStorage.GetFullList() + .Select(x => new ReportServicesViewModel { Id = x.Id, - DateCreate = x.DateCreate, - ReinforcedName = x.ReinforcedName, - Sum = x.Sum, - Status = x.Status.ToString(), + Cosmetics = x.ServiceCosmetic, + CosmeticName = x.ServiceCosmetic.Cosmetic.Mane }) .ToList(); return r; } - public void SaveReinforcedsToWordFile(ReportBindingModel model) + public List GetServices(ReportBindingModel model) + { + List r = _serviceStorage.GetFullList() + .Select(x => new ReportServicesViewModel + { + Id = x.Id, + ProcedureName = x.ServiceProcedure.Procedure.Name, + CosmeticName = x.ServiceCosmetic.Cosmetic.Mane + }) + .ToList(); + return r; + } + + public void SaveCosmeticsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список ЖИ", - Reinforceds = _reinforcedStorage.GetFullList() + Cosmetics = _cosmeticStorage.GetFullList() }); } - public void SaveReinforcedComponentToExcelFile(ReportBindingModel model) + public void SaveCosmeticProcedureToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, Title = "Список ЖИ", - ReinforcedComponents = GetReinforcedComponents() + CosmeticProcedures = GetCosmeticProcedures() }); } - public void SaveOrdersToPdfFile(ReportBindingModel model) + public void SaveServicesToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { @@ -105,7 +156,7 @@ namespace BeautySalonBusinessLogic.BusinessLogic Title = "Список заказов", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, - Orders = GetOrders(model) + Services = GetServices(model) }); } diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs index 46b669a..99879b4 100644 --- a/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs +++ b/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs @@ -1,4 +1,5 @@ using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Enums; using BeautySalonDataModels.Models; using System; using System.Collections.Generic; @@ -8,11 +9,25 @@ namespace BeautySalonContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public DateTime OrderDate { get; set; } public double OrderAmount { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } public int ClientId { get; set; } - public List OrderService { get; set; } = new(); - public List OrderCosmetic { get; set; } = new(); - public List OrderProcedure { get; set; } = new(); + public Dictionary OrderCosmetics + { + get; + set; + } = new(); + public Dictionary OrderProcedures + { + get; + set; + } = new(); + public Dictionary OrderServices + { + get; + set; + } = new(); } } diff --git a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs index 51e0765..f1c0571 100644 --- a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs @@ -8,10 +8,11 @@ namespace BeautySalonContracts.BusinessLogicContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - OrderViewModel? ReadElement(OrderSearchModel model); - bool Create(OrderBindingModel model); - bool Delete(OrderBindingModel model); - bool Update(OrderBindingModel model); - + OrderViewModel? ReadElement(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } } diff --git a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IReportLogic.cs b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IReportLogic.cs index 69c559b..a5a3916 100644 --- a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IReportLogic.cs +++ b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IReportLogic.cs @@ -5,24 +5,41 @@ using System.Text; using System.Threading.Tasks; using BeautySalonContracts.ViewModels; using BeautySalonContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; namespace BeautySalonContracts.BusinessLogicsContracts { public interface IReportLogic { - // Получение списка компонент с указанием, в каких изделиях используются + // Получение списка процедур с указанием, какую косметику использует List GetCosmeticProcedures(); + // Получение списка косметики с указанием, в каких процедурах используется + List GetProcedureCosmetics(); + + // Получение списка услуг за определенный период + List GetServices(ReportBindingModel model); // Получение списка заказов за определенный период - List GetServices(ReportBindingModel model); + List GetOrders(ReportBindingModel model); // Сохранение компонент в файл-Word void SaveCosmeticsToWordFile(ReportBindingModel model); - // Сохранение компонент с указаеним продуктов в файл-Excel - void SaveCosmeticProceduresToExcelFile(ReportBindingModel model); + // Сохранение процедур по косметике в файл-Word + void SaveCosmeticProceduresToWordFile(ReportBindingModel model); + // Сохранение косметики по процедурам в файл-Word + void SaveProcedureCosmeticsToWordFile(ReportBindingModel model); - // Сохранение заказов в файл-Pdf + + // Сохранение процедур с указанием косметики в файл-Excel + void SaveCosmeticProceduresToExcelFile(ReportBindingModel model); + // Сохранение косметики с указанием процедур в файл-Excel + void SaveProcedureCosmeticsToExcelFile(ReportBindingModel model); + + + // Сохранение услуг в файл-Pdf void SaveServicesToPdfFile(ReportBindingModel model); + // Сохранение заказов в файл-Pdf + void SaveOrdersToPdfFile(ReportBindingModel model); } } diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs index 322bdea..111c5f2 100644 --- a/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs +++ b/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using BeautySalonDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,8 +10,13 @@ namespace BeautySalonContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } - public DateTime? OrderDate { get; set; } public int? ClientId { get; set; } - + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + public List? Statuses { get; set; } + public List? CosmeticIds { get; set; } + public List? PeocedureIds { get; set; } + public List? ServiceIds { get; set; } + } } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs index 73b715e..41a9ea9 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs @@ -1,7 +1,9 @@ -using BeautySalonDataModels.Models; +using BeautySalonDataModels.Enums; +using BeautySalonDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,17 +14,35 @@ namespace BeautySalonContracts.ViewModels { public int Id { get; set; } - [DisplayName("Дата оформления заказа")] - public DateTime OrderDate { get; set; } - [DisplayName("Стоимость")] public double OrderAmount { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + public int ClientId { get; set; } [DisplayName("Клиент")] - public List OrderService { get; set; } = new(); - public List OrderCosmetic { get; set; } = new(); - public List OrderProcedure { get; set; } = new(); + public Dictionary OrderCosmetics + { + get; + set; + } = new(); + public Dictionary OrderProcedures + { + get; + set; + } = new(); + public Dictionary OrderServices + { + get; + set; + } = new(); } } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ReportCosmeticProceduresViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ReportCosmeticProceduresViewModel.cs new file mode 100644 index 0000000..6b528ae --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ReportCosmeticProceduresViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportCosmeticProceduresViewModel + { + public string CosmeticName { get; set; } = string.Empty; + public List Procedures { get; set; } = new(); + + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ReportOrdersViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ReportOrdersViewModel.cs index 5af91a3..1151106 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/ReportOrdersViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ReportOrdersViewModel.cs @@ -10,7 +10,7 @@ namespace PrecastConcretePlantContracts.ViewModels { public int Id { get; set; } public DateTime DateCreate { get; set; } - public string ReinforcedName { get; set; } = string.Empty; + public string ServiceName { get; set; } = string.Empty; public double Sum { get; set; } public string Status { get; set; } = string.Empty; } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs new file mode 100644 index 0000000..f43fe52 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportProcedureCosmeticsViewModel + { + public string ProcedureName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Cosmetic, int Count)> Cosmetics { get; set; } = new(); + + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ReportServicesViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ReportServicesViewModel.cs new file mode 100644 index 0000000..5ebd15f --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ReportServicesViewModel.cs @@ -0,0 +1,17 @@ +using BeautySalonContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportServicesViewModel + { + public int Id { get; set; } + public List Procedures{ get; set; } + public List Cosmetics { get; set; } + } +} + diff --git a/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs b/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs index 89e7f4a..0e2283a 100644 --- a/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs +++ b/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs @@ -1,12 +1,18 @@ -using System; +using BeautySalonDataModels.Enums; +using System; using System.Collections.Generic; namespace BeautySalonDataModels.Models { public interface IOrderModel : IId { - DateTime OrderDate { get; } double OrderAmount { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } int ClientId { get; } + Dictionary OrderCosmetics { get; } //список косметики "участвующей" в заказе + Dictionary OrderProcedures{ get; } //список процедур "участвующих" в заказе + Dictionary OrderServices { get; } //список услуг "участвующих" в заказе } } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs index fff9b14..4c2f56d 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs @@ -18,7 +18,7 @@ namespace BeautySalonDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=ALYONA;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs index 61c95db..ed193bc 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs @@ -16,8 +16,6 @@ namespace BeautySalonDatabaseImplement.Implements { using var context = new BeautySalonDatabase(); return context.Cosmetics - //.Include(x => x.Procedures) - //.ThenInclude(x => x.Procedure) .Select(x => x.GetViewModel) .ToList(); } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs index 86b8f8f..7fbb5c6 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs @@ -15,74 +15,6 @@ namespace BeautySalonDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new BeautySalonDatabase(); - var element = context.Orders - .Include(x => x.Services) - .Include(x => x.Procedures) - .Include(x => x.Cosmetics) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Orders.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new BeautySalonDatabase(); - 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) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; - } - - public List GetFilteredList(OrderSearchModel model) - { - if (model == null) - { - return new(); - } - using var context = new BeautySalonDatabase(); - if (model.ClientId.HasValue && model.OrderDate.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.ClientId == model.ClientId && - x.OrderDate == model.OrderDate).ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - if (model.ClientId.HasValue) - { - return context.Orders - .Include(x => x.Services) - .ThenInclude(x => x.Service) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); - } - public List GetFullList() { using var context = new BeautySalonDatabase(); @@ -97,7 +29,44 @@ namespace BeautySalonDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - + public List GetFilteredList(OrderSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new BeautySalonDatabase(); + if (model.ClientId.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.ClientId == model.ClientId).ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new BeautySalonDatabase(); + 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) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } public OrderViewModel? Insert(OrderBindingModel model) { using var context = new BeautySalonDatabase(); @@ -108,7 +77,14 @@ namespace BeautySalonDatabaseImplement.Implements } context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + 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) + .FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -136,5 +112,44 @@ namespace BeautySalonDatabaseImplement.Implements throw; } } + public OrderViewModel? Delete(OrderBindingModel model) + { + /*using var context = new BeautySalonDatabase(); + var element = context.Orders + .Include(x => x.Services) + .Include(x => x.Procedures) + .Include(x => x.Cosmetics) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null;*/ + + using var context = new BeautySalonDatabase(); + var element = context.Orders + .Include(x => x.Services) + .Include(x => x.Procedures) + .Include(x => x.Cosmetics) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = 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) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Orders.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } } } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs index 92cb7b5..0cec91f 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs @@ -1,6 +1,8 @@ using BeautySalonContracts.BindingModels; using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Enums; using BeautySalonDataModels.Models; +using DocumentFormat.OpenXml.Office2021.DocumentTasks; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -25,160 +27,196 @@ namespace BeautySalonDatabaseImplement.Models public int ClientId { get; set; } public virtual Client? Client { get; set; } - private List? _orderServices = null; - - private List? _orderCosmetics = null; - - private List? _orderProcedures = null; + [Required] + public OrderStatus Status { get; private set; } + [Required] + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + private Dictionary? _orderCosmetics = null;//Это поле для хранения словаря OrderCosmetics. [NotMapped] - public List OrderServices + public Dictionary OrderCosmetics//представляет список косметики, участвующей в заказе. Не присутствует в базе данных. { get { - _orderServices ??= Services - .Select(pc => new OrderServiceViewModel(pc.Service.GetViewModel, pc.OrderServiceCount)) - .ToList(); - return _orderServices; - } - } - - [NotMapped] - public List OrderProcedures - { - get - { - _orderProcedures ??= Procedures - .Select(pc => new OrderProcedureViewModel(pc.Procedure.GetViewModel, pc.OrderProcedureCount)) - .ToList(); - return _orderProcedures; - } - } - - [NotMapped] - public List OrderCosmetics - { - get - { - _orderCosmetics ??= Cosmetics - .Select(pc => new OrderCosmeticViewModel(pc.Cosmetic.GetViewModel)) - .ToList(); + if (_orderCosmetics == null) + { + _orderCosmetics = Cosmetics + .ToDictionary(recPC => recPC.CosmeticId, recPC => recPC.Cosmetic.CosmeticName); + } return _orderCosmetics; } } - - // связь услуги и заказов многие - ко - многим [ForeignKey("OrderId")] - public virtual List Services { get; set; } = new(); + public virtual List Cosmetics { get; set; } = new();//представляет список косметических товаров для данного заказа. - [ForeignKey("OrderId")] - public virtual List Cosmetics { get; set; } = new(); + private Dictionary? _orderProcedures = null;//Это поле для хранения словаря OrderProcedures. + [NotMapped] + public Dictionary OrderProcedures//представляет список процедур, участвующих в заказе. Не присутствует в базе данных. + { + get + { + if (_orderProcedures == null) + { + _orderProcedures = Procedures + .ToDictionary(recPC => recPC.ProcedureId, recPC => recPC.Procedure.ProcedureName); + } + return _orderProcedures; + } + } [ForeignKey("OrderId")] - public virtual List Procedures { get; set; } = new(); + public virtual List Procedures { get; set; } = new();//представляет список процедур для данного заказа. + + + private Dictionary? _orderServices = null;//Это поле для хранения словаря OrderServices. + [NotMapped] + public Dictionary OrderServices//представляет список процедур, участвующих в заказе. Не присутствует в базе данных. + { + get + { + if (_orderServices == null) + { + _orderServices = Services + .ToDictionary(recPC => recPC.ServiceId, recPC => recPC.Service.ServiceName); + } + return _orderServices; + } + } + [ForeignKey("OrderId")] + public virtual List Services { get; set; } = new();//представляет список процедур для данного заказа. + public static Order_ Create(BeautySalonDatabase context, OrderBindingModel model) { - return new Order_() + if (model == null) + { + return null; + } + var order = new Order_() { Id = model.Id, - OrderDate = model.OrderDate, OrderAmount = model.OrderAmount, - Services = model.OrderService.Select(x => new OrderService() - { - Service = context.Services.First(y => y.Id == x.Service.Id), - OrderServiceCount = x.Count - }).ToList(), - Procedures = model.OrderProcedure.Select(x => new OrderProcedure() - { - Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id), - OrderProcedureCount = x.Count - }).ToList(), - Cosmetics= model.OrderCosmetic.Select(x => new OrderCosmetic() - { - Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), - }).ToList(), + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, ClientId = model.ClientId, + Cosmetics = model.OrderCosmetics.Select(x => new OrderCosmetic + { + Cosmetic = context.Cosmetics.First(y => y.Id == x.Key) + }).ToList(), + Procedures = model.OrderProcedures.Select(x => new OrderProcedure + { + Procedure = context.Procedures.First(y => y.Id == x.Key) + }).ToList(), + Services = model.OrderServices.Select(x => new OrderService + { + Service = context.Services.First(y => y.Id == x.Key) + }).ToList() }; + + return order; } public void Update(OrderBindingModel model) { - OrderDate = model.OrderDate; OrderAmount = model.OrderAmount; + Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, - OrderDate = OrderDate, OrderAmount = OrderAmount, - OrderService = OrderServices, - OrderProcedure = OrderProcedures, - OrderCosmetic = OrderCosmetics, - ClientId = ClientId + OrderServices = OrderServices, + OrderProcedures = OrderProcedures, + OrderCosmetics = OrderCosmetics, + ClientId = ClientId, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, }; - public void UpdateServices(BeautySalonDatabase context, OrderBindingModel model) + public void UpdateCosmetics(BeautySalonDatabase 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(BeautySalonDatabase 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(BeautySalonDatabase context, OrderBindingModel model) + public void UpdateServices(BeautySalonDatabase 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/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml b/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml index 09749be..2adb318 100644 --- a/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml +++ b/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml @@ -1,64 +1,49 @@  - - - @ViewData["Title"] - СlientApp - - - + + + @ViewData["Title"] - ClientWebApp + + + -
- -
-
-
- @RenderBody() -
-
+
+ +
+
+
+ @RenderBody() +
+
-
-
- © 2023 - BeutySalonClientApp - Privacy -
-
- - - - @await RenderSectionAsync("Scripts", required: false) +
+
+ © 2024 - ClientWebApp - Privacy +
+
+ + + + @await RenderSectionAsync("Scripts", required: false) \ No newline at end of file