diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BeautyStudioBusinessLogic.csproj b/BeautyStudio/BeautyStudioBusinessLogic/BeautyStudioBusinessLogic.csproj index 3ef7d76..efe0b63 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BeautyStudioBusinessLogic.csproj +++ b/BeautyStudio/BeautyStudioBusinessLogic/BeautyStudioBusinessLogic.csproj @@ -12,7 +12,8 @@ - + + diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs index 954af34..fb203b3 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/LaborCostLogic.cs @@ -94,23 +94,6 @@ namespace BeautyStudioBusinessLogic.BusinessLogic { return; } - if (model.TimeSpent <= 0) - { - throw new ArgumentNullException("Количество часов должно быть больше 0", nameof(model.TimeSpent)); - } - if (string.IsNullOrEmpty(model.Difficulty)) - { - 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/MessageInfoLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/MessageInfoLogic.cs deleted file mode 100644 index 9b76b52..0000000 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/MessageInfoLogic.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Microsoft.Extensions.Logging; -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.BusinessLogicContracts; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.StoragesContracts; -using BeautyStudioContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioBusinessLogic.BusinessLogic -{ - public class MessageInfoLogic : IMessageInfoLogic - { - private readonly ILogger _logger; - private readonly IMessageInfoStorage _messageInfoStorage; - private readonly IStoreKeeperStorage _staffmemberStorage; - public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage, IStoreKeeperStorage staffmemberStorage) - { - _logger = logger; - _messageInfoStorage = messageInfoStorage; - _staffmemberStorage = staffmemberStorage; - } - public List? ReadList(MessageInfoSearchModel? model) - { - _logger.LogInformation("ReadList. MessageId:{MessageId}. StorekeeperId:{StorekeeperId}", model?.MessageId, model?.StorekeeperId); - var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.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(MessageInfoBindingModel model) - { - CheckModel(model); - if (_messageInfoStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - private void CheckModel(MessageInfoBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.MessageId)) - { - throw new ArgumentNullException("Не указан id сообщения", nameof(model.MessageId)); - } - if (string.IsNullOrEmpty(model.SenderName)) - { - throw new ArgumentNullException("Не указана почта", nameof(model.SenderName)); - } - if (string.IsNullOrEmpty(model.Subject)) - { - throw new ArgumentNullException("Не указана тема", nameof(model.Subject)); - } - if (string.IsNullOrEmpty(model.Body)) - { - throw new ArgumentNullException("Не указан текст сообщения", nameof(model.Subject)); - } - - _logger.LogInformation("MessageInfo. MessageId:{MessageId}. SenderName:{SenderName}. Subject:{Subject}. Body:{Body}", model.MessageId, model.SenderName, model.Subject, model.Body); - var element = _staffmemberStorage.GetElement(new StoreKeeperSearchModel - { - StoreKeeperEmail = model.SenderName - }); - if (element == null) - { - _logger.LogWarning("Не удалоссь найти клиента, отправившего письмо с адреса Email:{Email}", model.SenderName); - } - else - { - model.StorekeeperId = element.Id; - } - } - } -} diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs index 487c02f..639d526 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,10 +1,8 @@ -using BeautyStudioBusinessLogic.MailWorker; -using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.BindingModels; using BeautyStudioContracts.BusinessLogicContracts; using BeautyStudioContracts.SearchModels; using BeautyStudioContracts.StoragesContracts; using BeautyStudioContracts.ViewModels; -using BeautyStudioDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -14,167 +12,95 @@ using System.Threading.Tasks; namespace BeautyStudioBusinessLogic.BusinessLogic { - public class OrderLogic : IOrderLogic - { - private readonly ILogger _logger; - private readonly 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 OrderViewModel? ReadElement(OrderSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _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); - 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 class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } - } - public bool Update(OrderBindingModel 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"); - return false; - } - return true; - } - public bool Delete(OrderBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_orderStorage.Delete(model) == null) - { - _logger.LogWarning("Delete order operation failed"); - return false; - } - return true; - } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - 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) - { + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. OrderId:Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } - return StatusUpdate(model, OrderStatus.Выдан); - } - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Sum <= 0) - { - 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("Заказ с таким номером уже есть"); - } - } - private bool SendOrderStatusMail(int clientId, string subject, string text) - { - var client = _clientLogic.ReadElement(new() { Id = clientId }); - if (client == null) - { - return false; - } - _mailWorker.MailSendAsync(new() - { - MailAddress = client.StoreKeeperEmail, - Subject = subject, - Text = text - }); - return true; - } - } + public bool Create(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(OrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_orderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if(model.Sum < 0) + { + throw new ArgumentOutOfRangeException("Сумма меньше нуля",nameof(model.Sum)); + } + _logger.LogInformation("Order. Order:Id:{ Id}.Sum:{ Sum}", model.Id, model.Sum); + } + } } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs deleted file mode 100644 index 83ebe62..0000000 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ReportLogic.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BeautyStudioContracts.BusinessLogicContracts; -using BeautyStudioContracts.StoragesContracts; -using BeautyStudioBusinessLogic.OfficePackage; -using BeautyStudioContracts.ViewModels; -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.SearchModels; -using BeautyStudioBusinessLogic.OfficePackage.HelperModels; -using BeautyStudioBusinessLogic.OfficePackage.Implements; - -namespace BeautyStudioBusinessLogic.BusinessLogic -{ - public class ReportLogic : IReportLogic - { - private readonly IServiceStorage _serviceStorage; - private readonly IProcedureStorage _procedureStorage; - private readonly ICosmeticStorage _cosmeticStorage; - - private readonly AbstractSaveToExcel _saveToExcel; - private readonly AbstractSaveToWord _saveToWord; - private readonly AbstractSaveToPdf _saveToPdf; - - public ReportLogic(IServiceStorage serviceStorage, IProcedureStorage procedureStorage, ICosmeticStorage cosmeticStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) - { - _serviceStorage = serviceStorage; - _procedureStorage = procedureStorage; - _cosmeticStorage = cosmeticStorage; - _saveToExcel = saveToExcel; - _saveToWord = saveToWord; - _saveToPdf = saveToPdf; - } - //Получение косметики по процедуре - public List GetCosmeticProcedures() - { - var cosmetics = _cosmeticStorage.GetFullList(); - var procedures = _procedureStorage.GetFullList(); - var list = new List(); - foreach (var cosmetic in cosmetics) - { - var record = new ReportCosmeticProceduresViewModel - { - CosmeticName = cosmetic.CosmeticName, - Procedures = new List(), - }; - foreach (var procedure in procedures) - { - if (cosmetic.CosmeticProcedure.ContainsKey(procedure.Id)) - { - record.Procedures.Add(new(procedure.ProcedureName)); - } - } - list.Add(record); - } - return list; - } - - public List GetServices(ReportServiceBindingModel model) - { - List r = _serviceStorage.GetFullList() - .Select(x => new ReportServicesViewModel - { - Id = x.Id, - ServiceName = x.ServiceName, - 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; - } - - public void SaveCosmeticProceduresToWordFile(ReportBindingModel model) - { - _saveToWord.CreateDoc(new WordInfo - { - FileName = model.FileName, - Title = "Список процедур по косметике", - CosmeticProcedures = GetCosmeticProcedures() - }); - } - public void SaveCosmeticProceduresToExcelFile(ReportBindingModel model) - { - _saveToExcel.CreateReport(new ExcelInfo - { - FileName = model.FileName, - Title = "Список процедур по косметике", - CosmeticProcedures = GetCosmeticProcedures() - }); - } - - public void SaveServicesToPdfFile(ReportServiceBindingModel model) - { - var report = new PdfInfo - { - FileName = model.FileName, - Title = "Список услуг", - Services = GetServices(model) - }; - _saveToPdf.CreateReport(report); - } - } -} diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs index 185a276..7a598a9 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs @@ -56,8 +56,8 @@ namespace BeautyStudioBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", - model.StoreKeeperLogin, model.StoreKeeperEmail, model.Id); + _logger.LogInformation("ReadElement. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", + model.StoreKeeperEmail, model.Id); var element = _storeKeeperStorage.GetElement(model); @@ -74,8 +74,8 @@ namespace BeautyStudioBusinessLogic.BusinessLogic public List? ReadList(StoreKeeperSearchModel? model) { - _logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", - model?.StoreKeeperLogin, model?.StoreKeeperEmail, model?.Id); + _logger.LogInformation("ReadElement. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", + model?.StoreKeeperEmail, model?.Id); var list = model == null ? _storeKeeperStorage.GetFullList() : _storeKeeperStorage.GetFilteredList(model); @@ -114,7 +114,7 @@ namespace BeautyStudioBusinessLogic.BusinessLogic } if (string.IsNullOrEmpty(model.StoreKeeperFIO)) { - throw new ArgumentNullException("Нет имени кладовщика", nameof(model.StoreKeeperLogin)); + throw new ArgumentNullException("Нет имени кладовщика", nameof(model.StoreKeeperFIO)); } if (string.IsNullOrEmpty(model.StoreKeeperLogin)) { diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 796beab..2d00a29 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -29,9 +29,28 @@ namespace BeautyStudioBusinessLogic.OfficePackage CellToName = "C1" }); - uint rowIndex = 2; + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 2, + Text = "Косметика", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = 2, + Text = "Процедуры", + StyleInfo = ExcelStyleInfoType.Title + }); - foreach (var pc in info.CosmeticProcedures) + MergeCells(new ExcelMergeParameters + { + CellFromName = "B2", + CellToName = ColumnLetter(info.maxleng + 1) + "2" + }); + uint rowIndex = 3; + foreach (var pc in info.cosmeticProceduresReport) { InsertCellInWorksheet(new ExcelCellParameters { @@ -40,22 +59,41 @@ namespace BeautyStudioBusinessLogic.OfficePackage Text = pc.CosmeticName, StyleInfo = ExcelStyleInfoType.Text }); - rowIndex++; - foreach (var procedure in pc.Procedures) + int place = 2; + foreach (var proc in pc.Procedures) { InsertCellInWorksheet(new ExcelCellParameters { - ColumnName = "B", + ColumnName = ColumnLetter(place), RowIndex = rowIndex, - Text = procedure, + Text = proc, StyleInfo = ExcelStyleInfoType.TextWithBorder }); + + place++; } rowIndex++; } + SaveExcel(info); } + private static string ColumnLetter(int columnIndex) + { + int dividend = columnIndex; + string columnName = String.Empty; + int modulo; + + while (dividend > 0) + { + modulo = (dividend - 1) % 26; + columnName = Convert.ToChar(65 + modulo).ToString() + columnName; + dividend = (dividend - modulo) / 26; + } + + return columnName; + } + //Создание эксель файла protected abstract void CreateExcel(ExcelInfo info); diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 668e6c3..a8cecb3 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -35,8 +35,8 @@ namespace BeautyStudioBusinessLogic.OfficePackage Style = "Normal" }); - // Создаем таблицу с тремя колонками - CreateTable(new List { "7cm", "4cm", "4cm" }); + // Создаем таблицу с двумя колонками + CreateTable(new List { "5cm", "10cm" }); // Создаем заголовок таблицы CreateRow(new PdfRowParameters @@ -47,43 +47,40 @@ namespace BeautyStudioBusinessLogic.OfficePackage }); // Записываем основную информацию - foreach (var view in info.Services) + foreach (var report in info.Services) { CreateRow(new PdfRowParameters { - Texts = new List { view.ServiceName, "", "" }, + Texts = new List { "Номер услуги", "Заказ" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateRow(new PdfRowParameters + { + Texts = new List { report.Id.ToString(), "" }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); - - // Конвертируем из HashSet в List, чтобы можно было обращаться по индексу - List cosmetics = new List(); - foreach (var item in view.Cosmetics) - { - var cosmeticModel = item.Value.Item1; - cosmetics.Add(cosmeticModel.CosmeticName); - } - List procedures = new List(); - foreach (var item in view.Procedures) - { - var procedureModel = item.Value.Item1; - procedures.Add(procedureModel.ProcedureName); - } - - // Записываем названия лекарств во 2 колонку - // и названия лекарств в 3 колонку - int maxLength = Math.Max(cosmetics.Count, procedures.Count); - for (int i = 0; i < maxLength; i++) - { - string cosmetic = (i < cosmetics.Count) ? cosmetics[i] : ""; - string procedure = (i < procedures.Count) ? procedures[i] : ""; + foreach (var product in report.Orders) CreateRow(new PdfRowParameters { - Texts = new List { "", procedure, cosmetic }, + Texts = new List { "", product }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + CreateRow(new PdfRowParameters + { + Texts = new List { "", "Трудозатраты" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var production in report.LaborCosts) + CreateRow(new PdfRowParameters + { + Texts = new List { "", production }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); - } } // Сохраняем файл diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 82bed17..873ed4b 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -15,18 +15,9 @@ namespace BeautyStudioBusinessLogic.OfficePackage CreateWord(info); CreateParagraph(new WordParagraph { - Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties - { Bold = true, Size = "24", }) }, - TextProperties = new WordTextProperties + Texts = new List<(string, WordTextProperties)> { - Size = "24", - JustificationType = WordJustificationType.Center - } - }); - CreateParagraph(new WordParagraph - { - Texts = new List<(string, WordTextProperties)> { - ("Косметика" +" - " + "Процедура", new WordTextProperties { Size = "24", Bold = true, }), + (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, TextProperties = new WordTextProperties { @@ -34,31 +25,23 @@ namespace BeautyStudioBusinessLogic.OfficePackage JustificationType = WordJustificationType.Both } }); - int i = 1; - foreach (var cp in info.CosmeticProcedures) - { - foreach (var procedure in cp.Procedures) - { - CreateParagraph(new WordParagraph - { - Texts = new List<(string, WordTextProperties)> { - (i + ". " + cp.CosmeticName + " - " + procedure, new WordTextProperties { Size = "24", Bold = false, }), - }, - TextProperties = new WordTextProperties - { - Size = "24", - JustificationType = WordJustificationType.Both - } - }); - } - i++; - } + foreach (var report in info.cosmeticProceduresReport) + { + CreateNumberedParagraph(1, 0, report.CosmeticName); + foreach (var workshop in report.Procedures) + { + CreateNumberedParagraph(1, 1, workshop); + } + + } SaveWord(info); } //Создание док-файла protected abstract void CreateWord(WordInfo info); //Создание абзаца с текстом protected abstract void CreateParagraph(WordParagraph paragraph); + //Создание абзаца с нумерованной маркировкой текста + protected abstract void CreateNumberedParagraph(int numId, int ilvl, string text); //Сохранение файла protected abstract void SaveWord(WordInfo info); } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index e0c3255..fedaf22 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -9,9 +9,9 @@ namespace BeautyStudioBusinessLogic.OfficePackage.HelperModels { public class ExcelInfo { - public string FileName { get; set; } = string.Empty; + public MemoryStream memoryStream { get; set; } = new MemoryStream(); public string Title { get; set; } = string.Empty; - public List CosmeticProcedures { get; set; } = new(); - public List ProcedureCosmetics { get; set; } = new(); + public List cosmeticProceduresReport { get; set; } = new(); + public int maxleng { get; set; } } } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 76dada7..152ee12 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -9,11 +9,10 @@ namespace BeautyStudioBusinessLogic.OfficePackage.HelperModels { public class PdfInfo { - public string FileName { get; set; } = string.Empty; + public MemoryStream FileName { get; set; } = new(); public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List Orders { get; set; } = new(); public List Services { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 4dce0ad..2d2e5ed 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -9,9 +9,8 @@ namespace BeautyStudioBusinessLogic.OfficePackage.HelperModels { public class WordInfo { - public string FileName { get; set; } = string.Empty; + public MemoryStream memoryStream { get; set; } = new MemoryStream(); public string Title { get; set; } = string.Empty; - public List CosmeticProcedures { get; set; } = new(); - public List ProcedureCosmetics { get; set; } = new(); + public List cosmeticProceduresReport { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 48d5210..2e083ca 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -13,303 +13,276 @@ using System.Threading.Tasks; namespace BeautyStudioBusinessLogic.OfficePackage.Implements { - public class SaveToExcel : AbstractSaveToExcel - { - private SpreadsheetDocument? _spreadsheetDocument; - private SharedStringTablePart? _shareStringPart; - private Worksheet? _worksheet; - private static void CreateStyles(WorkbookPart workbookpart) - { - var sp = workbookpart.AddNewPart(); - sp.Stylesheet = new Stylesheet(); - var fonts = new Fonts() { Count = 2U, KnownFonts = true }; - var fontUsual = new Font(); - fontUsual.Append(new FontSize() { Val = 12D }); - fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); - fontUsual.Append(new FontName() { Val = "Times New Roman" }); - fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); - fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); - var fontTitle = new Font(); - fontTitle.Append(new Bold()); - fontTitle.Append(new FontSize() { Val = 14D }); - fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); - fontTitle.Append(new FontName() { Val = "Times New Roman" }); - fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); - fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); - fonts.Append(fontUsual); - fonts.Append(fontTitle); - var fills = new Fills() { Count = 2U }; - var fill1 = new Fill(); - fill1.Append(new PatternFill() { PatternType = PatternValues.None }); var fill2 = new Fill(); - fill2.Append(new PatternFill() - { - PatternType = PatternValues.Gray125 - }); - fills.Append(fill1); - fills.Append(fill2); - var borders = new Borders() { Count = 2U }; - var borderNoBorder = new Border(); - borderNoBorder.Append(new LeftBorder()); - borderNoBorder.Append(new RightBorder()); - borderNoBorder.Append(new TopBorder()); - borderNoBorder.Append(new BottomBorder()); - borderNoBorder.Append(new DiagonalBorder()); - var borderThin = new Border(); - var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; - leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() - { Indexed = 64U }); - var rightBorder = new RightBorder() - { - Style = BorderStyleValues.Thin - }; - rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() - { Indexed = 64U }); - var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; - topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() - { Indexed = 64U }); - var bottomBorder = new BottomBorder() - { - Style = BorderStyleValues.Thin - }; - bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() - { Indexed = 64U }); - borderThin.Append(leftBorder); - borderThin.Append(rightBorder); - borderThin.Append(topBorder); - borderThin.Append(bottomBorder); - borderThin.Append(new DiagonalBorder()); - borders.Append(borderNoBorder); - borders.Append(borderThin); - var cellStyleFormats = new CellStyleFormats() { Count = 1U }; - var cellFormatStyle = new CellFormat() - { - NumberFormatId = 0U, - FontId = 0U, - FillId = 0U, - BorderId = 0U - }; - cellStyleFormats.Append(cellFormatStyle); - var cellFormats = new CellFormats() { Count = 3U }; - var cellFormatFont = new CellFormat() - { - NumberFormatId = 0U, - FontId = 0U, - FillId = 0U, - BorderId = 0U, - FormatId = 0U, - ApplyFont = true - }; - var cellFormatFontAndBorder = new CellFormat() - { - NumberFormatId = 0U, - FontId = 0U, - FillId = 0U, - BorderId = 1U, - FormatId = 0U, - ApplyFont = true, - ApplyBorder = true - }; - var cellFormatTitle = new CellFormat() - { - NumberFormatId = 0U, - FontId = 1U, - FillId = 0U, - BorderId = 0U, - FormatId = 0U, - Alignment = new Alignment() - { - Vertical = VerticalAlignmentValues.Center, - WrapText = true, - Horizontal = HorizontalAlignmentValues.Center - }, - ApplyFont = true - }; - cellFormats.Append(cellFormatFont); - cellFormats.Append(cellFormatFontAndBorder); - cellFormats.Append(cellFormatTitle); - var cellStyles = new CellStyles() { Count = 1U }; - cellStyles.Append(new CellStyle() - { - Name = "Normal", - FormatId = 0U, - BuiltinId = 0U - }); - var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + public class SaveToExcel : AbstractSaveToExcel + { + private SpreadsheetDocument? _spreadsheetDocument; - var tableStyles = new TableStyles() - { - Count = 0U, - DefaultTableStyle = "TableStyleMedium2", - DefaultPivotStyle = "PivotStyleLight16" - }; - var stylesheetExtensionList = new StylesheetExtensionList(); - var stylesheetExtension1 = new StylesheetExtension() - { - Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" - }; - stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); - stylesheetExtension1.Append(new SlicerStyles() - { - DefaultSlicerStyle = "SlicerStyleLight1" - }); - var stylesheetExtension2 = new StylesheetExtension() - { - Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" - }; - stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); - stylesheetExtension2.Append(new TimelineStyles() - { - DefaultTimelineStyle = "TimeSlicerStyleLight1" - }); - stylesheetExtensionList.Append(stylesheetExtension1); - stylesheetExtensionList.Append(stylesheetExtension2); - sp.Stylesheet.Append(fonts); - sp.Stylesheet.Append(fills); - sp.Stylesheet.Append(borders); - sp.Stylesheet.Append(cellStyleFormats); - sp.Stylesheet.Append(cellFormats); - sp.Stylesheet.Append(cellStyles); - sp.Stylesheet.Append(differentialFormats); - sp.Stylesheet.Append(tableStyles); - sp.Stylesheet.Append(stylesheetExtensionList); - } - /// Получение номера стиля из типа - private static uint GetStyleValue(ExcelStyleInfoType styleInfo) - { - return styleInfo switch - { - ExcelStyleInfoType.Title => 2U, - ExcelStyleInfoType.TextWithBorder => 1U, - ExcelStyleInfoType.Text => 0U, - _ => 0U, - }; - } - protected override void CreateExcel(ExcelInfo info) - { - string directoryPath = @"C:\reports\"; - if (!Directory.Exists(directoryPath)) + private SharedStringTablePart? _shareStringPart; + + private Worksheet? _worksheet; + + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; + var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; + var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; + + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + + var cellStyles = new CellStyles() { Count = 1U }; + + cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U }); + + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + + var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + var stylesheetExtensionList = new StylesheetExtensionList(); + + var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); + + var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch { - Directory.CreateDirectory(directoryPath); + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBorder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfo info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.memoryStream, SpreadsheetDocumentType.Workbook); + // Создаем книгу (в ней хранятся листы) + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + + CreateStyles(workbookpart); + + // Получаем/создаем хранилище текстов для книги + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : _spreadsheetDocument.WorkbookPart.AddNewPart(); + + // Создаем SharedStringTable, если его нет + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); } - _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, - SpreadsheetDocumentType.Workbook); - var workbookpart = _spreadsheetDocument.AddWorkbookPart(); - workbookpart.Workbook = new Workbook(); CreateStyles(workbookpart); - _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() - ? - _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() - : - _spreadsheetDocument.WorkbookPart.AddNewPart(); - if (_shareStringPart.SharedStringTable == null) - { - _shareStringPart.SharedStringTable = new SharedStringTable(); - } - var worksheetPart = workbookpart.AddNewPart(); - worksheetPart.Worksheet = new Worksheet(new SheetData()); + // Создаем лист в книгу + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); - var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); - var sheet = new Sheet() - { - Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), - SheetId = 1, - Name = "Лист" - }; - sheets.Append(sheet); - _worksheet = worksheetPart.Worksheet; - } - protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) - { - if (_worksheet == null || _shareStringPart == null) - { - return; - } - var sheetData = _worksheet.GetFirstChild(); - if (sheetData == null) - { - return; - } + // Добавляем лист в книгу + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); - Row row; - if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) - { - row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); - } - else - { - row = new Row() { RowIndex = excelParams.RowIndex }; - sheetData.Append(row); - } + _worksheet = worksheetPart.Worksheet; + } + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } - Cell cell; - if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) - { - cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); - } - else - { + // Ищем строку, либо добавляем ее + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } - Cell? refCell = null; - foreach (Cell rowCell in row.Elements()) - { - if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) - { - refCell = rowCell; - break; - } - } - var newCell = new Cell() - { - CellReference = excelParams.CellReference - }; - row.InsertBefore(newCell, refCell); - cell = newCell; - } + // Ищем нужную ячейку + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + // Все ячейки должны быть последовательно друг за другом расположены + // нужно определить, после какой вставлять + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } - _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); - _shareStringPart.SharedStringTable.Save(); - cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); - cell.DataType = new EnumValue(CellValues.SharedString); - cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); - } - protected override void MergeCells(ExcelMergeParameters excelParams) - { - if (_worksheet == null) - { - return; - } - MergeCells mergeCells; - if (_worksheet.Elements().Any()) - { - mergeCells = _worksheet.Elements().First(); - } - else - { - mergeCells = new MergeCells(); - if (_worksheet.Elements().Any()) - { - _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); - } - else - { - _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); - } - } - var mergeCell = new MergeCell() - { - Reference = new StringValue(excelParams.Merge) - }; - mergeCells.Append(mergeCell); - } - protected override void SaveExcel(ExcelInfo info) - { - if (_spreadsheetDocument == null) - { - return; - } - _spreadsheetDocument.WorkbookPart!.Workbook.Save(); - _spreadsheetDocument.Dispose(); - } + var newCell = new Cell() { CellReference = excelParams.CellReference }; + row.InsertBefore(newCell, refCell); - } + cell = newCell; + } + + // Вставляем новый текст + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + } + + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + protected override void SaveExcel(ExcelInfo info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + + } } \ No newline at end of file diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 99677c2..978c327 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -15,10 +15,12 @@ namespace BeautyStudioBusinessLogic.OfficePackage.Implements public class SaveToPdf : AbstractSaveToPdf { private Document? _document; + private Section? _section; + private Table? _table; - private static ParagraphAlignment - GetParagraphAlignment(PdfParagraphAlignmentType type) + + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) { return type switch { @@ -29,26 +31,28 @@ namespace BeautyStudioBusinessLogic.OfficePackage.Implements }; } + /// /// Создание стилей для документа + /// + /// private static void DefineStyles(Document document) { var style = document.Styles["Normal"]; style.Font.Name = "Times New Roman"; style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); style.Font.Bold = true; } + protected override void CreatePdf(PdfInfo info) { - string directoryPath = @"C:\reports\"; - if (!Directory.Exists(directoryPath)) - { - Directory.CreateDirectory(directoryPath); - } _document = new Document(); DefineStyles(_document); + _section = _document.AddSection(); } + protected override void CreateParagraph(PdfParagraph pdfParagraph) { if (_section == null) @@ -60,6 +64,7 @@ namespace BeautyStudioBusinessLogic.OfficePackage.Implements paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); paragraph.Style = pdfParagraph.Style; } + protected override void CreateTable(List columns) { if (_document == null) @@ -67,11 +72,13 @@ namespace BeautyStudioBusinessLogic.OfficePackage.Implements return; } _table = _document.LastSection.AddTable(); + foreach (var elem in columns) { _table.AddColumn(elem); } } + protected override void CreateRow(PdfRowParameters rowParameters) { if (_table == null) @@ -82,19 +89,24 @@ namespace BeautyStudioBusinessLogic.OfficePackage.Implements for (int i = 0; i < rowParameters.Texts.Count; ++i) { row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) { row.Cells[i].Style = rowParameters.Style; } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; row.Cells[i].Borders.Right.Width = borderWidth; row.Cells[i].Borders.Top.Width = borderWidth; row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); row.Cells[i].VerticalAlignment = VerticalAlignment.Center; } } + protected override void SavePdf(PdfInfo info) { var renderer = new PdfDocumentRenderer(true) diff --git a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToWord.cs index f9ea149..1971d3c 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -15,115 +15,128 @@ using Text = DocumentFormat.OpenXml.Wordprocessing.Text; namespace BeautyStudioBusinessLogic.OfficePackage.Implements { - public class SaveToWord : AbstractSaveToWord - { - private WordprocessingDocument? _wordDocument; - private Body? _docBody; + public class SaveToWord : AbstractSaveToWord + { + private WordprocessingDocument? _wordDocument; - private static JustificationValues GetJustificationValues(WordJustificationType type) - { - return type switch - { - WordJustificationType.Both => JustificationValues.Both, - WordJustificationType.Center => JustificationValues.Center, - _ => JustificationValues.Left, - }; - } - private static SectionProperties CreateSectionProperties() - { - var properties = new SectionProperties(); + private Body? _docBody; - var pageSize = new PageSize - { - Orient = PageOrientationValues.Portrait - }; - - properties.AppendChild(pageSize); - - return properties; - } - private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) - { - if (paragraphProperties == null) - { - return null; - } - - var properties = new ParagraphProperties(); - - properties.AppendChild(new Justification() - { - Val = GetJustificationValues(paragraphProperties.JustificationType) - }); - - properties.AppendChild(new SpacingBetweenLines - { - LineRule = LineSpacingRuleValues.Auto - }); - - properties.AppendChild(new Indentation()); - - var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); - if (!string.IsNullOrEmpty(paragraphProperties.Size)) - { - paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); - } - properties.AppendChild(paragraphMarkRunProperties); - - return properties; - } - protected override void CreateWord(WordInfo info) - { - string directoryPath = @"C:\reports\"; - if (!Directory.Exists(directoryPath)) + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch { - Directory.CreateDirectory(directoryPath); + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + + properties.AppendChild(pageSize); + + return properties; + } + + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; } - _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); - MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); - mainPart.Document = new Document(); - _docBody = mainPart.Document.AppendChild(new Body()); - } - protected override void CreateParagraph(WordParagraph paragraph) - { - if (_docBody == null || paragraph == null) - { - return; - } - var docParagraph = new Paragraph(); - docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + var properties = new ParagraphProperties(); - foreach (var run in paragraph.Texts) - { - var docRun = new Run(); + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); - var properties = new RunProperties(); - properties.AppendChild(new FontSize { Val = run.Item2.Size }); - if (run.Item2.Bold) - { - properties.AppendChild(new Bold()); - } - docRun.AppendChild(properties); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); - docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + properties.AppendChild(new Indentation()); - docParagraph.AppendChild(docRun); - } + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); + } + properties.AppendChild(paragraphMarkRunProperties); - _docBody.AppendChild(docParagraph); - } - protected override void SaveWord(WordInfo info) - { - if (_docBody == null || _wordDocument == null) - { - return; - } - _docBody.AppendChild(CreateSectionProperties()); + return properties; + } - _wordDocument.MainDocumentPart!.Document.Save(); + protected override void CreateWord(WordInfo info) + { + _wordDocument = WordprocessingDocument.Create(info.memoryStream, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } - _wordDocument.Dispose(); - } - } + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + _docBody.AppendChild(docParagraph); + } + + protected override void CreateNumberedParagraph(int numId, int ilvl, string text) + { + Paragraph paragraph = new Paragraph( + new ParagraphProperties( + new NumberingProperties( + new NumberingLevelReference() { Val = ilvl }, + new NumberingId() { Val = numId })), + new Run(new Text(text))); + + _docBody!.Append(paragraph); + } + + protected override void SaveWord(WordInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Dispose(); + } + } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs index cdafdfa..6b3eca5 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/CosmeticBindingModel.cs @@ -13,8 +13,10 @@ namespace BeautyStudioContracts.BindingModels public int Id { get; set; } public string CosmeticName { get; set; } = string.Empty; public double CosmeticPrice { get; set; } + public int? OrderId { get; set; } public int LaborCostId { get; set; } public int StoreKeeperId { get; set; } - public Dictionary CosmeticProcedure { get; set; } = new(); + public DateTime DateCreate { get; set; } + public Dictionary CosmeticServices { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs index 57693c1..bc5a5cd 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/LaborCostBindingModel.cs @@ -1,4 +1,5 @@ -using BeautyStudioDataModels.Models; +using BeautyStudioDataModels.Enums; +using BeautyStudioDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -10,8 +11,8 @@ 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 TimeSpent TimeSpent { get; set; } + public Difficulties Difficulty { get; set; } public int StoreKeeperId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/MailSendInfoBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/MailSendInfoBindingModel.cs index c8d3ef3..c36494a 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/MailSendInfoBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/MailSendInfoBindingModel.cs @@ -11,6 +11,7 @@ namespace BeautyStudioContracts.BindingModels public string MailAddress { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty; public string Text { get; set; } = string.Empty; - public string Path { get; set; } = string.Empty; - } + public byte[] Pdf { get; set; } + public string FileName { get; set; } = string.Empty; + } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/MessageInfoBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/MessageInfoBindingModel.cs deleted file mode 100644 index 5ded4b1..0000000 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/MessageInfoBindingModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using BeautyStudioDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.BindingModels -{ - public class MessageInfoBindingModel : IMessageInfoModel - { - public string MessageId { get; set; } = string.Empty; - public int? StorekeeperId { get; set; } - public string SenderName { get; set; } = string.Empty; - public string Subject { get; set; } = string.Empty; - public string Body { get; set; } = string.Empty; - public DateTime DateDelivery { get; set; } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs index 479a3b0..0602b60 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs @@ -1,25 +1,16 @@ -using BeautyStudioContracts.ViewModels; -using BeautyStudioDataModels.Enums; +using BeautyStudioDataModels.Enums; using BeautyStudioDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BeautyStudioContracts.BindingModels { public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public double Sum { get; set; } - public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateComplete { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public string OrderName { get; set; } = string.Empty; public int StoreKeeperId { get; set; } - - public Dictionary OrderServices { get; set; } = new(); - public Dictionary OrderCosmetics { get; set; } = new(); - public Dictionary OrderProcedures { get; set; } = new(); + public DateTime PaymentDate { get; set; } = DateTime.Now; + public double Sum { get; set; } + public Dictionary OrderProcedures { get; set; } = new(); + public Dictionary Cosmetics { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs index 04316f4..4a2759e 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/ProcedureBindingModel.cs @@ -3,6 +3,7 @@ using BeautyStudioDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -15,6 +16,6 @@ namespace BeautyStudioContracts.BindingModels public double ProcedureCost { get; set; } public string ProcedureDescription { get; set; } = string.Empty; public int StoreKeeperId { get; set; } - public Dictionary ProcedureCosmetics { get; set; } = new(); + public Dictionary ProcedureServices { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/ReportServiceBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/ReportServiceBindingModel.cs deleted file mode 100644 index 90c5eb8..0000000 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/ReportServiceBindingModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.BindingModels -{ - public class ReportServiceBindingModel - { - public string FileName { get; set; } = string.Empty; - public int? StorekeeperId { get; set; } - public string? Email { get; set; } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs index 0ed868a..9622270 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs @@ -14,7 +14,7 @@ namespace BeautyStudioContracts.BindingModels public string ServiceName { get; set; } = string.Empty; public double ServicePrice { get; set; } public int StoreKeeperId { get; set; } - public Dictionary ServiceCosmetics { get; set; } = new(); - public Dictionary ServiceProcedures { get; set; } = new(); + public DateTime DateCreate { get; set; } + public Dictionary ServiceProcedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IMessageInfoLogic.cs b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IMessageInfoLogic.cs deleted file mode 100644 index bc16df2..0000000 --- a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IMessageInfoLogic.cs +++ /dev/null @@ -1,17 +0,0 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.BusinessLogicContracts -{ - public interface IMessageInfoLogic - { - List? ReadList(MessageInfoSearchModel? model); - bool Create(MessageInfoBindingModel model); - } -} diff --git a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs index bb34e67..8df7b75 100644 --- a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic; -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.ViewModels; +using BeautyStudioContracts.BindingModels; using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BeautyStudioContracts.BusinessLogicContracts { - public interface IOrderLogic - { - List? ReadList(OrderSearchModel? model); - OrderViewModel? ReadElement(OrderSearchModel model); - bool Create(OrderBindingModel model); - bool Delete(OrderBindingModel model); - bool Update(OrderBindingModel model); - - bool TakeOrderInWork(OrderBindingModel model); - bool FinishOrder(OrderBindingModel model); - bool DeliveryOrder(OrderBindingModel model); - } + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool Create(OrderBindingModel model); + bool Update(OrderBindingModel model); + bool Delete(OrderBindingModel model); + } } diff --git a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IReportLogic.cs b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IReportLogic.cs index 0559561..66aa737 100644 --- a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IReportLogic.cs +++ b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IReportLogic.cs @@ -6,14 +6,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BeautyStudioContracts.BusinessLogicContracts +namespace BeautyStudioContracts.BusinessLogicsContracts { - public interface IReportLogic - { - List GetServices(ReportServiceBindingModel model); - List GetCosmeticProcedures(); - void SaveCosmeticProceduresToExcelFile(ReportBindingModel model); - void SaveCosmeticProceduresToWordFile(ReportBindingModel model); - void SaveServicesToPdfFile(ReportServiceBindingModel model); - } -} + public interface IReportLogic + { + List GetBundligs(ReportBindingModel model); + List GetCars(ReportBindingModel model); + } +} \ No newline at end of file diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs index f715d5f..f3819b9 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/CosmeticSearchModel.cs @@ -9,8 +9,9 @@ namespace BeautyStudioContracts.SearchModels public class CosmeticSearchModel { public int? Id { get; set; } - public string? CosmeticName { get; set; } - public int? LaborCostId { get; set; } + public string CosmeticName { get; set; } = string.Empty; + public DateTime? DateCreate { get; set; } + public DateTime? DateComplete { get; set; } public int? StoreKeeperId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/LaborCostSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/LaborCostSearchModel.cs index 5bd7228..6b5c141 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/LaborCostSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/LaborCostSearchModel.cs @@ -9,8 +9,7 @@ namespace BeautyStudioContracts.SearchModels public class LaborCostSearchModel { public int? Id { get; set; } - public int? TimeSpent { get; set; } - public string? Difficulty { get; set; } public int? StoreKeeperId { get; set; } + public int? ServiceId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/MessageInfoSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/MessageInfoSearchModel.cs deleted file mode 100644 index 50e0809..0000000 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/MessageInfoSearchModel.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.SearchModels -{ - public class MessageInfoSearchModel - { - public int? StorekeeperId { get; set; } - public string? MessageId { get; set; } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs index d17fb62..0735929 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ using BeautyStudioDataModels.Enums; +using BeautyStudioDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -7,17 +8,14 @@ using System.Threading.Tasks; namespace BeautyStudioContracts.SearchModels { - - public class OrderSearchModel - { - public int? Id { get; set; } - public double? Sum { get; set; } - public DateTime? DateCreate { get; set; } - public DateTime? DateComplete { 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; } - } + public class OrderSearchModel + { + public int? Id { get; set; } + public int? ServiceId { get; set; } + public int? StoreKeeperId { get; set; } + public List Procedures { get; set; } = new(); + public List Cosmetics { get; set; } = new(); + public DateTime? DateCreate { get; set; } + public DateTime? DateComplete { get; set; } + } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs index d789b1d..d9d5a94 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/ProcedureSearchModel.cs @@ -9,9 +9,10 @@ namespace BeautyStudioContracts.SearchModels public class ProcedureSearchModel { public int? Id { get; set; } - public string? ProcedureName { get; set; } - public string? ProcedureDescription { get; set; } + public string ProcedureName { get; set; } = string.Empty; + public string ProcedureDescription { get; set; } = string.Empty; public int? StoreKeeperId { get; set; } + public int? ComseticId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs index f99d098..0468895 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/ServiceSearchModel.cs @@ -9,9 +9,9 @@ namespace BeautyStudioContracts.SearchModels public class ServiceSearchModel { public int? Id { get; set; } - public string? ServiceName { get; set; } + public string? ServiceName { get; set; } = string.Empty; public int? StoreKeeperId { get; set; } - public List? CosmeticIds { get; set; } - public List? ProcedureIds { get; set; } + public DateTime? DateCreate { get; set; } + public DateTime? DateComplete { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/SearchModels/StoreKeeperSearchModel.cs b/BeautyStudio/BeautyStudioContracts/SearchModels/StoreKeeperSearchModel.cs index 5d0ceee..6ef729f 100644 --- a/BeautyStudio/BeautyStudioContracts/SearchModels/StoreKeeperSearchModel.cs +++ b/BeautyStudio/BeautyStudioContracts/SearchModels/StoreKeeperSearchModel.cs @@ -9,8 +9,7 @@ namespace BeautyStudioContracts.SearchModels public class StoreKeeperSearchModel { public int? Id { get; set; } - public string? StoreKeeperFIO { get; set;} - public string? StoreKeeperLogin { get; set;} + public string? StoreKeeperLogin { get; set; } public string? StoreKeeperPassword { get; set;} public string? StoreKeeperEmail { get; set;} public string? StoreKeeperPhone { get; set;} diff --git a/BeautyStudio/BeautyStudioContracts/StoragesContracts/ICosmeticStorage.cs b/BeautyStudio/BeautyStudioContracts/StoragesContracts/ICosmeticStorage.cs index fe30cdb..5fe7126 100644 --- a/BeautyStudio/BeautyStudioContracts/StoragesContracts/ICosmeticStorage.cs +++ b/BeautyStudio/BeautyStudioContracts/StoragesContracts/ICosmeticStorage.cs @@ -17,6 +17,5 @@ namespace BeautyStudioContracts.StoragesContracts CosmeticViewModel? Insert(CosmeticBindingModel model); CosmeticViewModel? Update(CosmeticBindingModel model); CosmeticViewModel? Delete(CosmeticBindingModel model); - List GetCosmeticProcedures(CosmeticSearchModel model); } } diff --git a/BeautyStudio/BeautyStudioContracts/StoragesContracts/IMessageInfoStorage.cs b/BeautyStudio/BeautyStudioContracts/StoragesContracts/IMessageInfoStorage.cs deleted file mode 100644 index 16f7c57..0000000 --- a/BeautyStudio/BeautyStudioContracts/StoragesContracts/IMessageInfoStorage.cs +++ /dev/null @@ -1,19 +0,0 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.StoragesContracts -{ - public interface IMessageInfoStorage - { - List GetFullList(); - List GetFilteredList(MessageInfoSearchModel model); - MessageInfoViewModel? GetElement(MessageInfoSearchModel model); - MessageInfoViewModel? Insert(MessageInfoBindingModel model); - } -} diff --git a/BeautyStudio/BeautyStudioContracts/StoragesContracts/IOrderStorage.cs b/BeautyStudio/BeautyStudioContracts/StoragesContracts/IOrderStorage.cs index 2eb6abc..83e404d 100644 --- a/BeautyStudio/BeautyStudioContracts/StoragesContracts/IOrderStorage.cs +++ b/BeautyStudio/BeautyStudioContracts/StoragesContracts/IOrderStorage.cs @@ -9,13 +9,13 @@ using System.Threading.Tasks; namespace BeautyStudioContracts.StoragesContracts { - public interface IOrderStorage - { - List GetFullList(); - List GetFilteredList(OrderSearchModel model); - OrderViewModel? GetElement(OrderSearchModel model); - OrderViewModel? Insert(OrderBindingModel model); - OrderViewModel? Update(OrderBindingModel model); - OrderViewModel? Delete(OrderBindingModel model); - } + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } } diff --git a/BeautyStudio/BeautyStudioContracts/StoragesContracts/IProcedureStorage.cs b/BeautyStudio/BeautyStudioContracts/StoragesContracts/IProcedureStorage.cs index 0d11dd1..e345f10 100644 --- a/BeautyStudio/BeautyStudioContracts/StoragesContracts/IProcedureStorage.cs +++ b/BeautyStudio/BeautyStudioContracts/StoragesContracts/IProcedureStorage.cs @@ -17,6 +17,5 @@ namespace BeautyStudioContracts.StoragesContracts ProcedureViewModel? Insert(ProcedureBindingModel model); ProcedureViewModel? Update(ProcedureBindingModel model); ProcedureViewModel? Delete(ProcedureBindingModel model); - List GetProcedureCosmetics(ProcedureSearchModel model); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticProcedureViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticProcedureViewModel.cs deleted file mode 100644 index 50d805a..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticProcedureViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class CosmeticProcedureViewModel - { - public CosmeticViewModel Cosmetic { get; set; } = null!; - public ProcedureViewModel Procedure { get; set; } = null!; - public int Count { get; set; } - - public CosmeticProcedureViewModel() { } - - public CosmeticProcedureViewModel(CosmeticViewModel cosmetic, ProcedureViewModel procedure, int count) - { - Cosmetic = cosmetic; - Procedure = procedure; - Count = count; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs index d081cbb..853cdbe 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/CosmeticViewModel.cs @@ -18,12 +18,13 @@ namespace BeautyStudioContracts.ViewModels [DisplayName("Цена косметики")] public double CosmeticPrice { get; set; } + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } + public int? OrderId { get; set; } public int LaborCostId { get; set; } public int StoreKeeperId { get; set; } - public string StoreKeeperName { get; set; } = string.Empty; - - public Dictionary CosmeticProcedure { get; set; } = new(); + public Dictionary CosmeticServices { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/LaborCostViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/LaborCostViewModel.cs index 55b6745..7ee42f6 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/LaborCostViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/LaborCostViewModel.cs @@ -1,4 +1,5 @@ -using BeautyStudioDataModels.Models; +using BeautyStudioDataModels.Enums; +using BeautyStudioDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -12,10 +13,10 @@ namespace BeautyStudioContracts.ViewModels { public int Id { get; set; } [DisplayName("Потрачено времени (часов)")] - public int TimeSpent { get; set; } + public TimeSpent TimeSpent { get; set; } [DisplayName("Сложность")] - public string Difficulty { get; set; } = string.Empty; + public Difficulties Difficulty { get; set; } public int StoreKeeperId { get; set; } } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/MessageInfoViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/MessageInfoViewModel.cs deleted file mode 100644 index 72a41a7..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/MessageInfoViewModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using BeautyStudioDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class MessageInfoViewModel : IMessageInfoModel - { - public string MessageId { get; set; } = string.Empty; - - [DisplayName("Отправитель")] - public int? StorekeeperId { get; set; } - - [DisplayName("Получатель")] - public string SenderName { get; set; } = string.Empty; - - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } - - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderCosmeticViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderCosmeticViewModel.cs deleted file mode 100644 index 1141364..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderCosmeticViewModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class OrderCosmeticViewModel - { - public CosmeticViewModel Cosmetic { get; set; } = null!; - - public OrderCosmeticViewModel() { } - - public OrderCosmeticViewModel(CosmeticViewModel cosmetic) - { - Cosmetic = cosmetic; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderProcedureViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderProcedureViewModel.cs deleted file mode 100644 index 2d9d772..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderProcedureViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class OrderProcedureViewModel - { - public ProcedureViewModel Procedure { get; set; } = null!; - public int Count { get; set; } - - public OrderProcedureViewModel() { } - - public OrderProcedureViewModel(ProcedureViewModel procedure, int count) - { - Procedure = procedure; - Count = count; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderServiceViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderServiceViewModel.cs deleted file mode 100644 index 39c25db..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderServiceViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class OrderServiceViewModel - { - public ServiceViewModel Service { get; set; } = null!; - public int Count { get; set; } - - public OrderServiceViewModel() { } - - public OrderServiceViewModel(ServiceViewModel service, int count) - { - Service = service; - Count = count; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs index 3a64ea5..53fffb0 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/OrderViewModel.cs @@ -12,30 +12,16 @@ namespace BeautyStudioContracts.ViewModels public class OrderViewModel : IOrderModel { public int Id { get; set; } - public int CosmeticId { get; set; } - - public int ServiceId { get; set; } - - [DisplayName("Именование услуги")] - public string ServiceName { get; set; } = string.Empty; - - [DisplayName("Стоимость")] - public double Sum { get; set; } - - [DisplayName("Статус")] - public OrderStatus Status { get; set; } - - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } - - [DisplayName("Дата выполнения")] - public DateTime? DateComplete { get; set; } - - [DisplayName("Клиент")] public int StoreKeeperId { get; set; } + [DisplayName("Название заказа")] + public string OrderName { get; set; } = string.Empty; - public Dictionary OrderServices { get; set; } = new(); - public Dictionary OrderCosmetics { get; set; } = new(); - public Dictionary OrderProcedures { get; set; } = new(); + [DisplayName("Дата оплаты")] + public DateTime PaymentDate { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + public Dictionary OrderProcedures { get; set; } = new(); + public Dictionary Cosmetics { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCosmeticsViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCosmeticsViewModel.cs deleted file mode 100644 index 87316ae..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCosmeticsViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class ProcedureCosmeticsViewModel - { - public CosmeticViewModel Cosmetic { get; set; } = null!; - public ProcedureViewModel Procedure { get; set; } = null!; - public int Count { get; set; } - - public ProcedureCosmeticsViewModel() { } - - public ProcedureCosmeticsViewModel(CosmeticViewModel cosmetic, ProcedureViewModel procedure, int count) - { - Cosmetic = cosmetic; - Procedure = procedure; - Count = count; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs index bdabafc..5cb3678 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureViewModel.cs @@ -19,7 +19,6 @@ namespace BeautyStudioContracts.ViewModels [DisplayName("Описание процедуры")] public string ProcedureDescription { get; set; } = string.Empty; public int StoreKeeperId { get; set; } - public string StoreKeeperName { get; set; } = string.Empty; - public Dictionary ProcedureCosmetics { get; set; } = new(); + public Dictionary ProcedureServices { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportCosmeticProceduresViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ReportCosmeticViewModel.cs similarity index 78% rename from BeautyStudio/BeautyStudioContracts/ViewModels/ReportCosmeticProceduresViewModel.cs rename to BeautyStudio/BeautyStudioContracts/ViewModels/ReportCosmeticViewModel.cs index 82eff51..8a716e7 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportCosmeticProceduresViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ReportCosmeticViewModel.cs @@ -6,8 +6,9 @@ using System.Threading.Tasks; namespace BeautyStudioContracts.ViewModels { - public class ReportCosmeticProceduresViewModel + public class ReportCosmeticViewModel { + public int CosmeticID { get; set; } public string CosmeticName { get; set; } = string.Empty; public List Procedures { get; set; } = new(); diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportOrdersViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ReportOrdersViewModel.cs deleted file mode 100644 index 47b050c..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportOrdersViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using BeautyStudioDataModels.Enums; -using BeautyStudioDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class ReportOrdersViewModel - { - public int Id { get; set; } - public DateTime DateCreate { get; set; } - public double OrderAmount { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public Dictionary Cosmetics { get; set; } = new(); - public Dictionary Procedures { get; set; } = new(); - public Dictionary Services { get; set; } = new(); - } -} - diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs deleted file mode 100644 index 6e0c24a..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportProcedureCosmeticsViewModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.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/BeautyStudio/BeautyStudioContracts/ViewModels/ReportServicesViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ReportServicesViewModel.cs index 6f6e4e8..0840134 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ReportServicesViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ReportServicesViewModel.cs @@ -11,10 +11,8 @@ namespace BeautyStudioContracts.ViewModels public class ReportServicesViewModel { public int Id { get; set; } - public string ServiceName { get; set; } = string.Empty; - public Dictionary Cosmetics { get; set; } = new(); - public Dictionary Procedures { get; set; } = new(); - public double ServicePrice { get; set; } + public List Orders { get; set; } = new(); + public List LaborCosts { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceCosmeticViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceCosmeticViewModel.cs deleted file mode 100644 index 63e1aaa..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceCosmeticViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class ServiceCosmeticViewModel - { - public CosmeticViewModel Cosmetic { get; set; } = null!; - public ServiceViewModel Service { get; set; } = null!; - public int Count { get; set; } - - public ServiceCosmeticViewModel() { } - - public ServiceCosmeticViewModel(CosmeticViewModel cosmetic, ServiceViewModel service, int count) - { - Cosmetic = cosmetic; - Service = service; - Count = count; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceProcedureViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceProcedureViewModel.cs deleted file mode 100644 index 8fa1a0c..0000000 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceProcedureViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioContracts.ViewModels -{ - public class ServiceProcedureViewModel - { - public ProcedureViewModel Procedure { get; set; } = null!; - public int Count { get; set; } - - public ServiceProcedureViewModel() { } - - public ServiceProcedureViewModel(ProcedureViewModel procedure, int count) - { - Procedure = procedure; - Count = count; - } - } -} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs index ddf72ec..08fde4a 100644 --- a/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ServiceViewModel.cs @@ -19,8 +19,10 @@ namespace BeautyStudioContracts.ViewModels public double ServicePrice { get; set; } [DisplayName("Сотрудник")] public int StoreKeeperId { get; set; } - - public Dictionary ServiceCosmetics { get; set; } = new(); + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } + public Dictionary ServiceProcedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/StoreKeeprReportViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/StoreKeeprReportViewModel.cs new file mode 100644 index 0000000..9a4c0b6 --- /dev/null +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/StoreKeeprReportViewModel.cs @@ -0,0 +1,16 @@ +using BeautyStudioDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautyStudioContracts.ViewModels +{ + internal class StoreKeeperReportViewModel + { + public int? Id; + public Dictionary ProcedureCosmetics; + public int? Count; + } +} diff --git a/BeautyStudio/BeautyStudioDataModels/Enums/Difficulties.cs b/BeautyStudio/BeautyStudioDataModels/Enums/Difficulties.cs new file mode 100644 index 0000000..460f9c2 --- /dev/null +++ b/BeautyStudio/BeautyStudioDataModels/Enums/Difficulties.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautyStudioDataModels.Enums +{ + public enum Difficulties + { + Неизвестно = -1, + Легко = 0, + Средне = 1, + Тяжело = 2, + } +} diff --git a/BeautyStudio/BeautyStudioDataModels/Enums/TimeSpent.cs b/BeautyStudio/BeautyStudioDataModels/Enums/TimeSpent.cs new file mode 100644 index 0000000..3b4e5bb --- /dev/null +++ b/BeautyStudio/BeautyStudioDataModels/Enums/TimeSpent.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautyStudioDataModels.Enums +{ + public enum TimeSpent + { + Неизвестно = -1, + Полчаса = 0, + Час = 1, + ПолтораЧаса = 2, + ДваЧаса = 3, + ТриЧаса = 4, + ПятьЧасов = 5, + } +} diff --git a/BeautyStudio/BeautyStudioDataModels/Models/ICosmeticModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/ICosmeticModel.cs index 81247a2..801e73c 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/ICosmeticModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/ICosmeticModel.cs @@ -11,6 +11,7 @@ namespace BeautyStudioDataModels.Models string CosmeticName { get; } double CosmeticPrice { get; } int LaborCostId { get; } - Dictionary CosmeticProcedure { get; } + public DateTime DateCreate { get; set; } + Dictionary CosmeticServices { get; } } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/ILaborCostModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/ILaborCostModel.cs index 8a9052f..b3c9e52 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/ILaborCostModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/ILaborCostModel.cs @@ -1,4 +1,5 @@ -using System; +using BeautyStudioDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,8 +9,7 @@ namespace BeautyStudioDataModels.Models { public interface ILaborCostModel : IId { - int TimeSpent { get; } - string Difficulty { get; } - int StoreKeeperId { get; } + TimeSpent TimeSpent { get; } + Difficulties Difficulty { get; } } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IMessageInfoModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IMessageInfoModel.cs deleted file mode 100644 index a3907e1..0000000 --- a/BeautyStudio/BeautyStudioDataModels/Models/IMessageInfoModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioDataModels.Models -{ - public interface IMessageInfoModel - { - string MessageId { get; } - string SenderName { get; } - DateTime DateDelivery { get; } - string Subject { get; } - string Body { get; } - } -} diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs index bb6f08d..425491c 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/IOrderModel.cs @@ -1,22 +1,17 @@ -using System; +using BeautyStudioDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using BeautyStudioDataModels.Enums; namespace BeautyStudioDataModels.Models { - public interface IOrderModel : IId - { - double Sum { get; } - DateTime DateCreate { get; } - DateTime? DateComplete { get; } - OrderStatus Status { get; } - int StoreKeeperId { get; } - Dictionary OrderCosmetics { get; } // список косметики "участвующей" в заказе - Dictionary OrderProcedures { get; } // список процедур "участвующих" в заказе - Dictionary OrderServices { get; } // список услуг "участвующих" в заказе - } - + public interface IOrderModel : IId + { + string OrderName { get; set; } + DateTime PaymentDate { get; set; } + double Sum { get; set; } + Dictionary OrderProcedures { get; } + } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs index ec6a233..7d8c981 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/IProcedureModel.cs @@ -11,7 +11,6 @@ namespace BeautyStudioDataModels.Models string ProcedureName { get; } double ProcedureCost { get; } string ProcedureDescription { get; } - int StoreKeeperId { get; } - Dictionary ProcedureCosmetics { get; } + Dictionary ProcedureServices { get; } } } diff --git a/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs b/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs index 208d90b..e498d81 100644 --- a/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs +++ b/BeautyStudio/BeautyStudioDataModels/Models/IServiceModel.cs @@ -11,8 +11,6 @@ namespace BeautyStudioDataModels.Models { string ServiceName { get; } double ServicePrice { get; } - int StoreKeeperId { get; set; } - Dictionary ServiceCosmetics { get; } - Dictionary ServiceProcedures { get; } + DateTime DateCreate { get; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs index 5babffa..53837a2 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs @@ -16,18 +16,13 @@ namespace BeautyStudioDatabaseImplement } public virtual DbSet Orders { set; get; } - public virtual DbSet LaborCost { set; get; } + public virtual DbSet LaborCosts { set; get; } public virtual DbSet Cosmetics { set; get; } public virtual DbSet Services { set; get; } public virtual DbSet Procedures { set; get; } - public virtual DbSet ServiceCosmetics { set; get; } - public virtual DbSet ServiceProcedures { set; get; } - public virtual DbSet OrderCosmetics { set; get; } - 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 CosmeticServices { set; get; } + public virtual DbSet ProcedureServices { set; get; } public virtual DbSet StoreKeepers { set; get; } - public virtual DbSet MessageInfos { set; get; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs index 416402d..d94c526 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs @@ -4,119 +4,129 @@ using BeautyStudioContracts.StoragesContracts; using BeautyStudioContracts.ViewModels; using BeautyStudioDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Implements { - public class CosmeticStorage : ICosmeticStorage - { - public List GetFullList() - { - 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(); - } - public List GetFilteredList(CosmeticSearchModel model) - { - using var context = new BeautyStudioDatabase(); - if (model.Id.HasValue) - { - return context.Cosmetics - .Include(x => x.StoreKeeper) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - if (model.StoreKeeperId.HasValue) - { - return context.Cosmetics - .Include(x => x.StoreKeeper) - .Where(x => x.StoreKeeperId == model.StoreKeeperId) - .Select(x => x.GetViewModel) - .ToList(); - } - - return new(); - } - - public CosmeticViewModel? GetElement(CosmeticSearchModel model) - { - if (string.IsNullOrEmpty(model.CosmeticName) && !model.Id.HasValue) - { - return null; - } - using var context = new BeautyStudioDatabase(); - return context.Cosmetics - .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) - { - using var context = new BeautyStudioDatabase(); - var newCosmetic = Cosmetic.Create(context, model); - if (newCosmetic == null) - { - return null; - } - - context.Cosmetics.Add(newCosmetic); - context.SaveChanges(); - return newCosmetic.GetViewModel; - } - - public CosmeticViewModel? Update(CosmeticBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var element = context.Cosmetics - .Include(x => x.LaborCost) - .FirstOrDefault(x => x.Id.Equals(model.Id)); - if (element == null) - { - return null; - } - - element.Update(context, model); - context.SaveChanges(); - return element.GetViewModel; - } - - public CosmeticViewModel? Delete(CosmeticBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var element = context.Cosmetics - .Include(x => x.LaborCost) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Cosmetics.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - public List GetCosmeticProcedures(CosmeticSearchModel model) - { - if (model == null) - { - return new(); - } - using var context = new BeautyStudioDatabase(); - var procedures = context.CosmeticProcedures - .Where(x => x.CosmeticId == model.Id) - .Select(x => x.Procedure.GetViewModel) - .ToList(); - return procedures; - } - } + public class CosmeticStorage : ICosmeticStorage + { + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.Cosmetics + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.LaborCost) + .Include(x => x.Order) + .Include(x => x.StoreKeeper) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(CosmeticSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (model.DateCreate.HasValue) // Для отчета списка + { + //будет применятся в ReportLogic + return context.Cosmetics + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Where(x => x.DateCreate <= model.DateComplete && x.DateCreate >= model.DateCreate) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.StoreKeeperId.HasValue) + { + return context.Cosmetics + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.LaborCost) + .Include(x => x.Order) + .Include(x => x.StoreKeeper) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + public CosmeticViewModel? GetElement(CosmeticSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (!model.Id.HasValue) + { + return null; + } + return context.Cosmetics + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.LaborCost) + .Include(x => x.Order) + .Include(x => x.StoreKeeper) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + public CosmeticViewModel? Insert(CosmeticBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var newCosm = Cosmetic.Create(context, model); + if (newCosm == null) + { + return null; + } + context.Cosmetics.Add(newCosm); + context.SaveChanges(); + return context.Cosmetics + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.LaborCost) + .Include(x => x.Order) + .Include(x => x.StoreKeeper) + .FirstOrDefault(x => x.Id == newCosm.Id) + ?.GetViewModel; + } + public CosmeticViewModel? Update(CosmeticBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var cosm = context.Cosmetics.FirstOrDefault(x => x.Id == model.Id); + if (cosm == null) + { + return null; + } + cosm.Update(model); + cosm.UpdateServices(context, model); + context.SaveChanges(); + return context.Cosmetics + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.LaborCost) + .Include(x => x.Order) + .Include(x => x.StoreKeeper) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public CosmeticViewModel? Delete(CosmeticBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var element = context.Cosmetics + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Cosmetics + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.LaborCost) + .Include(x => x.Order) + .Include(x => x.StoreKeeper) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Cosmetics.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs index 66568ba..a584577 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/LaborCostStorage.cs @@ -3,110 +3,90 @@ using BeautyStudioContracts.SearchModels; using BeautyStudioContracts.StoragesContracts; using BeautyStudioContracts.ViewModels; using BeautyStudioDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Implements { - public class LaborCostStorage : ILaborCostStorage - { - 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 deletedElement; - } - return null; - } - - public LaborCostViewModel? GetElement(LaborCostSearchModel model) - { - if (!model.Id.HasValue) - { - 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; - } - } - - public List GetFilteredList(LaborCostSearchModel model) - { - using var context = new BeautyStudioDatabase(); - if (model.Id.HasValue) - { - return context.LaborCost - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - if (model.StoreKeeperId.HasValue) - { - return context.LaborCost - .Where(x => x.StoreKeeperId == model.StoreKeeperId) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); - } - - public List GetFullList() - { - using var context = new BeautyStudioDatabase(); - return context.LaborCost - .Select(x => x.GetViewModel) - .ToList(); - } - - public LaborCostViewModel? Insert(LaborCostBindingModel model) - { - var newLaborCost = LaborCost.Create(model); - if (newLaborCost == null) - { - return null; - } - using var context = new BeautyStudioDatabase(); - context.LaborCost.Add(newLaborCost); - context.SaveChanges(); - return context.LaborCost - .FirstOrDefault(x => x.Id == newLaborCost.Id) - ?.GetViewModel; - } - - public LaborCostViewModel? Update(LaborCostBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var order = context.LaborCost.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - return context.LaborCost - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; - } - } + public class LaborCostStorage : ILaborCostStorage + { + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.LaborCosts + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(LaborCostSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (model.StoreKeeperId.HasValue) + { + return context.LaborCosts + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + public LaborCostViewModel? GetElement(LaborCostSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (!model.Id.HasValue) + { + return null; + } + return context.LaborCosts + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + public LaborCostViewModel? Insert(LaborCostBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var newFeature = LaborCost.Create(model); + if (newFeature == null) + { + return null; + } + context.LaborCosts.Add(newFeature); + context.SaveChanges(); + return context.LaborCosts + .FirstOrDefault(x => x.Id == newFeature.Id) + ?.GetViewModel; + } + public LaborCostViewModel? Update(LaborCostBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var order = context.LaborCosts.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.LaborCosts + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public LaborCostViewModel? Delete(LaborCostBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var element = context.LaborCosts + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.LaborCosts + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.LaborCosts.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/MessageInfoStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/MessageInfoStorage.cs deleted file mode 100644 index 285a194..0000000 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/MessageInfoStorage.cs +++ /dev/null @@ -1,58 +0,0 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.StoragesContracts; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioDatabaseImplement.Implements -{ - public class MessageInfoStorage : IMessageInfoStorage - { - public List GetFullList() - { - using var context = new BeautyStudioDatabase(); - return context.MessageInfos.Select(x => x.GetViewModel).ToList(); - } - public List GetFilteredList(MessageInfoSearchModel model) - { - if (!model.StorekeeperId.HasValue) - { - return new List(); - } - - using var context = new BeautyStudioDatabase(); - - return context.MessageInfos - .Where(x => x.StorekeeperId == model.StorekeeperId && x.StorekeeperId == model.StorekeeperId) - .Select(x => x.GetViewModel) - .ToList(); - } - - public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) - { - if (string.IsNullOrEmpty(model.MessageId)) - { - return new(); - } - using var context = new BeautyStudioDatabase(); - return context.MessageInfos.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; - } - public MessageInfoViewModel? Insert(MessageInfoBindingModel model) - { - var newMessage = MessageInfo.Create(model); - if (newMessage == null) - { - return null; - } - using var context = new BeautyStudioDatabase(); - context.MessageInfos.Add(newMessage); - context.SaveChanges(); - return newMessage.GetViewModel; - } - } -} \ No newline at end of file diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs index 3dc7fe6..404eb8e 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/OrderStorage.cs @@ -12,132 +12,150 @@ using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Implements { - public class OrderStorage : IOrderStorage - { - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new BeautyStudioDatabase(); - 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 class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var element = context.Orders + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Orders + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Orders.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new BeautyStudioDatabase(); - 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? GetElement(OrderSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (!model.Id.HasValue) + { + return null; + } + return context.Orders + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } - public List GetFilteredList(OrderSearchModel model) - { - if (model == null) - { - return new(); - } - using var context = new BeautyStudioDatabase(); - 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) - .ThenInclude(x => x.Cosmetic) - .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(); - } - return new(); - } + public List GetFilteredList(OrderSearchModel model) + { + using var context = new BeautyStudioDatabase(); - public List GetFullList() - { - using var context = new BeautyStudioDatabase(); - 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) - .Select(x => x.GetViewModel) - .ToList(); - } + if (model.DateCreate.HasValue && model.DateComplete.HasValue) + { + return context.Orders + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .ThenInclude(x => x.Services) + .ThenInclude(x => x.Service) + .Where(x => x.PaymentDate >= model.DateCreate && x.PaymentDate <= model.DateComplete) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Procedures.Count > 0) + { + return context.Orders + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Where(x => x.OrderProcedures.Any(p => model.Procedures.Any(procedure => p.Value == procedure))) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Cosmetics.Count > 0) + { + return context.Orders + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Where(x => x.Cosmetics.Any(car => model.Cosmetics.Any(searchCosm => car.Id == searchCosm.Id))) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.StoreKeeperId.HasValue) + { + return context.Orders + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } - public OrderViewModel? Insert(OrderBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var newOrder = Order.Create(context, model); - if (newOrder == null) - { - return null; - } - context.Orders.Add(newOrder); - context.SaveChanges(); - return newOrder.GetViewModel; - } + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.Orders + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Select(x => x.GetViewModel) + .ToList(); + } - public OrderViewModel? Update(OrderBindingModel model) - { - using var context = new BeautyStudioDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - order.UpdateCosmetics(context, model); - order.UpdateProcedures(context, model); - order.UpdateServices(context, model); - transaction.Commit(); - return order.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; - } - } - } + public OrderViewModel? Insert(OrderBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var newOrder = Order.Create(context, model); + if (newOrder == null) + { + return null; + } + context.Orders.Add(newOrder); + context.SaveChanges(); + return context.Orders + .Include(x => x.StoreKeeper) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => x.Id == newOrder.Id) + ?.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.Orders + .Include(x => x.StoreKeeper) + .Include(x => x.Cosmetics) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs index ea42875..4cfedec 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs @@ -12,115 +12,99 @@ using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Implements { - public class ProcedureStorage : IProcedureStorage - { - public List GetFullList() - { - using var context = new BeautyStudioDatabase(); - return context.Procedures - .Include(x => x.StoreKeeper) - .Include(x => x.Cosmetics) - .ThenInclude(x => x.Cosmetic) - .Select(x => x.GetViewModel) - .ToList(); - } + public class ProcedureStorage : IProcedureStorage + { + public ProcedureViewModel? Delete(ProcedureBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var element = context.Procedures + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Procedures + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Procedures.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } - 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(); - } + public ProcedureViewModel? GetElement(ProcedureSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (!model.Id.HasValue) + { + return null; + } + return context.Procedures + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } - return new(); - } + public List GetFilteredList(ProcedureSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (model.StoreKeeperId.HasValue) + { + return context.Procedures + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Where(x => x.StoreKeeperId == model.StoreKeeperId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.Procedures + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Select(x => x.GetViewModel) + .ToList(); + } - public ProcedureViewModel? GetElement(ProcedureSearchModel model) - { - if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue) - { - return null; - } - using var context = new BeautyStudioDatabase(); - return context.Procedures - .Include(x => x.Cosmetics) - .ThenInclude(x => x.Cosmetic) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProcedureName) && x.ProcedureName == model.ProcedureName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } + public ProcedureViewModel? Insert(ProcedureBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var newProcedure = Procedure.Create(context, model); + if (newProcedure == null) + { + return null; + } + context.Procedures.Add(newProcedure); + context.SaveChanges(); + return context.Procedures + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .FirstOrDefault(x => x.Id == newProcedure.Id) + ?.GetViewModel; + } - public ProcedureViewModel? Insert(ProcedureBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var newProcedure = Procedure.Create(context, model); - if (newProcedure == null) - { - return null; - } - - context.Procedures.Add(newProcedure); - context.SaveChanges(); - return newProcedure.GetViewModel; - } - - - public ProcedureViewModel? Update(ProcedureBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var element = context.Procedures - .FirstOrDefault(x => x.Id.Equals(model.Id)); - if (element == null) - { - 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(); - return element.GetViewModel; - } - return null; - } - - public List GetProcedureCosmetics(ProcedureSearchModel model) - { - if (model == null) - { - return new(); - } - using var context = new BeautyStudioDatabase(); - var cosmetics = context.ProcedureCosmetics - .Where(x => x.ProcedureId == model.Id) - .Select(x => x.Cosmetic.GetViewModel) - .ToList(); - return cosmetics; - } - - } + public ProcedureViewModel? Update(ProcedureBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var proc = context.Procedures.FirstOrDefault(x => x.Id == model.Id); + if (proc == null) + { + return null; + } + proc.Update(model); + proc.UpdateServices(context, model); + context.SaveChanges(); + return context.Procedures + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs index 17bcca9..fa4e1e6 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ServiceStorage.cs @@ -3,7 +3,6 @@ using BeautyStudioContracts.SearchModels; using BeautyStudioContracts.StoragesContracts; using BeautyStudioContracts.ViewModels; using BeautyStudioDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -12,123 +11,81 @@ using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Implements { - public class ServiceStorage : IServiceStorage - { - public ServiceViewModel? Delete(ServiceBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var element = context.Services - .Include(x => x.Procedures) - .Include(x => x.Cosmetics) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Services.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - public ServiceViewModel? GetElement(ServiceSearchModel model) - { - if (string.IsNullOrEmpty(model.ServiceName) && !model.Id.HasValue) - { - return null; - } - using var context = new BeautyStudioDatabase(); - return context.Services - .Include(x => x.Procedures) - .ThenInclude(x => x.Procedure) - .Include(x => x.Cosmetics) - .ThenInclude(x => x.Cosmetic) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) && x.ServiceName == model.ServiceName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public List GetFilteredList(ServiceSearchModel model) - { - if (model == null) - { - return new(); - } - using var context = new BeautyStudioDatabase(); - if (model.Id.HasValue) - { - return context.Services - .Include(x => x.Procedures) - .ThenInclude(x => x.Procedure) - .Include(x => x.Cosmetics) - .ThenInclude(x => x.Cosmetic) - .Where(x => x.Id == model.Id) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - if (model.StoreKeeperId.HasValue) - { - return context.Services - .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(); - } - return new(); - } - - public List GetFullList() - { - using var context = new BeautyStudioDatabase(); - return context.Services - .Include(x => x.Procedures) - .ThenInclude(x => x.Procedure) - .Include(x => x.Cosmetics) - .ThenInclude(x => x.Cosmetic) - .Select(x => x.GetViewModel) - .ToList(); - } - - public ServiceViewModel? Insert(ServiceBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var newService = Service.Create(context, model); - if (newService == null) - { - return null; - } - context.Services.Add(newService); - context.SaveChanges(); - return newService.GetViewModel; - } - - public ServiceViewModel? Update(ServiceBindingModel model) - { - using var context = new BeautyStudioDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - var service = context.Services.FirstOrDefault(rec => rec.Id == model.Id); - if (service == null) - { - return null; - } - service.Update(model); - context.SaveChanges(); - service.UpdateCosmetics(context, model); - service.UpdateProcedures(context, model); - transaction.Commit(); - return service.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; - } - } - } + public class ServiceStorage : IServiceStorage + { + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.Services + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ServiceSearchModel model) + { + if (!model.StoreKeeperId.HasValue && !model.DateCreate.HasValue && !model.DateComplete.HasValue) + { + return new(); + } + using var context = new BeautyStudioDatabase(); + if (model.DateCreate.HasValue) + return context.Services.Where(x => x.StoreKeeperId == model.StoreKeeperId).Where(x => x.DateCreate <= model.DateComplete && x.DateCreate >= model.DateCreate).Select(x => x.GetViewModel).ToList(); + else + return context.Services.Where(x => x.StoreKeeperId == model.StoreKeeperId).Select(x => x.GetViewModel).ToList(); + } + public ServiceViewModel? GetElement(ServiceSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (!model.Id.HasValue) + { + return null; + } + return context.Services + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + public ServiceViewModel? Insert(ServiceBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var newBundling = Service.Create(model); + if (newBundling == null) + { + return null; + } + context.Services.Add(newBundling); + context.SaveChanges(); + return context.Services + .FirstOrDefault(x => x.Id == newBundling.Id) + ?.GetViewModel; + } + public ServiceViewModel? Update(ServiceBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var order = context.Services.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.Services + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public ServiceViewModel? Delete(ServiceBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var element = context.Services + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Services + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Services.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs index 1483e77..340c8ec 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs @@ -1,118 +1,94 @@ -using System; +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 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(); - } + public class StoreKeeperStorage : IStoreKeeperStorage + { + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.StoreKeepers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(StoreKeeperSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new BeautyStudioDatabase(); + if (model.Id.HasValue) + { + return context.StoreKeepers.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } + } - // Фильтрация по логину - if (!string.IsNullOrEmpty(model.StoreKeeperLogin)) - { - return context.StoreKeepers - .Where(x => x.StoreKeeperLogin.Contains(model.StoreKeeperLogin)) - .Select(x => x.GetViewModel) - .ToList(); - } + public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (!model.Id.HasValue && string.IsNullOrEmpty(model.StoreKeeperEmail)) { return null; } + return context.StoreKeepers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) + || (!string.IsNullOrEmpty(model.StoreKeeperEmail) && !string.IsNullOrEmpty(model.StoreKeeperPassword) && x.StoreKeeperEmail.Equals(model.StoreKeeperEmail) && x.StoreKeeperPassword.Equals(model.StoreKeeperPassword)))?.GetViewModel; + } - 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; - } + public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var res = context.StoreKeepers + .FirstOrDefault(x => x.Id == model.Id); - //// Поиск по логину - if (!string.IsNullOrEmpty(model.StoreKeeperLogin)) - { - return context.StoreKeepers - .FirstOrDefault(x => x.StoreKeeperLogin.Equals(model.StoreKeeperLogin)) - ?.GetViewModel; - } + if (res != null) + { + context.StoreKeepers.Remove(res); + context.SaveChanges(); + } - return null; - } - public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var newStoreKeeper = StoreKeeper.Create(model); - if (newStoreKeeper == null) - { - return null; - } + return res?.GetViewModel; + } - context.StoreKeepers.Add(newStoreKeeper); - context.SaveChanges(); - return newStoreKeeper.GetViewModel; - } - public StoreKeeperViewModel? Update(StoreKeeperBindingModel model) - { - using var context = new BeautyStudioDatabase(); - var storekeeper = context.StoreKeepers - .FirstOrDefault(x => x.Id.Equals(model.Id)); - if (storekeeper == null) - { - return null; - } + public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + var res = StoreKeeper.Create(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; - } + if (res != null) + { + context.StoreKeepers.Add(res); + context.SaveChanges(); + } - context.StoreKeepers.Remove(storekeeper); - context.SaveChanges(); - return storekeeper.GetViewModel; - } - } + return res?.GetViewModel; + } + + public StoreKeeperViewModel? Update(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + + var res = context.StoreKeepers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240829021006_Mig.Designer.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240909181355_InitialMig.Designer.cs similarity index 57% rename from BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240829021006_Mig.Designer.cs rename to BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240909181355_InitialMig.Designer.cs index 2f4b919..2326376 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240829021006_Mig.Designer.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240909181355_InitialMig.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BeautyStudioDatabaseImplement.Migrations { [DbContext(typeof(BeautyStudioDatabase))] - [Migration("20240829021006_Mig")] - partial class Mig + [Migration("20240909181355_InitialMig")] + partial class InitialMig { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -40,9 +40,15 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("CosmeticPrice") .HasColumnType("double precision"); + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + b.Property("LaborCostId") .HasColumnType("integer"); + b.Property("OrderId") + .HasColumnType("integer"); + b.Property("StoreKeeperId") .HasColumnType("integer"); @@ -50,12 +56,14 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasIndex("LaborCostId"); + b.HasIndex("OrderId"); + b.HasIndex("StoreKeeperId"); b.ToTable("Cosmetics"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticProcedure", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticServices", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -66,19 +74,16 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("CosmeticId") .HasColumnType("integer"); - b.Property("ProcedureCosmeticCount") - .HasColumnType("integer"); - - b.Property("ProcedureId") + b.Property("ServiceId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("CosmeticId"); - b.HasIndex("ProcedureId"); + b.HasIndex("ServiceId"); - b.ToTable("CosmeticProcedures"); + b.ToTable("CosmeticServices"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b => @@ -89,9 +94,8 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Difficulty") - .IsRequired() - .HasColumnType("text"); + b.Property("Difficulty") + .HasColumnType("integer"); b.Property("StoreKeeperId") .HasColumnType("integer"); @@ -101,39 +105,7 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("StoreKeeperId"); - - 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"); + b.ToTable("LaborCosts"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => @@ -144,15 +116,13 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("DateComplete") - .HasColumnType("timestamp with time zone"); + b.Property("OrderName") + .IsRequired() + .HasColumnType("text"); - b.Property("DateCreate") + b.Property("PaymentDate") .HasColumnType("timestamp with time zone"); - b.Property("Status") - .HasColumnType("integer"); - b.Property("StoreKeeperId") .HasColumnType("integer"); @@ -166,32 +136,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.ToTable("Orders"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderCosmetic", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("CosmeticId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("OrderId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("CosmeticId"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderCosmetics"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderProcedure", b => { b.Property("Id") @@ -203,9 +147,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("OrderId") .HasColumnType("integer"); - b.Property("OrderProcedureCount") - .HasColumnType("integer"); - b.Property("ProcedureId") .HasColumnType("integer"); @@ -218,32 +159,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.ToTable("OrderProcedures"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("OrderId") - .HasColumnType("integer"); - - b.Property("OrderServiceCount") - .HasColumnType("integer"); - - b.Property("ServiceId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.HasIndex("ServiceId"); - - b.ToTable("OrderServices"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => { b.Property("Id") @@ -268,12 +183,10 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("StoreKeeperId"); - b.ToTable("Procedures"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetic", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureServices", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -281,22 +194,22 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("CosmeticId") - .HasColumnType("integer"); - b.Property("Count") .HasColumnType("integer"); b.Property("ProcedureId") .HasColumnType("integer"); - b.HasKey("Id"); + b.Property("ServiceId") + .HasColumnType("integer"); - b.HasIndex("CosmeticId"); + b.HasKey("Id"); b.HasIndex("ProcedureId"); - b.ToTable("ProcedureCosmetics"); + b.HasIndex("ServiceId"); + + b.ToTable("ProcedureServices"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => @@ -307,6 +220,9 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + b.Property("ServiceName") .IsRequired() .HasColumnType("text"); @@ -319,63 +235,9 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("StoreKeeperId"); - b.ToTable("Services"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceCosmetic", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("CosmeticId") - .HasColumnType("integer"); - - b.Property("ServiceCosmeticCount") - .HasColumnType("integer"); - - b.Property("ServiceId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("CosmeticId"); - - b.HasIndex("ServiceId"); - - b.ToTable("ServiceCosmetics"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ProcedureId") - .HasColumnType("integer"); - - b.Property("ServiceId") - .HasColumnType("integer"); - - b.Property("ServiceProcedureCount") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ProcedureId"); - - b.HasIndex("ServiceId"); - - b.ToTable("ServiceProcedures"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b => { b.Property("Id") @@ -417,54 +279,40 @@ namespace BeautyStudioDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") + .WithMany("Cosmetics") + .HasForeignKey("OrderId"); + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") - .WithMany() + .WithMany("Cosmetics") .HasForeignKey("StoreKeeperId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("LaborCost"); + b.Navigation("Order"); + b.Navigation("StoreKeeper"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticProcedure", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticServices", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany("Procedures") + .WithMany("Services") .HasForeignKey("CosmeticId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Cosmetics") - .HasForeignKey("ProcedureId") + b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") + .WithMany("CosmeticServices") + .HasForeignKey("ServiceId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Cosmetic"); - b.Navigation("Procedure"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") - .WithMany() - .HasForeignKey("StoreKeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("StoreKeeper"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.MessageInfo", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "Storekeeper") - .WithMany() - .HasForeignKey("StorekeeperId"); - - b.Navigation("Storekeeper"); + b.Navigation("Service"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => @@ -478,25 +326,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("StoreKeeper"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderCosmetic", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany() - .HasForeignKey("CosmeticId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") - .WithMany("Cosmetics") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Cosmetic"); - - b.Navigation("Order"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderProcedure", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") @@ -506,7 +335,7 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany() + .WithMany("OrderProcedures") .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -516,95 +345,16 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("Procedure"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureServices", b => { - b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") + b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") .WithMany("Services") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany() - .HasForeignKey("ServiceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - - 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") - .WithMany() - .HasForeignKey("StoreKeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("StoreKeeper"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceCosmetic", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany() - .HasForeignKey("CosmeticId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany("Cosmetics") - .HasForeignKey("ServiceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Cosmetic"); - - b.Navigation("Service"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany("Procedures") + .WithMany("ProcedureServices") .HasForeignKey("ServiceId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -616,7 +366,7 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b => { - b.Navigation("Procedures"); + b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b => @@ -629,20 +379,25 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("Cosmetics"); b.Navigation("Procedures"); - - b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => { - b.Navigation("Cosmetics"); + b.Navigation("OrderProcedures"); + + b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { - b.Navigation("Cosmetics"); + b.Navigation("CosmeticServices"); - b.Navigation("Procedures"); + b.Navigation("ProcedureServices"); + }); + + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b => + { + b.Navigation("Cosmetics"); }); #pragma warning restore 612, 618 } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240829021006_Mig.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240909181355_InitialMig.cs similarity index 50% rename from BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240829021006_Mig.cs rename to BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240909181355_InitialMig.cs index 0ed403f..3c30e07 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240829021006_Mig.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/20240909181355_InitialMig.cs @@ -7,11 +7,58 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BeautyStudioDatabaseImplement.Migrations { /// - public partial class Mig : Migration + public partial class InitialMig : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "LaborCosts", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TimeSpent = table.Column(type: "integer", nullable: false), + Difficulty = table.Column(type: "integer", nullable: false), + StoreKeeperId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LaborCosts", 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), + StoreKeeperId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Procedures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Services", + 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), + ServiceName = table.Column(type: "text", nullable: false), + ServicePrice = table.Column(type: "double precision", nullable: false), + StoreKeeperId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Services", x => x.Id); + }); + migrationBuilder.CreateTable( name: "StoreKeepers", columns: table => new @@ -30,45 +77,30 @@ namespace BeautyStudioDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "LaborCost", + name: "ProcedureServices", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - TimeSpent = table.Column(type: "integer", nullable: false), - Difficulty = table.Column(type: "text", nullable: false), - StoreKeeperId = table.Column(type: "integer", nullable: false) + ProcedureId = table.Column(type: "integer", nullable: false), + ServiceId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_LaborCost", x => x.Id); + table.PrimaryKey("PK_ProcedureServices", x => x.Id); table.ForeignKey( - name: "FK_LaborCost_StoreKeepers_StoreKeeperId", - column: x => x.StoreKeeperId, - principalTable: "StoreKeepers", + name: "FK_ProcedureServices_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", principalColumn: "Id", 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"); + name: "FK_ProcedureServices_Services_ServiceId", + column: x => x.ServiceId, + principalTable: "Services", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -77,11 +109,10 @@ namespace BeautyStudioDatabaseImplement.Migrations { 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) + StoreKeeperId = table.Column(type: "integer", nullable: false), + OrderName = table.Column(type: "text", nullable: false), + PaymentDate = table.Column(type: "timestamp with time zone", nullable: false), + Sum = table.Column(type: "double precision", nullable: false) }, constraints: table => { @@ -94,69 +125,33 @@ namespace BeautyStudioDatabaseImplement.Migrations 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 - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ServiceName = table.Column(type: "text", nullable: false), - ServicePrice = table.Column(type: "double precision", nullable: false), - StoreKeeperId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Services", x => x.Id); - table.ForeignKey( - name: "FK_Services_StoreKeepers_StoreKeeperId", - column: x => x.StoreKeeperId, - principalTable: "StoreKeepers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "Cosmetics", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OrderId = table.Column(type: "integer", nullable: true), CosmeticName = table.Column(type: "text", nullable: false), CosmeticPrice = table.Column(type: "double precision", nullable: false), StoreKeeperId = table.Column(type: "integer", nullable: false), - LaborCostId = table.Column(type: "integer", nullable: false) + LaborCostId = table.Column(type: "integer", nullable: false), + DateCreate = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Cosmetics", x => x.Id); table.ForeignKey( - name: "FK_Cosmetics_LaborCost_LaborCostId", + name: "FK_Cosmetics_LaborCosts_LaborCostId", column: x => x.LaborCostId, - principalTable: "LaborCost", + principalTable: "LaborCosts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Cosmetics_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id"); table.ForeignKey( name: "FK_Cosmetics_StoreKeepers_StoreKeeperId", column: x => x.StoreKeeperId, @@ -172,8 +167,7 @@ namespace BeautyStudioDatabaseImplement.Migrations 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) + ProcedureId = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -193,206 +187,55 @@ namespace BeautyStudioDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "OrderServices", + name: "CosmeticServices", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - OrderId = table.Column(type: "integer", nullable: false), - ServiceId = table.Column(type: "integer", nullable: false), - OrderServiceCount = table.Column(type: "integer", nullable: false) + CosmeticId = table.Column(type: "integer", nullable: false), + ServiceId = table.Column(type: "integer", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_OrderServices", x => x.Id); + table.PrimaryKey("PK_CosmeticServices", x => x.Id); table.ForeignKey( - name: "FK_OrderServices_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", + name: "FK_CosmeticServices_Cosmetics_CosmeticId", + column: x => x.CosmeticId, + principalTable: "Cosmetics", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_OrderServices_Services_ServiceId", + name: "FK_CosmeticServices_Services_ServiceId", column: x => x.ServiceId, principalTable: "Services", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "ServiceProcedures", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ServiceId = table.Column(type: "integer", nullable: false), - ProcedureId = table.Column(type: "integer", nullable: false), - ServiceProcedureCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ServiceProcedures", x => x.Id); - table.ForeignKey( - name: "FK_ServiceProcedures_Procedures_ProcedureId", - column: x => x.ProcedureId, - principalTable: "Procedures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ServiceProcedures_Services_ServiceId", - column: x => x.ServiceId, - principalTable: "Services", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "CosmeticProcedures", - 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), - ProcedureCosmeticCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CosmeticProcedures", x => x.Id); - table.ForeignKey( - name: "FK_CosmeticProcedures_Cosmetics_CosmeticId", - column: x => x.CosmeticId, - principalTable: "Cosmetics", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_CosmeticProcedures_Procedures_ProcedureId", - column: x => x.ProcedureId, - principalTable: "Procedures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "OrderCosmetics", - columns: table => new - { - 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), - Count = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderCosmetics", x => x.Id); - table.ForeignKey( - name: "FK_OrderCosmetics_Cosmetics_CosmeticId", - column: x => x.CosmeticId, - principalTable: "Cosmetics", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrderCosmetics_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - 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 - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - CosmeticId = table.Column(type: "integer", nullable: false), - ServiceId = table.Column(type: "integer", nullable: false), - ServiceCosmeticCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ServiceCosmetics", x => x.Id); - table.ForeignKey( - name: "FK_ServiceCosmetics_Cosmetics_CosmeticId", - column: x => x.CosmeticId, - principalTable: "Cosmetics", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ServiceCosmetics_Services_ServiceId", - column: x => x.ServiceId, - principalTable: "Services", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_CosmeticProcedures_CosmeticId", - table: "CosmeticProcedures", - column: "CosmeticId"); - - migrationBuilder.CreateIndex( - name: "IX_CosmeticProcedures_ProcedureId", - table: "CosmeticProcedures", - column: "ProcedureId"); - migrationBuilder.CreateIndex( name: "IX_Cosmetics_LaborCostId", table: "Cosmetics", column: "LaborCostId"); + migrationBuilder.CreateIndex( + name: "IX_Cosmetics_OrderId", + table: "Cosmetics", + column: "OrderId"); + migrationBuilder.CreateIndex( name: "IX_Cosmetics_StoreKeeperId", table: "Cosmetics", column: "StoreKeeperId"); migrationBuilder.CreateIndex( - name: "IX_LaborCost_StoreKeeperId", - table: "LaborCost", - column: "StoreKeeperId"); - - migrationBuilder.CreateIndex( - name: "IX_MessageInfos_StorekeeperId", - table: "MessageInfos", - column: "StorekeeperId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderCosmetics_CosmeticId", - table: "OrderCosmetics", + name: "IX_CosmeticServices_CosmeticId", + table: "CosmeticServices", column: "CosmeticId"); migrationBuilder.CreateIndex( - name: "IX_OrderCosmetics_OrderId", - table: "OrderCosmetics", - column: "OrderId"); + name: "IX_CosmeticServices_ServiceId", + table: "CosmeticServices", + column: "ServiceId"); migrationBuilder.CreateIndex( name: "IX_OrderProcedures_OrderId", @@ -410,85 +253,27 @@ namespace BeautyStudioDatabaseImplement.Migrations column: "StoreKeeperId"); migrationBuilder.CreateIndex( - name: "IX_OrderServices_OrderId", - table: "OrderServices", - column: "OrderId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderServices_ServiceId", - table: "OrderServices", - column: "ServiceId"); - - migrationBuilder.CreateIndex( - name: "IX_ProcedureCosmetics_CosmeticId", - table: "ProcedureCosmetics", - column: "CosmeticId"); - - migrationBuilder.CreateIndex( - name: "IX_ProcedureCosmetics_ProcedureId", - table: "ProcedureCosmetics", + name: "IX_ProcedureServices_ProcedureId", + table: "ProcedureServices", column: "ProcedureId"); migrationBuilder.CreateIndex( - name: "IX_Procedures_StoreKeeperId", - table: "Procedures", - column: "StoreKeeperId"); - - migrationBuilder.CreateIndex( - name: "IX_ServiceCosmetics_CosmeticId", - table: "ServiceCosmetics", - column: "CosmeticId"); - - migrationBuilder.CreateIndex( - name: "IX_ServiceCosmetics_ServiceId", - table: "ServiceCosmetics", + name: "IX_ProcedureServices_ServiceId", + table: "ProcedureServices", column: "ServiceId"); - - migrationBuilder.CreateIndex( - name: "IX_ServiceProcedures_ProcedureId", - table: "ServiceProcedures", - column: "ProcedureId"); - - migrationBuilder.CreateIndex( - name: "IX_ServiceProcedures_ServiceId", - table: "ServiceProcedures", - column: "ServiceId"); - - migrationBuilder.CreateIndex( - name: "IX_Services_StoreKeeperId", - table: "Services", - column: "StoreKeeperId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "CosmeticProcedures"); - - migrationBuilder.DropTable( - name: "MessageInfos"); - - migrationBuilder.DropTable( - name: "OrderCosmetics"); + name: "CosmeticServices"); migrationBuilder.DropTable( name: "OrderProcedures"); migrationBuilder.DropTable( - name: "OrderServices"); - - migrationBuilder.DropTable( - name: "ProcedureCosmetics"); - - migrationBuilder.DropTable( - name: "ServiceCosmetics"); - - migrationBuilder.DropTable( - name: "ServiceProcedures"); - - migrationBuilder.DropTable( - name: "Orders"); + name: "ProcedureServices"); migrationBuilder.DropTable( name: "Cosmetics"); @@ -500,7 +285,10 @@ namespace BeautyStudioDatabaseImplement.Migrations name: "Services"); migrationBuilder.DropTable( - name: "LaborCost"); + name: "LaborCosts"); + + migrationBuilder.DropTable( + name: "Orders"); migrationBuilder.DropTable( name: "StoreKeepers"); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs index 5441932..61ccbcf 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Migrations/BeautyStudioDatabaseModelSnapshot.cs @@ -37,9 +37,15 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("CosmeticPrice") .HasColumnType("double precision"); + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + b.Property("LaborCostId") .HasColumnType("integer"); + b.Property("OrderId") + .HasColumnType("integer"); + b.Property("StoreKeeperId") .HasColumnType("integer"); @@ -47,12 +53,14 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasIndex("LaborCostId"); + b.HasIndex("OrderId"); + b.HasIndex("StoreKeeperId"); b.ToTable("Cosmetics"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticProcedure", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticServices", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -63,19 +71,16 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("CosmeticId") .HasColumnType("integer"); - b.Property("ProcedureCosmeticCount") - .HasColumnType("integer"); - - b.Property("ProcedureId") + b.Property("ServiceId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("CosmeticId"); - b.HasIndex("ProcedureId"); + b.HasIndex("ServiceId"); - b.ToTable("CosmeticProcedures"); + b.ToTable("CosmeticServices"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b => @@ -86,9 +91,8 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Difficulty") - .IsRequired() - .HasColumnType("text"); + b.Property("Difficulty") + .HasColumnType("integer"); b.Property("StoreKeeperId") .HasColumnType("integer"); @@ -98,39 +102,7 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("StoreKeeperId"); - - 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"); + b.ToTable("LaborCosts"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => @@ -141,15 +113,13 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("DateComplete") - .HasColumnType("timestamp with time zone"); + b.Property("OrderName") + .IsRequired() + .HasColumnType("text"); - b.Property("DateCreate") + b.Property("PaymentDate") .HasColumnType("timestamp with time zone"); - b.Property("Status") - .HasColumnType("integer"); - b.Property("StoreKeeperId") .HasColumnType("integer"); @@ -163,32 +133,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.ToTable("Orders"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderCosmetic", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("CosmeticId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("OrderId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("CosmeticId"); - - b.HasIndex("OrderId"); - - b.ToTable("OrderCosmetics"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderProcedure", b => { b.Property("Id") @@ -200,9 +144,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Property("OrderId") .HasColumnType("integer"); - b.Property("OrderProcedureCount") - .HasColumnType("integer"); - b.Property("ProcedureId") .HasColumnType("integer"); @@ -215,32 +156,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.ToTable("OrderProcedures"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("OrderId") - .HasColumnType("integer"); - - b.Property("OrderServiceCount") - .HasColumnType("integer"); - - b.Property("ServiceId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.HasIndex("ServiceId"); - - b.ToTable("OrderServices"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => { b.Property("Id") @@ -265,12 +180,10 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("StoreKeeperId"); - b.ToTable("Procedures"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetic", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureServices", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -278,22 +191,22 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("CosmeticId") - .HasColumnType("integer"); - b.Property("Count") .HasColumnType("integer"); b.Property("ProcedureId") .HasColumnType("integer"); - b.HasKey("Id"); + b.Property("ServiceId") + .HasColumnType("integer"); - b.HasIndex("CosmeticId"); + b.HasKey("Id"); b.HasIndex("ProcedureId"); - b.ToTable("ProcedureCosmetics"); + b.HasIndex("ServiceId"); + + b.ToTable("ProcedureServices"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => @@ -304,6 +217,9 @@ namespace BeautyStudioDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + b.Property("ServiceName") .IsRequired() .HasColumnType("text"); @@ -316,63 +232,9 @@ namespace BeautyStudioDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("StoreKeeperId"); - b.ToTable("Services"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceCosmetic", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("CosmeticId") - .HasColumnType("integer"); - - b.Property("ServiceCosmeticCount") - .HasColumnType("integer"); - - b.Property("ServiceId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("CosmeticId"); - - b.HasIndex("ServiceId"); - - b.ToTable("ServiceCosmetics"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ProcedureId") - .HasColumnType("integer"); - - b.Property("ServiceId") - .HasColumnType("integer"); - - b.Property("ServiceProcedureCount") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ProcedureId"); - - b.HasIndex("ServiceId"); - - b.ToTable("ServiceProcedures"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b => { b.Property("Id") @@ -414,54 +276,40 @@ namespace BeautyStudioDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") + .WithMany("Cosmetics") + .HasForeignKey("OrderId"); + b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") - .WithMany() + .WithMany("Cosmetics") .HasForeignKey("StoreKeeperId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("LaborCost"); + b.Navigation("Order"); + b.Navigation("StoreKeeper"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticProcedure", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.CosmeticServices", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany("Procedures") + .WithMany("Services") .HasForeignKey("CosmeticId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Cosmetics") - .HasForeignKey("ProcedureId") + b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") + .WithMany("CosmeticServices") + .HasForeignKey("ServiceId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Cosmetic"); - b.Navigation("Procedure"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "StoreKeeper") - .WithMany() - .HasForeignKey("StoreKeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("StoreKeeper"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.MessageInfo", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", "Storekeeper") - .WithMany() - .HasForeignKey("StorekeeperId"); - - b.Navigation("Storekeeper"); + b.Navigation("Service"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b => @@ -475,25 +323,6 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("StoreKeeper"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderCosmetic", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany() - .HasForeignKey("CosmeticId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") - .WithMany("Cosmetics") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Cosmetic"); - - b.Navigation("Order"); - }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderProcedure", b => { b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") @@ -503,7 +332,7 @@ namespace BeautyStudioDatabaseImplement.Migrations .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany() + .WithMany("OrderProcedures") .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -513,95 +342,16 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("Procedure"); }); - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b => + modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureServices", b => { - b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order") + b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") .WithMany("Services") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany() - .HasForeignKey("ServiceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - - 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") - .WithMany() - .HasForeignKey("StoreKeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("StoreKeeper"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceCosmetic", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic") - .WithMany() - .HasForeignKey("CosmeticId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany("Cosmetics") - .HasForeignKey("ServiceId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Cosmetic"); - - b.Navigation("Service"); - }); - - modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b => - { - b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure") - .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service") - .WithMany("Procedures") + .WithMany("ProcedureServices") .HasForeignKey("ServiceId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -613,7 +363,7 @@ namespace BeautyStudioDatabaseImplement.Migrations modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b => { - b.Navigation("Procedures"); + b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b => @@ -626,20 +376,25 @@ namespace BeautyStudioDatabaseImplement.Migrations b.Navigation("Cosmetics"); b.Navigation("Procedures"); - - b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b => { - b.Navigation("Cosmetics"); + b.Navigation("OrderProcedures"); + + b.Navigation("Services"); }); modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b => { - b.Navigation("Cosmetics"); + b.Navigation("CosmeticServices"); - b.Navigation("Procedures"); + b.Navigation("ProcedureServices"); + }); + + 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 0b569f0..9caa35e 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs @@ -14,7 +14,7 @@ namespace BeautyStudioDatabaseImplement.Models public class Cosmetic : ICosmeticModel { public int Id { get; set; } - + public int? OrderId { get; set; } [Required] public string CosmeticName { get; set; } = string.Empty; @@ -27,29 +27,29 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int LaborCostId { get; set; } public virtual LaborCost LaborCost { get; set; } = new(); + public virtual Order? Order { get; set; } - //// связь многие-ко-многим заказов и косметики - //[ForeignKey("CosmeticId")] - //public virtual List Orders { get; set; } = new(); + [Required] + public DateTime DateCreate { get; set; } = DateTime.Now; + + private Dictionary? _cosmeticServices = null; // связь многие-ко-многим косметики с процедурами [ForeignKey("CosmeticId")] - private Dictionary? _cosmeticProcedures = null; + public virtual List Services { get; set; } = new(); [NotMapped] - public Dictionary CosmeticProcedure + public Dictionary CosmeticServices { get { - if (_cosmeticProcedures == null) + if (_cosmeticServices == null) { - _cosmeticProcedures = Procedures.ToDictionary(recPC => recPC.ProcedureId, recPC => (recPC.Procedure as IProcedureModel)); + _cosmeticServices = Services.ToDictionary(recPC => recPC.ServiceId, recPC => (recPC.Service as IServiceModel)); } - return _cosmeticProcedures; + return _cosmeticServices; } } - // список косметики в закаче - public virtual List Procedures { get; set; } = new(); public static Cosmetic Create(BeautyStudioDatabase context, CosmeticBindingModel model) { @@ -58,49 +58,54 @@ namespace BeautyStudioDatabaseImplement.Models { return null; } - var cosmetic = new Cosmetic() + return new Cosmetic() { Id = model.Id, + StoreKeeperId = model.StoreKeeperId, + LaborCostId = model.LaborCostId, + OrderId = model.OrderId, CosmeticName = model.CosmeticName, CosmeticPrice = model.CosmeticPrice, - LaborCostId = model.LaborCostId, - StoreKeeperId = model.StoreKeeperId + DateCreate = model.DateCreate, + + Services = model.CosmeticServices.Select(x => new CosmeticServices + { + Service = context.Services.First(y => y.Id == x.Key) + }).ToList() }; - return cosmetic; } - public void Update(BeautyStudioDatabase context, CosmeticBindingModel model) - { - CosmeticName = model.CosmeticName; - CosmeticPrice = model.CosmeticPrice; - LaborCostId = model.LaborCostId; - } + public void Update(CosmeticBindingModel model) + { + if (model == null) + { + return; + } + StoreKeeperId = model.StoreKeeperId; + LaborCostId = model.LaborCostId; + OrderId = model.OrderId; + CosmeticName = model.CosmeticName; + DateCreate = model.DateCreate; + CosmeticPrice = model.CosmeticPrice; + } - public void UpdateProcedures(BeautyStudioDatabase context, CosmeticBindingModel model) + public void UpdateServices(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) + foreach (var pc in model.CosmeticServices) { - context.CosmeticProcedures.Add(new CosmeticProcedure + if (!context.CosmeticServices.Any(ps => ps.CosmeticId == cosmetic.Id && ps.ServiceId == pc.Value.Id)) { - Cosmetic = cosmetic, - Procedure = context.Procedures.First(x => x.Id == rp.Key), - }); - context.SaveChanges(); + context.CosmeticServices.Add(new CosmeticServices + { + Cosmetic = cosmetic, + Service = context.Services.First(x => x.Id == pc.Key), + }); + } + } - _cosmeticProcedures = null; + context.SaveChanges(); + _cosmeticServices = null; } public CosmeticViewModel GetViewModel => new() @@ -108,8 +113,9 @@ namespace BeautyStudioDatabaseImplement.Models Id = Id, CosmeticName = CosmeticName, CosmeticPrice = CosmeticPrice, + OrderId = OrderId, LaborCostId = LaborCostId, - CosmeticProcedure = CosmeticProcedure, + CosmeticServices = CosmeticServices, StoreKeeperId = StoreKeeperId }; } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/CosmeticProcedure.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/CosmeticProcedure.cs deleted file mode 100644 index 5bc4f62..0000000 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/CosmeticProcedure.cs +++ /dev/null @@ -1,27 +0,0 @@ -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 CosmeticProcedure - { - public int Id { get; set; } - - [Required] - public int CosmeticId { get; set; } - - [Required] - public int ProcedureId { get; set; } - - [Required] - public int ProcedureCosmeticCount { get; set; } - - public virtual Cosmetic Cosmetic { get; set; } = new(); - - public virtual Procedure Procedure { get; set; } = new(); - } -} diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ServiceCosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/CosmeticServices.cs similarity index 82% rename from BeautyStudio/BeautyStudioDatabaseImplement/Models/ServiceCosmetic.cs rename to BeautyStudio/BeautyStudioDatabaseImplement/Models/CosmeticServices.cs index 3a1e82d..8a9eaa4 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ServiceCosmetic.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/CosmeticServices.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Models { - public class ServiceCosmetic + public class CosmeticServices { public int Id { get; set; } @@ -17,9 +17,6 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int ServiceId { get; set; } - [Required] - public int ServiceCosmeticCount { get; set; } - public virtual Cosmetic Cosmetic { get; set; } = new(); public virtual Service Service { get; set; } = new(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs index 5acf53f..763784b 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs @@ -1,5 +1,6 @@ using BeautyStudioContracts.BindingModels; using BeautyStudioContracts.ViewModels; +using BeautyStudioDataModels.Enums; using BeautyStudioDataModels.Models; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -12,15 +13,13 @@ namespace BeautyStudioDatabaseImplement.Models public int Id { get; set; } [Required] - public int TimeSpent { get; set; } + public TimeSpent TimeSpent { get; set; } [Required] - public string Difficulty { get; set; } = string.Empty; + public Difficulties Difficulty { get; set; } public int StoreKeeperId { get; set; } - public virtual StoreKeeper StoreKeeper { get; set; } - // связь один-ко-многим трудозатрат с косметикой [ForeignKey("LaborCostId")] public virtual List Cosmetics { get; set; } = new(); @@ -46,6 +45,7 @@ namespace BeautyStudioDatabaseImplement.Models { return; } + StoreKeeperId = model.StoreKeeperId; TimeSpent = model.TimeSpent; Difficulty = model.Difficulty; } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/MessageInfo.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/MessageInfo.cs deleted file mode 100644 index 6951ef9..0000000 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/MessageInfo.cs +++ /dev/null @@ -1,65 +0,0 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BeautyStudioDatabaseImplement.Models -{ - public class MessageInfo : IMessageInfoModel - { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.None)] - public string MessageId { get; set; } = string.Empty; - - public int? StorekeeperId { get; set; } - - public virtual StoreKeeper? Storekeeper { get; set; } - - [Required] - public string SenderName { get; set; } = string.Empty; - - [Required] - public DateTime DateDelivery { get; set; } - - [Required] - public string Subject { get; set; } = string.Empty; - - [Required] - public string Body { get; set; } = string.Empty; - - public static MessageInfo? Create(MessageInfoBindingModel? model) - { - if (model == null) - { - return null; - } - return new() - { - MessageId = model.MessageId, - StorekeeperId = model.StorekeeperId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - Subject = model.Subject, - Body = model.Body, - - }; - } - - - public MessageInfoViewModel GetViewModel => new() - { - MessageId = MessageId, - StorekeeperId = StorekeeperId, - SenderName = SenderName, - DateDelivery = DateDelivery, - Subject = Subject, - Body = Body - }; - } -} diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs index a1e8aff..ecd3459 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs @@ -2,6 +2,7 @@ using BeautyStudioContracts.ViewModels; using BeautyStudioDataModels.Enums; using BeautyStudioDataModels.Models; +using DocumentFormat.OpenXml.Bibliography; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -15,202 +16,94 @@ namespace BeautyStudioDatabaseImplement.Models public class Order : IOrderModel { public int Id { get; set; } - - [Required] - public DateTime DateCreate { get; set; } - - public DateTime? DateComplete { get; set; } - - [Required] - public OrderStatus Status { get; set; } - - [Required] + public int StoreKeeperId { get; set; } + public virtual StoreKeeper StoreKeeper { get; set; } + public string OrderName { get; set; } = string.Empty; + + public DateTime PaymentDate { get; set; } + public double Sum { get; set; } - [Required] - public int StoreKeeperId { get; set; } - public virtual StoreKeeper? StoreKeeper { get; set; } + [ForeignKey("OrderId")] + public virtual List Cosmetics { get; set; } = new(); + private Dictionary? _orderProcedures = null; - private Dictionary? _orderCosmetics = null; // поле для - [NotMapped] - public Dictionary? OrderCosmetics - { - get - { - if (_orderCosmetics == null) - { - _orderCosmetics = Cosmetics.ToDictionary(recPC => recPC.CosmeticId, recPC => (recPC.Cosmetic as ICosmeticModel, recPC.Count)); - } - return _orderCosmetics; - } - } + [ForeignKey("OrderId")] + public virtual List Procedures { get; set; } = new(); + [NotMapped] + public Dictionary OrderProcedures + { + get + { + if (_orderProcedures == null) + { + _orderProcedures = Procedures.ToDictionary(recPc => recPc.ProcedureId, recPc => recPc.Procedure as IProcedureModel); + } + return _orderProcedures; + } + } + public static Order? Create(BeautyStudioDatabase context, OrderBindingModel model) + { + if (model == null) + { + return null; + } + var order = new Order() + { + Id = model.Id, + OrderName = model.OrderName, + PaymentDate = model.PaymentDate, + Sum = model.Sum, + Procedures = model.OrderProcedures.Select(x => new OrderProcedure + { + Procedure = context.Procedures.First(y => y.Id == x.Value.Id) + }).ToList() + }; - [ForeignKey("OrderId")] - public virtual List Cosmetics { get; set; } = new(); // список косметических товаров для данного заказа. + foreach (var cosmetic in model.Cosmetics) + { + var cosm = context.Cosmetics.FirstOrDefault(x => x.Id == cosmetic.Value.Id); + if (cosm != null) + { + order.Cosmetics.Add(cosm); + } + } - private Dictionary? _orderProcedures = null; // поле для хранения словаря OrderCosmetics. + return order; + } - [NotMapped] - public Dictionary OrderProcedures // список косметики используемых в заказе. - { - get - { - 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 Dictionary OrderServices - { - get - { - 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(); - public static Order Create(BeautyStudioDatabase context, OrderBindingModel model) - { - if (model == null) - { - return null; - } - var order = new Order() - { - Id = model.Id, - Sum = model.Sum, - DateCreate = model.DateCreate, - DateComplete = model.DateComplete, - Status = model.Status, - StoreKeeperId = model.StoreKeeperId, - 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) - { - Sum = model.Sum; - Status = model.Status; - DateComplete = model.DateComplete; - } - - public OrderViewModel GetViewModel => new() - { - Id = Id, - DateCreate = DateCreate, - DateComplete = DateComplete, - Sum = Sum, - Status = Status - }; - - public void UpdateCosmetics(BeautyStudioDatabase context, OrderBindingModel model) - { - 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 rp in model.OrderCosmetics) - { - context.OrderCosmetics.Add(new OrderCosmetic - { - Order = order, - Cosmetic = context.Cosmetics.First(x => x.Id == rp.Key), - }); - context.SaveChanges(); - } - _orderCosmetics = null; - } - - public void UpdateProcedures(BeautyStudioDatabase context, OrderBindingModel model) - { - 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 rp in model.OrderProcedures) - { - context.OrderProcedures.Add(new OrderProcedure - { - Order = order, - Procedure = context.Procedures.First(x => x.Id == rp.Key), - }); - context.SaveChanges(); - } - _orderProcedures = null; - } - - public void UpdateServices(BeautyStudioDatabase context, OrderBindingModel model) - { - 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 rp in model.OrderServices) - { - context.OrderServices.Add(new OrderService - { - Order = order, - Service = context.Services.First(x => x.Id == rp.Key), - }); - context.SaveChanges(); - } - _orderServices = null; - } - } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + OrderName = model.OrderName; + PaymentDate = model.PaymentDate; + Sum = model.Sum; + } + public void UpdateProcedures(BeautyStudioDatabase context, OrderBindingModel model) + { + var order = context.Orders.First(x => x.Id == Id); + foreach (var pc in model.OrderProcedures) + { + context.OrderProcedures.Add(new OrderProcedure + { + Order = order, + Procedure = context.Procedures.First(x => x.Id == pc.Key), + }); + context.SaveChanges(); + } + _orderProcedures = null; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + OrderName = OrderName, + PaymentDate = PaymentDate, + Sum = Sum, + OrderProcedures = OrderProcedures, + Cosmetics = Cosmetics.ToDictionary(x => x.Id, x => x as ICosmeticModel), + }; + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs deleted file mode 100644 index acac6c6..0000000 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderCosmetic.cs +++ /dev/null @@ -1,27 +0,0 @@ -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 OrderCosmetic - { - public int Id { get; set; } - - [Required] - public int OrderId { get; set; } - - [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/OrderProcedure.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderProcedure.cs index 358b8c7..baafd14 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderProcedure.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderProcedure.cs @@ -17,9 +17,6 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int ProcedureId { get; set; } - [Required] - public int OrderProcedureCount { get; set; } - public virtual Order Order { get; set; } = new(); public virtual Procedure Procedure { get; set; } = new(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderService.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderService.cs deleted file mode 100644 index 39e11bd..0000000 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/OrderService.cs +++ /dev/null @@ -1,27 +0,0 @@ -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 OrderService - { - public int Id { get; set; } - - [Required] - public int OrderId { get; set; } - - [Required] - public int ServiceId { get; set; } - - [Required] - public int OrderServiceCount { get; set; } - - public virtual Order Order { get; set; } = new(); - - public virtual Service Service { get; set; } = new(); - } -} diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs index 8959807..9cf7858 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs @@ -26,91 +26,84 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int StoreKeeperId { get; set; } - public virtual StoreKeeper StoreKeeper { get; set; } - private Dictionary? _procedureCosmetics = null;//Это поле для хранения словаря OrderCosmetics. - - [NotMapped] - public Dictionary ProcedureCosmetics //представляет список косметики, участвующей в заказе. Не присутствует в базе данных. - { - get - { - if (_procedureCosmetics == null) - { - _procedureCosmetics = Cosmetics - .ToDictionary(recPC => recPC.CosmeticId, recPC => (recPC.Cosmetic as ICosmeticModel, recPC.ProcedureCosmeticCount)); - } - return _procedureCosmetics; - } - } + [ForeignKey("ProcedureId")] + public virtual List OrderProcedures { get; set; } = new(); - public virtual List Cosmetics { get; set; } = new();//представляет список косметических товаров для данного заказа. + private Dictionary? _procedureServices = null; + [ForeignKey("ProcedureId")] + public virtual List Services { get; set; } = new(); - public static Procedure Create(BeautyStudioDatabase context, ProcedureBindingModel model) - { - if (model == null) - { - return null; - } - var procedure = new Procedure() - { - Id = model.Id, - ProcedureName = model.ProcedureName, - ProcedureCost = model.ProcedureCost, - ProcedureDescription = model.ProcedureDescription, - StoreKeeperId = model.StoreKeeperId, - Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure - { - Cosmetic = context.Cosmetics.First(y => y.Id == x.Key) - }).ToList(), + public Dictionary ProcedureServices + { + get + { + if (_procedureServices == null) + { + _procedureServices = Services.ToDictionary(recPc => recPc.ServiceId, recPc => recPc.Service as IServiceModel); + } + return _procedureServices; + } + } + public static Procedure? Create(BeautyStudioDatabase context, ProcedureBindingModel model) + { + if (model == null) + { + return null; + } + var procedure = new Procedure() + { + Id = model.Id, + ProcedureName = model.ProcedureName, + ProcedureCost = model.ProcedureCost, + ProcedureDescription = model.ProcedureDescription, + Services = model.ProcedureServices.Select(x => new ProcedureServices + { + Service = context.Services.First(y => y.Id == x.Value.Id) + }).ToList() + }; - }; + return procedure; + } - return procedure; - } - public void Update(ProcedureBindingModel model) - { - ProcedureName = model.ProcedureName; - ProcedureCost = model.ProcedureCost; - ProcedureDescription = model.ProcedureDescription; - } + public void UpdateServices(BeautyStudioDatabase context, ProcedureBindingModel model) + { + var procedure = context.Procedures.First(x => x.Id == model.Id); - public ProcedureViewModel GetViewModel => new() - { - Id = Id, - ProcedureName = ProcedureName, - ProcedureCost = ProcedureCost, - ProcedureDescription = ProcedureDescription, - ProcedureCosmetics = ProcedureCosmetics, - StoreKeeperId = StoreKeeperId, - StoreKeeperName = StoreKeeper.StoreKeeperFIO, - }; + foreach (var pc in model.ProcedureServices) + { + // Проверяем, существует ли уже запись-связь + if (!context.ProcedureServices.Any(ps => ps.ProcedureId == procedure.Id && ps.ServiceId == pc.Value.Id)) + { + context.ProcedureServices.Add(new ProcedureServices + { + Procedure = procedure, + Service = context.Services.First(x => x.Id == pc.Value.Id), + }); + } + } - public void UpdateCosmetics(BeautyStudioDatabase context, ProcedureBindingModel model) - { - 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 rp in model.ProcedureCosmetics) - { - context.CosmeticProcedures.Add(new CosmeticProcedure - { - Procedure = procedure, - Cosmetic = context.Cosmetics.First(x => x.Id == rp.Key), - }); - context.SaveChanges(); - } - _procedureCosmetics = null; - } - } + context.SaveChanges(); // Сохраняем изменения только один раз + _procedureServices = null; + } + public void Update(ProcedureBindingModel? model) + { + if (model == null) + { + return; + } + ProcedureName = model.ProcedureName; + ProcedureCost = model.ProcedureCost; + ProcedureDescription = model.ProcedureDescription; + } + + public ProcedureViewModel GetViewModel => new() + { + Id = Id, + ProcedureName = ProcedureName, + ProcedureCost = ProcedureCost, + ProcedureDescription = ProcedureDescription, + ProcedureServices = ProcedureServices, + }; + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs deleted file mode 100644 index b045a49..0000000 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetic.cs +++ /dev/null @@ -1,27 +0,0 @@ -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/ServiceProcedure.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureServices.cs similarity index 81% rename from BeautyStudio/BeautyStudioDatabaseImplement/Models/ServiceProcedure.cs rename to BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureServices.cs index 9099cd5..511c86f 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ServiceProcedure.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureServices.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; @@ -8,21 +7,21 @@ using System.Threading.Tasks; namespace BeautyStudioDatabaseImplement.Models { - public class ServiceProcedure + public class ProcedureServices { public int Id { get; set; } - [Required] - public int ServiceId { get; set; } - [Required] public int ProcedureId { get; set; } [Required] - public int ServiceProcedureCount { get; set; } + public int ServiceId { get; set; } - public virtual Service Service { get; set; } = new(); + [Required] + public int Count { get; set; } public virtual Procedure Procedure { get; set; } = new(); + public virtual Service Service { get; set; } = new(); + } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs index 404d16d..ec09515 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs @@ -1,6 +1,7 @@ using BeautyStudioContracts.BindingModels; using BeautyStudioContracts.ViewModels; using BeautyStudioDataModels.Models; +using DocumentFormat.OpenXml.InkML; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -8,6 +9,7 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -17,7 +19,8 @@ namespace BeautyStudioDatabaseImplement.Models public class Service : IServiceModel { public int Id {get; set; } - + [Required] + public DateTime DateCreate { get ; set; } = DateTime.Now; [Required] public string ServiceName { get; set; } = string.Empty; @@ -25,144 +28,56 @@ namespace BeautyStudioDatabaseImplement.Models public double ServicePrice { get; set; } public int StoreKeeperId { get; set; } - public virtual StoreKeeper StoreKeeper { get; set; } - private Dictionary? _serviceCosmetics = null;//Это поле для хранения словаря OrderCosmetics. - [NotMapped] - public Dictionary ServiceCosmetics //представляет список косметики, участвующей в заказе. Не присутствует в базе данных. - { - get - { - 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; - } - } + public virtual List CosmeticServices { get; set; } = new(); [ForeignKey("ServiceId")] - public virtual List Procedures { get; set; } = new();//представляет список косметических товаров для данного заказа. + public virtual List ProcedureServices { get; set; } = new(); - public static Service Create(BeautyStudioDatabase context, ServiceBindingModel model) + public static Service? Create(ServiceBindingModel model) { if (model == null) { return null; } - var service = new Service() + return new Service() { Id = model.Id, + StoreKeeperId = model.StoreKeeperId, ServiceName = model.ServiceName, ServicePrice = model.ServicePrice, - StoreKeeperId = model.StoreKeeperId, - Cosmetics = model.ServiceCosmetics.Select(x => new ServiceCosmetic - { - Cosmetic = context.Cosmetics.First(y => y.Id == x.Key) - }).ToList(), - Procedures = model.ServiceProcedures.Select(x => new ServiceProcedure - { - Procedure = context.Procedures.First(y => y.Id == x.Key) - }).ToList() + DateCreate = model.DateCreate, + }; + } + public static Service Create(ServiceViewModel model) + { + return new Service + { + Id = model.Id, + StoreKeeperId = model.StoreKeeperId, + ServiceName = model.ServiceName, + ServicePrice = model.ServicePrice, + DateCreate = model.DateCreate, }; - - return service; } - - public void Update(ServiceBindingModel model) { + if (model == null) + { + return; + } + DateCreate = model.DateCreate; + StoreKeeperId = model.StoreKeeperId; ServiceName = model.ServiceName; ServicePrice = model.ServicePrice; - StoreKeeperId = model.StoreKeeperId; } - public ServiceViewModel GetViewModel => new() { Id = Id, + StoreKeeperId = StoreKeeperId, ServiceName = ServiceName, ServicePrice = ServicePrice, - ServiceCosmetics = ServiceCosmetics, - ServiceProcedures = ServiceProcedures, - StoreKeeperId = StoreKeeperId, + DateCreate = DateCreate, }; - - - - public void UpdateCosmetics(BeautyStudioDatabase context, ServiceBindingModel model) - { - 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 rp in model.ServiceCosmetics) - { - context.ServiceCosmetics.Add(new ServiceCosmetic - { - Service = service, - 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(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 rp in model.ServiceProcedures) - { - context.ServiceProcedures.Add(new ServiceProcedure - { - Service = service, - Procedure = context.Procedures.First(x => x.Id == rp.Key), - }); - context.SaveChanges(); - } - _serviceProcedures = null; - } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs index 37af6c0..1fe04f5 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs @@ -25,6 +25,9 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public string StoreKeeperPhone { get; set; } = string.Empty; + [ForeignKey("StoreKeeperId")] + public virtual List Cosmetics { get; set; } = new(); + public static StoreKeeper? Create(StoreKeeperBindingModel model) { diff --git a/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj b/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj index 411b9ad..1097767 100644 --- a/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj +++ b/BeautyStudio/BeautyStudioRestAPI/BeautyStudioRestAPI.csproj @@ -12,7 +12,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/BeautyStudio/BeautyStudioRestAPI/Controllers/CosmeticController.cs b/BeautyStudio/BeautyStudioRestAPI/Controllers/CosmeticController.cs index 103728d..6a1f6b8 100644 --- a/BeautyStudio/BeautyStudioRestAPI/Controllers/CosmeticController.cs +++ b/BeautyStudio/BeautyStudioRestAPI/Controllers/CosmeticController.cs @@ -53,7 +53,7 @@ namespace BeautyStudioRestAPI.Controllers { try { - return cosmetic.ReadList(new CosmeticSearchModel { LaborCostId = userId }); + return cosmetic.ReadList(new CosmeticSearchModel { Id = userId }); } catch (Exception ex) { diff --git a/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs b/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs deleted file mode 100644 index 22df385..0000000 --- a/BeautyStudio/BeautyStudioRestAPI/Controllers/ReportController.cs +++ /dev/null @@ -1,89 +0,0 @@ -using BeautyStudioBusinessLogic.MailWorker; -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.BusinessLogicContracts; -using Microsoft.AspNetCore.Mvc; - -namespace BeautyStudioRestAPI.Controllers -{ - [Route("api/[controller]/[action]")] - [ApiController] - public class ReportController : Controller - { - private readonly ILogger _logger; - private readonly IReportLogic _reportLogic; - - private readonly AbstractMailWorker _mailWorker; - public ReportController(ILogger logger, IReportLogic reportLogic, AbstractMailWorker abstractMailWorker) - { - _logger = logger; - _reportLogic = reportLogic; - _mailWorker = abstractMailWorker; - } - [HttpPost] - public void SaveServicesPdfFile(ReportBindingModel report) - { - try - { - _reportLogic.SaveServicesToPdfFile(new ReportServiceBindingModel - { - FileName = "C:\\reports\\pdfservicesreport.pdf", - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания отчета"); - throw; - } - } - [HttpPost] - public void SaveCosmeticProceduresToWordFile(ReportBindingModel report) - { - try - { - _reportLogic.SaveCosmeticProceduresToWordFile(new ReportBindingModel { FileName = "C:\\reports\\wordcosmeticproceduresreport.docx" }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания отчета"); - throw; - } - } - [HttpPost] - public void SaveCosmeticProceduresToExcelFile(ReportBindingModel report) - { - try - { - _reportLogic.SaveCosmeticProceduresToExcelFile(new ReportBindingModel { FileName = "C:\\reports\\excelcosmeticproceduresreport.xlsx" }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания отчета"); - throw; - } - } - [HttpPost] - public void MailSend(ReportServiceBindingModel report) - { - try - { - _reportLogic.SaveServicesToPdfFile(new ReportServiceBindingModel - { - FileName = report.FileName, - StorekeeperId = report.StorekeeperId, - Email = report.Email, - }); - _mailWorker.MailSendAsync(new MailSendInfoBindingModel - { - MailAddress = report.Email!, - Subject = "Отчет по услугам", - Text = "Ваш отчет:" - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отправки письма"); - throw; - } - } - } -} diff --git a/BeautyStudio/BeautyStudioRestAPI/Program.cs b/BeautyStudio/BeautyStudioRestAPI/Program.cs index 7f3667d..4995f69 100644 --- a/BeautyStudio/BeautyStudioRestAPI/Program.cs +++ b/BeautyStudio/BeautyStudioRestAPI/Program.cs @@ -5,7 +5,6 @@ using BeautyStudioContracts.StoragesContracts; using BeautyStudioDatabaseImplement.Implements; using BeautyStudioBusinessLogic.OfficePackage; using BeautyStudioBusinessLogic.OfficePackage.Implements; -using Microsoft.OpenApi.Models; using System.Reflection.PortableExecutable; using BeautyStudioBusinessLogic.MailWorker; @@ -16,7 +15,6 @@ builder.Logging.AddLog4Net("log4net.config"); // Add services to the container. builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -24,7 +22,6 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -34,22 +31,12 @@ 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.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(c => -{ - c.SwaggerDoc("v1", new OpenApiInfo { Title = "BeautyStudioRestAPI", Version = "v1" }); -}); - var app = builder.Build(); var mailSender = app.Services.GetService(); mailSender?.MailConfig(new MailConfigBindingModel @@ -62,11 +49,7 @@ mailSender?.MailConfig(new MailConfigBindingModel PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) }); // Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BeautyStudioRestAPI v1")); -} + app.UseAuthorization(); app.MapControllers(); diff --git a/BeautyStudio/StoreKeeperWebApp/APIStoreKeeper.cs b/BeautyStudio/StoreKeeperWebApp/APIStoreKeeper.cs deleted file mode 100644 index 76febdb..0000000 --- a/BeautyStudio/StoreKeeperWebApp/APIStoreKeeper.cs +++ /dev/null @@ -1,49 +0,0 @@ -using BeautyStudioContracts.ViewModels; -using Newtonsoft.Json; -using System.Net.Http.Headers; -using System.Text; - -namespace StoreKeeperWebApp -{ - public class APIStoreKeeper - { - private static readonly HttpClient _storekeeper = new(); - - public static StoreKeeperViewModel? Storekeeper { get; set; } = null; - - public static void Connect(IConfiguration configuration) - { - _storekeeper.BaseAddress = new Uri(configuration["IPAddress"]); - _storekeeper.DefaultRequestHeaders.Accept.Clear(); - _storekeeper.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - } - - public static T? GetRequest(string requestUrl) - { - var response = _storekeeper.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } - - public static void PostRequest(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); - - var response = _storekeeper.PostAsync(requestUrl, data); - - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - } -} \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs deleted file mode 100644 index d19dea6..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Controllers/CosmeticController.cs +++ /dev/null @@ -1,161 +0,0 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.BusinessLogicContracts; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDatabaseImplement; -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(int laborCostId) - { - 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, double price, int laborCost) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - if (string.IsNullOrEmpty(name) || 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, 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/HomeController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/HomeController.cs index f7c0628..89bc9d8 100644 --- a/BeautyStudio/StoreKeeperWebApp/Controllers/HomeController.cs +++ b/BeautyStudio/StoreKeeperWebApp/Controllers/HomeController.cs @@ -3,267 +3,422 @@ using BeautyStudioContracts.ViewModels; using StoreKeeperWebApp; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; -using BeautyStudioContracts.BusinessLogicContracts; -using BeautyStudioBusinessLogic.MailWorker; -using DocumentFormat.OpenXml.Spreadsheet; -using Microsoft.Extensions.Hosting; -using BeautyStudioContracts.SearchModels; +using System.IO; +using System.Numerics; +using BeautyStudioDataModels.Enums; +using BeautyStudioDatabaseImplement.Models; using StoreKeeperWebApp.Models; -using Microsoft.AspNetCore.Identity.Data; +using DocumentFormat.OpenXml.Wordprocessing; namespace StoreKeeperWebApp.Controllers { - public class HomeController : Controller - { - private readonly ILogger _logger; - private readonly IStoreKeeperLogic _logic; - private readonly ICosmeticLogic _cosmeticLogic; - private readonly IReportLogic _reportLogic; + public class HomeController : Controller + { + private readonly ILogger _logger; + private readonly StoreKeeperData _data; + public HomeController(ILogger logger, StoreKeeperData data) + { + _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserStoreKeeper.user != null; } } + private int UserId { get { return UserStoreKeeper.user!.Id; } } + public IActionResult IndexNonReg() + { + if (!IsLoggedIn) + return View(); + return RedirectToAction("Index"); + } + public IActionResult Index() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + return View(); + } + [HttpGet] + public IActionResult Enter() + { + if (!IsLoggedIn) + return View(); + return RedirectToAction("Index"); + } + [HttpPost] + public void Enter(string login, string password) + { + var user = _data.Login(login, password); + if (user != null) + { + UserStoreKeeper.user = user; + Response.Redirect("Index"); + } + } + [HttpGet] + public IActionResult Register() + { + return View(); + } + public IActionResult Logout() + { + UserStoreKeeper.user = null; + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public void Register(string name, string phone, string email, string password1, string password2) + { + if (password1 == password2 && _data.Register(new() { StoreKeeperEmail = email, StoreKeeperLogin = email, StoreKeeperFIO = name, StoreKeeperPhone = phone, StoreKeeperPassword = password1 })) + { + Response.Redirect("Index"); + } + } + [HttpGet] + public IActionResult IndexService() + { + if (UserStoreKeeper.user != null) + { + var list = _data.GetServices(UserStoreKeeper.user.Id); + if (list != null) + return View(list); + return View(new List()); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public void IndexService(int id) + { + if (UserStoreKeeper.user != null) + { + _data.DeleteService(id); + } + Response.Redirect("IndexService"); + } + [HttpGet] + public IActionResult CreateService(int id) + { + var procedures = _data.GetProcedures(); + ViewBag.AllProcedures = procedures; + if (id != 0) + { + var value = _data.GetService(id); + if (value != null) + return View(value); + } + return View(new ServiceViewModel()); + } + [HttpPost] + public IActionResult CreateService(ServiceBindingModel model, int[] procedureIds) + { + var procedures = _data.GetProcedures(); + if (model.Id == 0) + { + model.DateCreate = DateTime.UtcNow; + model.StoreKeeperId = UserStoreKeeper.user!.Id; + for (int i = 0; i < procedureIds.Length; i++) + { + var procedure = procedures!.FirstOrDefault(x => x.Id == procedureIds[i])!; + model.ServiceProcedures.Add(i, procedure); + } + if (_data.CreateService(model)) + return RedirectToAction("IndexService"); + } + else + { + for (int i = 0; i < procedureIds.Length; i++) + { + var procedure = procedures!.FirstOrDefault(x => x.Id == procedureIds[i])!; + model.ServiceProcedures.Add(i, procedure); + } + model.StoreKeeperId = UserStoreKeeper.user!.Id; + if (_data.UpdateService(model)) + return RedirectToAction("IndexService"); + } + return View(); + } - private readonly AbstractMailWorker _mailLogic; + [HttpGet] + public IActionResult IndexLaborCost() + { + if (UserStoreKeeper.user != null) + { + var list = _data.GetLaborCosts(UserStoreKeeper.user.Id); + if (list != null) + return View(list); + return View(new List()); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public void IndexLaborCost(int id) + { + if (UserStoreKeeper.user != null) + { + _data.DeleteLaborCost(id); + } + Response.Redirect("IndexLaborCost"); + } + [HttpGet] + public IActionResult CreateLaborCost(int id) + { + if (id != 0) + { + var value = _data.GetLaborCost(id); + if (value != null) + return View(value); + } + return View(new LaborCostViewModel()); + } + [HttpPost] + public IActionResult CreateLaborCost(LaborCostBindingModel model) + { + if (model.Id == 0) + { + model.StoreKeeperId = UserStoreKeeper.user!.Id; + if (_data.CreateLaborCost(model)) + return RedirectToAction("IndexLaborCost"); + } + else + { + model.StoreKeeperId = UserStoreKeeper.user!.Id; + if (_data.UpdateLaborCost(model)) + return RedirectToAction("IndexLaborCost"); + } + return View(); + } + [HttpGet] + public IActionResult IndexCosmetic() + { + if (UserStoreKeeper.user != null) + { + var cosmetics = _data.GetCosmetics(UserStoreKeeper.user.Id); + return View(cosmetics); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult IndexCosmetic(int id) + { + _data.DeleteCosmetic(id); + return RedirectToAction("IndexCosmetic"); + } + [HttpGet] + public IActionResult CreateCosmetic(int id) + { + var services = _data.GetServices(UserStoreKeeper.user!.Id); + var laborCosts = _data.GetLaborCosts(UserStoreKeeper.user!.Id); + ViewBag.AllServices = services; + ViewBag.LaborCosts = laborCosts; + if (id != 0) + { + var value = _data.GetCosmetic(id); + if (value != null) + return View(value); + } + return View(new CosmeticViewModel()); + } + [HttpPost] + public IActionResult CreateCosmetic(int id, string CosmeticName, int LaborCostId, int[] serviceIds) + { + CosmeticBindingModel model = new CosmeticBindingModel(); + model.Id = id; + model.CosmeticName = CosmeticName; + model.LaborCostId = LaborCostId; + model.DateCreate = DateTime.UtcNow; + model.StoreKeeperId = UserStoreKeeper.user!.Id; + var services = _data.GetServices(UserStoreKeeper.user!.Id); + double sum = 0; + for (int i = 0; i < serviceIds.Length; i++) + { + var service = services!.FirstOrDefault(x => x.Id == serviceIds[i])!; + model.CosmeticServices[serviceIds[i]] = service; + sum += service.ServicePrice; + } + model.CosmeticPrice = sum; + bool changed = false; + if (model.CosmeticServices.Count > 0) + { + if (id != 0) + { + changed = _data.UpdateCosmetic(model); + } + else + { + changed = _data.CreateCosmetic(model); + } + } + if (changed) + return RedirectToAction("IndexCosmetic"); + else + { + ViewBag.AllServices = services; + return View(model); + } + } - public HomeController(ILogger logger, IStoreKeeperLogic workerLogic, ICosmeticLogic cosmeticLogic, IReportLogic reportLogic, AbstractMailWorker mailLogic) - { - _logger = logger; - _logic = workerLogic; - _cosmeticLogic = cosmeticLogic; - _reportLogic = reportLogic; - _mailLogic = mailLogic; - } + [HttpGet] + public IActionResult Privacy() + { + if (IsLoggedIn) + return View(UserStoreKeeper.user); + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult Privacy(int id, string fullname, string email, string password, string phone) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + StoreKeeperBindingModel user = new() + { + Id = id, + StoreKeeperFIO = fullname, + StoreKeeperEmail = email, + StoreKeeperPhone = phone, + }; + if (_data.UpdateUser(user)) + { + UserStoreKeeper.user = new StoreKeeperViewModel + { + Id = id, + StoreKeeperEmail = email, + StoreKeeperFIO = fullname, + StoreKeeperPhone = phone, + }; + } + return View(user); + } + [HttpGet] + public IActionResult ServiceTimeChoose() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + return View(); + } + [HttpPost] + public IActionResult SendReport(DateTime startDate, DateTime endDate) + { - [HttpGet] - public IActionResult Index() - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } + return Ok(); + } + [HttpGet] + public IActionResult ServiceTimeReport() + { + var startDateStr = HttpContext.Session.GetString("StartDate"); + var endDateStr = HttpContext.Session.GetString("EndDate"); - return View(APIStoreKeeper.Storekeeper); - } + if (string.IsNullOrEmpty(startDateStr) || string.IsNullOrEmpty(endDateStr)) + { + return RedirectToAction("ServiceTimeChoose"); + } - [HttpGet] - public IActionResult Privacy() - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIStoreKeeper.Storekeeper); - } - [HttpPost] + var startDate = DateTime.Parse(startDateStr); + var endDate = DateTime.Parse(endDateStr).AddDays(1); - public void Privacy(string login, string password, string fio, string phone) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception(" ?... , !!!"); - } - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception(" , , "); - } - _logic.Update(new StoreKeeperBindingModel - { - Id = APIStoreKeeper.Storekeeper.Id, - StoreKeeperFIO = fio, - StoreKeeperLogin = login, - StoreKeeperPassword = password, - StoreKeeperEmail = login, - StoreKeeperPhone = phone - - }); - APIStoreKeeper.Storekeeper.StoreKeeperFIO = fio; - APIStoreKeeper.Storekeeper.StoreKeeperLogin = login; - APIStoreKeeper.Storekeeper.StoreKeeperPassword = password; - APIStoreKeeper.Storekeeper.StoreKeeperEmail = login; - APIStoreKeeper.Storekeeper.StoreKeeperPhone = phone; + var values = _data.GetTimeReport(startDate, endDate, UserId); - Response.Redirect("Privacy"); - } + ViewBag.StartDate = startDate; + ViewBag.EndDate = endDate; - [HttpGet] - public IActionResult Enter() - { - if (APIStoreKeeper.Storekeeper != null) - { - throw new Exception(" !"); - } + return View(values); + } + [HttpPost] + public IActionResult TimeReportWeb(DateTime startDate, DateTime endDate) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); - return View(); - } - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { - throw new Exception(" !"); - } + HttpContext.Session.SetString("StartDate", startDate.ToString("yyyy-MM-dd")); + HttpContext.Session.SetString("EndDate", endDate.ToString("yyyy-MM-dd")); - APIStoreKeeper.Storekeeper = _logic.ReadElement(new StoreKeeperSearchModel - { - StoreKeeperLogin = login, - StoreKeeperPassword = password - }); - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception(" /"); - } + return RedirectToAction("ServiceTimeReport"); + } + [HttpPost] + public void ServiceTimeMail() + { + var startDateStr = HttpContext.Session.GetString("StartDate"); + var endDateStr = HttpContext.Session.GetString("EndDate"); + var startDate = DateTime.Parse(startDateStr); + var endDate = DateTime.Parse(endDateStr).AddDays(1); + using (MemoryStream memoryStream = new MemoryStream()) + { + _data.SendMailReport(startDate, endDate, UserId, memoryStream); + } + Response.Redirect("ServiceTimeReport"); + } + [HttpGet] + public IActionResult CosmeticProcedureChoose() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var details = _data.GetCosmetics(UserId); + return View(details); + } + [HttpPost] + public IActionResult CosmeticProcedureChoose(List selectedItems, string reportType) + { + string value = string.Join("/", selectedItems); + HttpContext.Session.SetString("Cosmetics", value); + if (reportType.Equals("default")) + return RedirectToAction("CosmeticProceduresReport"); + else if (reportType.Equals("excel")) + return RedirectToAction("ExcelGenerate"); + else + return RedirectToAction("WordGenerate"); + } + public async Task ExcelGenerate() + { + var value = HttpContext.Session.GetString("Cosmetics"); + if (value != null) + { + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + using (MemoryStream memoryStream = new MemoryStream()) + { + _data.SaveReportExcel(rawReports, memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + var outputStream = new MemoryStream(); + await memoryStream.CopyToAsync(outputStream); + outputStream.Seek(0, SeekOrigin.Begin); + return File(outputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ReportExcel.xlsx"); + } + } + return RedirectToAction("CosmeticProceduresChoose"); + } + public async Task WordGenerate() + { + var value = HttpContext.Session.GetString("Cosmetics"); + if (value != null) + { + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + using (MemoryStream memoryStream = new MemoryStream()) + { + _data.SaveReportWord(rawReports, memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + var outputStream = new MemoryStream(); + await memoryStream.CopyToAsync(outputStream); + outputStream.Seek(0, SeekOrigin.Begin); + return File(outputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "ReportWord.docx"); + } + } + return RedirectToAction("CosmeticProceduresChoose"); + } + [HttpGet] + public IActionResult CosmeticProceduresReport() + { + var value = HttpContext.Session.GetString("Cosmetics"); + if (value != null) + { + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + var reports = _data.GetProcedureReports(rawReports); + return View(reports); + } + return View(new List()); + } + public IActionResult ReportMenu() + { + return View(); + } - Response.Redirect("Index"); - } - - [HttpGet] - public IActionResult Register() - { - if (APIStoreKeeper.Storekeeper != null) - { - throw new Exception(" !"); - } - - return View(); - } - [HttpPost] - public void Register(string fio, string email, string password, string phone) - { - if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(phone)) - { - throw new Exception(" !"); - } - - _logic.Create(new StoreKeeperBindingModel - { - StoreKeeperFIO = fio, - StoreKeeperEmail = email, - StoreKeeperPassword = password, - StoreKeeperLogin = email, - StoreKeeperPhone = phone - }); - - Response.Redirect("Enter"); - } - [HttpGet] - public void Logout() - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception(" !"); - } - - APIStoreKeeper.Storekeeper = null; - Response.Redirect("Enter"); - } - - [HttpGet] - public IActionResult Reports() - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception(" !"); - } - var data = _reportLogic.GetServices(new ReportServiceBindingModel()); - - return View(data); - } - - [HttpPost] - public async Task CreateReportWord(List cosmetics, DateTime dateFrom, DateTime dateTo, [FromServices] IWebHostEnvironment hostingEnvironment) - { - // - var folderName = "C:\\"; - var fileName = $" {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx"; - var filePath = Path.Combine(hostingEnvironment.ContentRootPath, folderName, fileName); - - _reportLogic.SaveCosmeticProceduresToWordFile(new ReportBindingModel - { - FileName = filePath, - DateFrom = dateFrom, - DateTo = dateTo - }); - - // - var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath); - return File(fileBytes, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fileName); - } - - [HttpPost] - public async Task CreateReportExcel(List cosmetics, DateTime dateFrom, DateTime dateTo, [FromServices] IWebHostEnvironment hostingEnvironment) - { - // - var folderName = "C:\\"; - var fileName = $" {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx"; - var filePath = Path.Combine(hostingEnvironment.ContentRootPath, folderName, fileName); - - _reportLogic.SaveCosmeticProceduresToExcelFile(new ReportBindingModel - { - FileName = filePath, - DateFrom = dateFrom, - DateTo = dateTo - }); - - // - var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath); - return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName); - } - - [HttpPost] - public async Task CreateReportPdf(DateTime dateFrom, DateTime dateTo, [FromServices] IWebHostEnvironment hostingEnvironment) - { - // - var folderName = "C:\\"; - var fileName = $" {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.pdf"; - var filePath = Path.Combine(hostingEnvironment.ContentRootPath, folderName, fileName); - - _reportLogic.SaveServicesToPdfFile(new ReportServiceBindingModel - { - FileName = filePath, - StorekeeperId = APIStoreKeeper.Storekeeper.Id - }); - - // - var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath); - return File(fileBytes, "application/pdf", fileName); - } - - [HttpPost] - public async Task SendReport(IFormFile fileUpload, [FromServices] IWebHostEnvironment hostingEnvironment) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception(" !"); - } - - if (fileUpload == null || fileUpload.Length <= 0) - { - throw new Exception(" !"); - } - - // - var uploadPath = Path.Combine(hostingEnvironment.ContentRootPath, "C:\\"); - var fileName = Path.GetFileName(fileUpload.FileName); - var fullPath = Path.Combine(uploadPath, fileName); - - using (var fileStream = new FileStream(fullPath, FileMode.Create)) - { - await fileUpload.CopyToAsync(fileStream); - } - - _mailLogic.MailSendAsync(new MailSendInfoBindingModel - { - MailAddress = APIStoreKeeper.Storekeeper.StoreKeeperEmail, - Subject = $"{fileName.Split('.')[0]}", - Text = $" {DateTime.Now}", - Path = fullPath - }); - - return RedirectToAction("Reports", "Home"); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + } } \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs deleted file mode 100644 index bde281d..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Controllers/LaborCostController.cs +++ /dev/null @@ -1,179 +0,0 @@ -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? GetLaborCosts(int id) - { - try - { - return laborCost.ReadElement(new LaborCostSearchModel - { - Id = id - }); - } - catch (Exception ex) - { - logger.LogError(ex, "Ошибка получения трудозатраты"); - throw; - } - } - - [HttpGet] - public IActionResult LaborCosts() - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - return View(laborCost.ReadList(null)); - } - - [HttpGet] - public IActionResult CreateLaborCosts() - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel - { - StoreKeeperId = APIStoreKeeper.Storekeeper.Id, - }); - - return View(); - } - - [HttpPost] - public void CreateLaborCosts(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/LaborCosts"); - } - - [HttpGet] - public IActionResult UpdateLaborCosts(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 UpdateLaborCosts(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/LaborCosts"); - } - - /// - /// Удалить косметику - /// - /// - [HttpPost] - public void DeleteLaborCosts(int id) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - laborCost.Delete(new LaborCostBindingModel - { - Id = id - }); - - Response.Redirect("/LaborCost/LaborCosts"); - } - } -} diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/ProcedureController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/ProcedureController.cs deleted file mode 100644 index 217efe0..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Controllers/ProcedureController.cs +++ /dev/null @@ -1,147 +0,0 @@ -using BeautyStudioBusinessLogic.BusinessLogic; -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.BusinessLogicContracts; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDatabaseImplement.Models; -using Microsoft.AspNetCore.Mvc; -using StoreKeeperWebApp; - -namespace StoreKeeperWebApp.Controllers -{ - public class ProcedureController : Controller - { - private readonly ILogger logger; - - private readonly ICosmeticLogic cosmetic; - private readonly IProcedureLogic procedure; - private readonly IServiceLogic service; - - public ProcedureController(ILogger logger, ICosmeticLogic cosmetic, IProcedureLogic procedure) - { - this.logger = logger; - this.cosmetic = cosmetic; - this.procedure = procedure; - } - - [HttpGet] - public ProcedureViewModel? GetProcedure(int id) - { - try - { - return procedure.ReadElement(new ProcedureSearchModel - { - Id = id - }); - } - catch (Exception ex) - { - logger.LogError(ex, "Ошибка получения косметики"); - throw; - } - } - - [HttpGet] - public IActionResult Procedures() - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - return View(procedure.ReadList(null)); - } - - [HttpGet] - public IActionResult CreateProcedures() - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - ViewBag.Procedures = procedure.ReadList(null); - - return View(); - } - - [HttpPost] - public void CreateProcedures(string name, double cost, string description) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - if (string.IsNullOrEmpty(name) || cost <= 0 || cost <= 0 || string.IsNullOrEmpty(description)) - { - throw new Exception("Введены не все данные!"); - } - - procedure.Create(new ProcedureBindingModel - { - ProcedureName = name, - ProcedureCost = cost, - ProcedureDescription = description, - StoreKeeperId = APIStoreKeeper.Storekeeper.Id - }); - - Response.Redirect("/Evaluation/Evaluations"); - } - - [HttpGet] - public IActionResult UpdateProcedures(int id) - { - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - return View(cosmetic.ReadElement(new CosmeticSearchModel - { - Id = id - })); - } - - [HttpPost] - public void UpdateProcedures(int id, string name, double cost, string description) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - if (string.IsNullOrEmpty(name) || cost <= 0 || string.IsNullOrEmpty(description)) - { - throw new Exception("Введены не все данные!"); - } - - procedure.Update(new ProcedureBindingModel - { - Id = id, - ProcedureName = name, - ProcedureCost = cost, - ProcedureDescription = description, - StoreKeeperId = APIStoreKeeper.Storekeeper.Id - }); - - Response.Redirect("/Evaluation/Evaluations"); - } - - [HttpPost] - public void DeleteProcedure(int id) - { - if (APIStoreKeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - procedure.Delete(new ProcedureBindingModel - { - Id = id - }); - - Response.Redirect("/Evaluation/Evaluations"); - } - } -} \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs b/BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs deleted file mode 100644 index 72bdd05..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Controllers/ServiceController.cs +++ /dev/null @@ -1,194 +0,0 @@ -using BeautyStudioContracts.BindingModels; -using BeautyStudioContracts.BusinessLogicContracts; -using BeautyStudioContracts.SearchModels; -using BeautyStudioContracts.ViewModels; -using BeautyStudioDatabaseImplement.Models; -using BeautyStudioDataModels.Enums; -using BeautyStudioDataModels.Models; -using DocumentFormat.OpenXml.Spreadsheet; -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"); - } - - public IActionResult AddProcedureToService() - { - - if (APIStoreKeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - ViewBag.Procedures = _procedureLogic.ReadList(null); - ViewBag.Services = _serviceLogic.ReadList(null); - return View(); - } - //[HttpPost] - //public void AddProcedureToService(int product, int order) - //{ - // if (APIStoreKeeper.Storekeeper == null) - // { - // throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); - // } - // APIStoreKeeper.PostRequest("api/main/updateorder", new OrderBindingModel - // { - // Id = order, - // ProductId = product, - // Status = OrderStatus.Принят, - // }); - // Response.Redirect(""); - //} - } -} diff --git a/BeautyStudio/StoreKeeperWebApp/Program.cs b/BeautyStudio/StoreKeeperWebApp/Program.cs index c69b8a4..0880e9d 100644 --- a/BeautyStudio/StoreKeeperWebApp/Program.cs +++ b/BeautyStudio/StoreKeeperWebApp/Program.cs @@ -5,8 +5,8 @@ using BeautyStudioContracts.BusinessLogicContracts; using BeautyStudioContracts.StoragesContracts; using BeautyStudioBusinessLogic.OfficePackage.Implements; using BeautyStudioBusinessLogic.OfficePackage; -using System.Reflection.PortableExecutable; using BeautyStudioDatabaseImplement.Implements; +using StoreKeeperWebApp; var builder = WebApplication.CreateBuilder(args); @@ -16,19 +16,17 @@ builder.Services.AddControllersWithViews(); // Logger service builder.Logging.SetMinimumLevel(LogLevel.Trace); - +builder.Logging.AddLog4Net("log4net.config"); // 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.AddTransient(); builder.Services.AddSingleton(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -41,8 +39,14 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddSession(options => +{ + options.IdleTimeout = TimeSpan.FromMinutes(30); + options.Cookie.HttpOnly = true; + options.Cookie.IsEssential = true; +}); var app = builder.Build(); diff --git a/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs b/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs new file mode 100644 index 0000000..4d9b101 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/StoreKeeperData.cs @@ -0,0 +1,298 @@ +using BeautyStudioContracts.BusinessLogicContracts; +using BeautyStudioContracts.ViewModels; +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.StoragesContracts; +using BeautyStudioContracts.SearchModels; +using BeautyStudioBusinessLogic.MailWorker; +using BeautyStudioBusinessLogic.OfficePackage; +using BeautyStudioDatabaseImplement.Models; +using System.Linq; +using BeautyStudioDataModels.Models; +using BeautyStudioBusinessLogic.BusinessLogic; + +namespace StoreKeeperWebApp +{ + public class StoreKeeperData + { + private readonly ILogger _logger; + private readonly IStoreKeeperLogic _StoreKeeperLogic; + private readonly IServiceLogic _serviceLogic; + private readonly ILaborCostLogic _laborCostLogic; + private readonly ICosmeticLogic _cosmeticLogic; + private readonly IProcedureLogic _procedureLogic; + private readonly IOrderLogic _orderLogic; + private readonly AbstractSaveToExcel _excel; + private readonly AbstractSaveToWord _word; + private readonly AbstractSaveToPdf _pdf; + private readonly AbstractMailWorker _mail; + + public StoreKeeperData(ILogger logger, IStoreKeeperLogic StoreKeeperLogic, + IServiceLogic serviceLogic, ILaborCostLogic laborCostLogic, ICosmeticLogic cosmeticLogic, + IProcedureLogic procedureLogic, IOrderLogic orderLogic, + AbstractSaveToExcel excel, + AbstractSaveToWord word, + AbstractMailWorker mail, + AbstractSaveToPdf pdf) + { + _logger = logger; + _StoreKeeperLogic = StoreKeeperLogic; + _serviceLogic = serviceLogic; + _laborCostLogic = laborCostLogic; + _cosmeticLogic = cosmeticLogic; + _procedureLogic = procedureLogic; + _orderLogic = orderLogic; + _excel = excel; + _word = word; + _mail = mail; + _pdf = pdf; + } + + public StoreKeeperViewModel? Login(string email, string password) + { + return _StoreKeeperLogic.ReadElement(new() + { + StoreKeeperEmail = email, + StoreKeeperPassword = password + }); + } + public bool Register(StoreKeeperBindingModel model) + { + return _StoreKeeperLogic.Create(model); + } + public bool UpdateUser(StoreKeeperBindingModel model) + { + return _StoreKeeperLogic.Update(model); + } + + public List? GetServices(int userId) + { + return _serviceLogic.ReadList(new ServiceSearchModel() { StoreKeeperId = userId }); + } + public bool DeleteService(int serviceId) + { + return _serviceLogic.Delete(new() { Id = serviceId }); + } + public bool CreateService(ServiceBindingModel model) + { + return _serviceLogic.Create(model); + } + public bool UpdateService(ServiceBindingModel model) + { + return _serviceLogic.Update(model); + } + public ServiceViewModel? GetService(int id) + { + return _serviceLogic.ReadElement(new() { Id = id }); + } + public List? GetLaborCosts(int userId) + { + return _laborCostLogic.ReadList(new LaborCostSearchModel() { StoreKeeperId = userId }); + } + public bool DeleteLaborCost(int serviceId) + { + return _laborCostLogic.Delete(new() { Id = serviceId }); + } + public bool CreateLaborCost(LaborCostBindingModel model) + { + return _laborCostLogic.Create(model); + } + public bool UpdateLaborCost(LaborCostBindingModel model) + { + return _laborCostLogic.Update(model); + } + public LaborCostViewModel? GetLaborCost(int id) + { + return _laborCostLogic.ReadElement(new() { Id = id }); + } + public List? GetCosmetics(int userId) + { + return _cosmeticLogic.ReadList(new CosmeticSearchModel() { StoreKeeperId = userId }); + } + public CosmeticViewModel? GetCosmetic(int id) + { + return _cosmeticLogic.ReadElement(new() { Id = id }); + } + public bool CreateCosmetic(CosmeticBindingModel model) + { + return _cosmeticLogic.Create(model); + } + public bool UpdateCosmetic(CosmeticBindingModel model) + { + return _cosmeticLogic.Update(model); + } + public bool DeleteCosmetic(int cosmeticId) + { + return _cosmeticLogic.Delete(new() { Id = cosmeticId }); + } + public List? GetProcedures() + { + return _procedureLogic.ReadList(null); + } + public List? GetOrders() + { + return _orderLogic.ReadList(null); + } + + public List GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId) + { + var services = _serviceLogic.ReadList(new() { DateCreate = startDate, DateComplete = endDate, StoreKeeperId = UserId }); + if (services == null) + return new(); + List serviceTimeReports = new List(); + foreach (var service in services) + { + var report = new ReportServicesViewModel(); + report.Id = service.Id; + + List prs = new List(); + HashSet filteredOrders = new HashSet(); + + var procedures = _procedureLogic.ReadList(null);//get all procedures + var orders = _orderLogic.ReadList(null); //get all orders + + foreach (var p in procedures) + { + foreach(var s in p.ProcedureServices) + { + if(s.Value.Id == service.Id) + { + prs.Add(p); + break; + } + } + } + + foreach(var o in orders) + { + foreach (var p in prs) + { + foreach (var op in o.OrderProcedures) + { + if(op.Value.Id == p.Id) + { + filteredOrders.Add(o); break; + } + } + } + } + + HashSet laborcosts = new HashSet(); + var cosmetics = _cosmeticLogic.ReadList(null); + + foreach(var c in cosmetics) + { + foreach(var s in c.CosmeticServices) + { + if(s.Value.Id == service.Id) + { + laborcosts.Add(c.LaborCostId); + break; + } + } + } + + + + report.Orders = filteredOrders.Select(w => w.Id.ToString()).ToList(); + foreach (int l in laborcosts) + { + report.LaborCosts.Add(l.ToString()); + } + + serviceTimeReports.Add(report); + } + return serviceTimeReports; + } + + public List? GetProcedureReports(List cosmetics) + { + List reports = new(); + foreach (int i in cosmetics) + { + ReportCosmeticViewModel report = new(); + var cosmetic = _cosmeticLogic.ReadElement(new() { Id = i }); + report.CosmeticName = cosmetic!.CosmeticName; + var procedures = _procedureLogic.ReadList(null); + + HashSet filteredProcedures = new HashSet(); + + if (cosmetic.CosmeticServices != null && procedures != null) + { + var servicesC = new HashSet(cosmetic.CosmeticServices.Values); + + foreach (var procedure in procedures) + { + if (procedure.ProcedureServices != null) + { + var servicesP = new HashSet(procedure.ProcedureServices.Values); + foreach (IServiceModel serv in servicesP) + { + foreach(IServiceModel s in servicesC) + { + if (s.Id == serv.Id) + { + filteredProcedures.Add(procedure); + break; + } + } + } + } + } + } + + report.Procedures = filteredProcedures.Select(w => w.ProcedureName).ToList(); + reports.Add(report); + } + return reports; + } + + public void SaveReportExcel(List services, MemoryStream stream) + { + var reports = GetProcedureReports(services); + if (reports == null) + return; + int maxsize = 0; + foreach (var report in reports) { maxsize = Math.Max(maxsize, report.Procedures.Count); } + _excel.CreateReport(new() + { + cosmeticProceduresReport = reports, + Title = "Отчет Косметика-Процедуры", + memoryStream = stream, + maxleng = maxsize + }); + } + + public void SaveReportWord(List services, MemoryStream stream) + { + var reports = GetProcedureReports(services); + if (reports == null) + return; + _word.CreateDoc(new() + { + memoryStream = stream, + Title = "Отчет. Косметика-Процедуры", + cosmeticProceduresReport = reports + }); + } + + public void SendMailReport(DateTime? startDate, DateTime? endDate, int UserId, MemoryStream stream) + { + var reports = GetTimeReport(startDate, endDate, UserId); + if (reports == null) + return; + _pdf.CreateReport(new() + { + DateFrom = startDate!.Value, + DateTo = endDate!.Value, + FileName = stream, + Services = reports, + Title = "Отчет" + }); + byte[] report = stream.GetBuffer(); + _mail.MailSendAsync(new() { MailAddress = UserStoreKeeper.user!.StoreKeeperEmail, Subject = "Отчет", FileName = "PdfReport.pdf", Pdf = report }); + } + + + + } +} diff --git a/BeautyStudio/StoreKeeperWebApp/StoreKeeperWebApp.csproj b/BeautyStudio/StoreKeeperWebApp/StoreKeeperWebApp.csproj index 1799b73..dc6c9d5 100644 --- a/BeautyStudio/StoreKeeperWebApp/StoreKeeperWebApp.csproj +++ b/BeautyStudio/StoreKeeperWebApp/StoreKeeperWebApp.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -9,6 +9,7 @@ + diff --git a/BeautyStudio/StoreKeeperWebApp/UserStorekeeper.cs b/BeautyStudio/StoreKeeperWebApp/UserStorekeeper.cs new file mode 100644 index 0000000..6f99365 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/UserStorekeeper.cs @@ -0,0 +1,9 @@ +using BeautyStudioContracts.ViewModels; + +namespace StoreKeeperWebApp +{ + public static class UserStoreKeeper + { + public static StoreKeeperViewModel? user { get; set; } + } +} diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml deleted file mode 100644 index 16e0455..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/Cosmetics.cshtml +++ /dev/null @@ -1,68 +0,0 @@ -@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/CreateCosmetics.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/CreateCosmetics.cshtml deleted file mode 100644 index 521b250..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/CreateCosmetics.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@{ - ViewData["Title"] = "Создание косметики"; -} - -
-

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

-
- -
- -
-
Название:
-
-
- - -
-
Цена:
-
-
- - -
-
Трудозатрата:
-
- -
-
- - -
-
-
-
-
- diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/UpdateCosmetics.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/UpdateCosmetics.cshtml deleted file mode 100644 index a1eb9fb..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Cosmetic/UpdateCosmetics.cshtml +++ /dev/null @@ -1,45 +0,0 @@ -@using BeautyStudioContracts.ViewModels - -@model CosmeticViewModel - -@{ - ViewData["Title"] = "Редактирование косметики"; -} - -
-

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

-
- -
- -
-
Название:
-
-
- - -
-
Цена:
-
-
- - -
-
Трудозатрата:
-
- -
-
- - -
-
-
-
-
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/AddServicesCosmetic.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/AddServicesCosmetic.cshtml new file mode 100644 index 0000000..88039ff --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/AddServicesCosmetic.cshtml @@ -0,0 +1,29 @@ +@{ + ViewData["Title"] = "AddServicesCosmetic"; +} +
+

Выбрать услугу к косметике

+
+
+
+
Услуга
+
+ +
+
+
+
Косметика
+
+ +
+
+
+
Количество:
+
+ +
+
+
+ +
+
\ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/CosmeticProcedureChoose.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/CosmeticProcedureChoose.cshtml new file mode 100644 index 0000000..6c08e2d --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/CosmeticProcedureChoose.cshtml @@ -0,0 +1,54 @@ +@using BeautyStudioContracts.ViewModels; +@model List + +@{ + ViewData["Title"] = "Выбор косметики для отчета"; +} + +

Выберите детали для отчета

+ +
+ + + + + + + + + @for (int i = 0; i < Model.Count; i++) + { + + + + + } + +
SelectВыберите косметику:
+ + @Model[i].CosmeticName
+ + + + + +
+ +@section Scripts { + +} \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/CosmeticProceduresReport.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/CosmeticProceduresReport.cshtml new file mode 100644 index 0000000..2a0e08e --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/CosmeticProceduresReport.cshtml @@ -0,0 +1,35 @@ +@using BeautyStudioContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Отчет косметика - процедуры"; +} +
+

Список косметики с процедурами

+
+ + + + + + + + + + @foreach (var detail in Model) + { + + + + + } + +
КосметикаПроцедуры
@detail.CosmeticName +
    + @foreach (var workshop in detail.Procedures) + { +
  • @workshop
  • + } +
+
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateCosmetic.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateCosmetic.cshtml new file mode 100644 index 0000000..1c61b84 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateCosmetic.cshtml @@ -0,0 +1,169 @@ +@using BeautyStudioContracts.ViewModels; +@using BeautyStudioDataModels.Enums; + +@model CosmeticViewModel + +@{ + ViewData["Title"] = "CreateCosmetic"; + ViewBag.Services = Model.CosmeticServices; +} +
+

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

+
+
+
+
+
+
Название:
+
+ + +
+
+
+
Трудозатрата:
+
+ + +
+
+
+
Детали
+
+ + + + + + + + + + + + @foreach (var service in ViewBag.Services) + { + + + + + + + + } + +
ID услуги Стоимость Удалить
+ @service.Value.Id + @service.Value.ServicePrice
+
+ + +
+
+
Сумма:
+
+
+
+
+
+
+
+ + + + + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateLaborCost.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateLaborCost.cshtml new file mode 100644 index 0000000..4f52e7a --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateLaborCost.cshtml @@ -0,0 +1,65 @@ +@using BeautyStudioContracts.ViewModels; +@using BeautyStudioDataModels.Enums; + +@model LaborCostViewModel; + +@{ + ViewData["Title"] = "CreateLaborCost"; +} +
+

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

+
+
+ +
+
Сложность:
+
+ + +
+
+
+
Количество часов:
+
+ + +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateService.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateService.cshtml new file mode 100644 index 0000000..b52a12c --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/CreateService.cshtml @@ -0,0 +1,133 @@ +@using BeautyStudioContracts.ViewModels; +@using BeautyStudioDataModels.Enums; +@{ + ViewData["Title"] = "CreateService"; + ViewBag.Procedures = Model.ServiceProcedures; +} +@model ServiceViewModel; +
+

Услуга

+
+
+ +
+
Название:
+
+ + +
+
+ + @if (ViewBag.AllProcedures != null && ViewBag.AllProcedures.Count != 0) + { +
+
Процедуры
+
+ + + + + + + + + + @foreach (var procedure in ViewBag.Procedures) + { + + + + + + } + +
ID процедуры Удалить
+ @procedure.Value.Id +
+
+ + +
+ } +
+
Цена:
+
+ + +
+
+
+
+
+
+
+ + + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexCosmetic.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexCosmetic.cshtml new file mode 100644 index 0000000..412b2d0 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexCosmetic.cshtml @@ -0,0 +1,64 @@ +@using BeautyStudioContracts.ViewModels; + +@model List + +@{ + ViewData["Title"] = "Cosmetic"; +} + +
+

Косметика

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

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

+ return; + } +

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

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер + + Название + + Изменить косметику + + Удалить косметику +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.CosmeticName) + + Изменить + +
+ + +
+
+ } +
\ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexLaborCost.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexLaborCost.cshtml new file mode 100644 index 0000000..fadfa14 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexLaborCost.cshtml @@ -0,0 +1,70 @@ +@using BeautyStudioContracts.ViewModels; + +@model List + +@{ + ViewData["Title"] = "LaborCosts"; +} + +
+

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

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

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

+ return; + } +

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

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ Номер + + Сложность + + Количество затраченного времени + + Изменить трудозатрату + + Удалить трудозатрату +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Difficulty) + + @Html.DisplayFor(modelItem => item.TimeSpent) + + Изменить + +
+ + +
+
+ } +
\ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexNonReg.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexNonReg.cshtml new file mode 100644 index 0000000..c99fc31 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexNonReg.cshtml @@ -0,0 +1,8 @@ +@{ + ViewData["Title"] = "Home Page"; +} + +
+

StoreKeeperApp "Вы ужасны". Добро пожаловать!

+

Войдите или зарегистрируйтесь

+
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexService.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexService.cshtml new file mode 100644 index 0000000..0a1c04c --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/IndexService.cshtml @@ -0,0 +1,70 @@ +@using BeautyStudioContracts.ViewModels; + +@model List + +@{ + ViewData["Title"] = "Services"; +} + +
+

Услуги

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

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

+ return; + } +

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

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ Номер + + Название + + Цена + + Изменить услугу + + Удалить услугу +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.ServiceName) + + @Html.DisplayFor(modelItem => item.ServicePrice) + + Изменить + +
+ + +
+
+ } +
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/Privacy.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/Privacy.cshtml index af4fb19..bec2dd4 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Home/Privacy.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/Privacy.cshtml @@ -1,6 +1,102 @@ -@{ - ViewData["Title"] = "Privacy Policy"; +@{ + ViewData["Title"] = "Register"; } -

@ViewData["Title"]

+
+

Данные пользователя:

+
+
+
+
Полное имя:
+
+ + +
+
+
+
Логин:
+
+ + +
+
+
+
Пароль:
+
+ + +
+
+
+
Почта:
+
+ + +
+
+
+
Номер телефона:
+
+ + +
+
+
-

Use this page to detail your site's privacy policy.

+ + \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/Register.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/Register.cshtml index 0a3163d..5049f43 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Home/Register.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/Register.cshtml @@ -5,28 +5,99 @@

Регистрация

- -
- - +
+
Ваше полное имя:
+
+ + +
-
- - +
+
Почта:
+
+ + +
-
- - +
+
Пароль:
+
+ + +
- -
- - +
+
Повтор пароля:
+
+ + +
- -
- +
+
Номер телефона:
+
+ + +
+
+
+
+
+ + + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/ReportMenu.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/ReportMenu.cshtml new file mode 100644 index 0000000..f407168 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/ReportMenu.cshtml @@ -0,0 +1,11 @@ +@{ + ViewData["Title"] = "Report Menu"; +} + +
+

Меню создания отчетов

+ +
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/Reports.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/Reports.cshtml deleted file mode 100644 index d5a02cd..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Home/Reports.cshtml +++ /dev/null @@ -1,93 +0,0 @@ -@using BeautyStudioContracts.ViewModels -@model List - -@{ - ViewBag.Title = "Отчеты"; -} - -
-

Отчеты

-
- -
-
- -
- -
- - -
- -
- - -
- -
- -
- - -
-
- -
-
-
- - -
-

Список услуг:

-
- - - - - - - - - - @if (Model == null || Model.Count <= 0) - { - - } - else - { - foreach (var record in Model) - { - - - - - // Конвертируем из HashSet в List, чтобы можно было обращаться по индексу - var cosmetics = new List(); - foreach (var kvp in record.Cosmetics) - { - var cosmeticModel = kvp.Value.Item1; - cosmetics.Add(cosmeticModel.CosmeticName); - } - var procedures = new List(); - foreach (var kvp in record.Procedures) - { - var procedureModel = kvp.Value.Item1; - procedures.Add(procedureModel.ProcedureName); - } - - - // Записываем названия лекарств во 2 колонку - // и названия лекарств в 3 колонку - int maxLength = Math.Max(cosmetics.Count, procedures.Count); - for (int i = 0; i < maxLength; i++) - { - - - - - - } - } - } - -
УслугаПроцедурыКосметика
Нет доступных данных@record.ServiceName
@(i < cosmetics.Count ? cosmetics[i] : "")@(i < procedures.Count ? procedures[i] : "")
\ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/ServiceTimeChoose.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/ServiceTimeChoose.cshtml new file mode 100644 index 0000000..9e439c0 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/ServiceTimeChoose.cshtml @@ -0,0 +1,85 @@ +@{ + ViewData["Title"] = "Создание отчета"; +} + +
+

Создание отчета

+
+
+
+
+ +
+
+ + +
+
+
+
+ +
+
+ + +
+
+
+
+ +
+
+
+ + + diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Home/ServiceTimeReport.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Home/ServiceTimeReport.cshtml new file mode 100644 index 0000000..6d87742 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/Views/Home/ServiceTimeReport.cshtml @@ -0,0 +1,50 @@ +@using BeautyStudioContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Services on Time Services"; +} + +
+

Список услуг в диапазоне времени

+
+ +
+ +
+ + + + + + + + + + + + @foreach (var detail in Model) + { + + + + + + } + +
УслугаЗаказТрудозатрата
@detail.Id +
    + @foreach (var product in detail.Orders) + { +
  • @product
  • + } +
+
+
    + @foreach (var production in detail.LaborCosts) + { +
  • @production
  • + } +
+
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/CreateLaborCosts.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/CreateLaborCosts.cshtml deleted file mode 100644 index b21c0f3..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/CreateLaborCosts.cshtml +++ /dev/null @@ -1,38 +0,0 @@ -@{ - ViewData["Title"] = "Трудозатраты"; -} - -
-

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

-
- -
-
-
Количество часов:
-
-
- -
-
Сложность:
-
-
- -
-
Косметика:
-
- -
-
- - -
-
-
-
-
- diff --git a/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/LaborCosts.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/LaborCosts.cshtml deleted file mode 100644 index 5649d9b..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/LaborCosts.cshtml +++ /dev/null @@ -1,68 +0,0 @@ -@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/LaborCost/UpdateLaborCosts.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/UpdateLaborCosts.cshtml deleted file mode 100644 index 17e26d2..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/LaborCost/UpdateLaborCosts.cshtml +++ /dev/null @@ -1,29 +0,0 @@ -@using BeautyStudioContracts.ViewModels - -@model LaborCostViewModel - -@{ - ViewData["Title"] = "Редактирование трудозатрат"; -} - -
-

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

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

Привязка процедуры к услуге

-
-
-
- - -
-
- - -
-
- -
-
\ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Service/CreateServices.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/CreateServices.cshtml deleted file mode 100644 index 0d1697a..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Service/CreateServices.cshtml +++ /dev/null @@ -1,47 +0,0 @@ -@{ - ViewData["Title"] = "Создание услуг"; -} - -
-

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

-
- -
-
-
Название:
-
-
-
-
Цена:
-
-
- -
-
Процедуры:
-
- -
-
-
-
Косметика:
-
- -
-
- - -
-
-
-
-
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml deleted file mode 100644 index ad0f2fc..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Service/Services.cshtml +++ /dev/null @@ -1,67 +0,0 @@ -@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/UpdateServices.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Service/UpdateServices.cshtml deleted file mode 100644 index 9878179..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Service/UpdateServices.cshtml +++ /dev/null @@ -1,54 +0,0 @@ -@using BeautyStudioContracts.ViewModels - -@model ServiceViewModel - -@{ - ViewData["Title"] = "Редактирование услуг"; -} - -
-

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

-
- -
-
-
Название:
-
-
-
-
Цена:
-
-
- -
-
Процедуры:
-
- -
-
-
-
Косметика:
-
- -
-
- - -
-
-
-
-
- diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Shared/AddProcedureToService.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Shared/AddProcedureToService.cshtml deleted file mode 100644 index 8df877c..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Shared/AddProcedureToService.cshtml +++ /dev/null @@ -1,24 +0,0 @@ - -@{ - ViewData["Title"] = "AddProcedureToService"; -} - - - - -
-

Привязка процедуры к услуге

-
-
-
- - -
-
- - -
-
- -
-
\ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Shared/UpdateLaborCosts.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Shared/UpdateLaborCosts.cshtml deleted file mode 100644 index 605c2ce..0000000 --- a/BeautyStudio/StoreKeeperWebApp/Views/Shared/UpdateLaborCosts.cshtml +++ /dev/null @@ -1,29 +0,0 @@ -@using BeautyStudioContracts.ViewModels - -@model LaborCostViewModel - -@{ - ViewData["Title"] = "Редактирование трудозатраты"; -} - -
-

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

-
- -
-
-
Потрачено времени (часов):
-
-
- -
-
Сложность:
-
-
- - -
-
-
-
-
diff --git a/BeautyStudio/StoreKeeperWebApp/Views/Shared/_Layout.cshtml b/BeautyStudio/StoreKeeperWebApp/Views/Shared/_Layout.cshtml index 0f8fe03..2eb40c6 100644 --- a/BeautyStudio/StoreKeeperWebApp/Views/Shared/_Layout.cshtml +++ b/BeautyStudio/StoreKeeperWebApp/Views/Shared/_Layout.cshtml @@ -29,19 +29,22 @@ Авторизация +
diff --git a/BeautyStudio/StoreKeeperWebApp/appsettings.json b/BeautyStudio/StoreKeeperWebApp/appsettings.json index 4702e80..7666d6d 100644 --- a/BeautyStudio/StoreKeeperWebApp/appsettings.json +++ b/BeautyStudio/StoreKeeperWebApp/appsettings.json @@ -11,5 +11,5 @@ "PopHost": "pop.gmail.com", "PopPort": "995", "MailLogin": "rpplabs724@gmail.com", - "MailPassword": "tdqp zkqz avzv yebn" + "MailPassword": "tlta buqp gljg jiso" } diff --git a/BeautyStudio/StoreKeeperWebApp/libman.json b/BeautyStudio/StoreKeeperWebApp/libman.json deleted file mode 100644 index ceee271..0000000 --- a/BeautyStudio/StoreKeeperWebApp/libman.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": "1.0", - "defaultProvider": "cdnjs", - "libraries": [] -} \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/log4net.config b/BeautyStudio/StoreKeeperWebApp/log4net.config new file mode 100644 index 0000000..e17bf81 --- /dev/null +++ b/BeautyStudio/StoreKeeperWebApp/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BeautyStudio/StoreKeeperWebApp/nlog.config b/BeautyStudio/StoreKeeperWebApp/nlog.config deleted file mode 100644 index 700fddf..0000000 --- a/BeautyStudio/StoreKeeperWebApp/nlog.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file