From 3d1fb5c06734af2d34f2d802443ae52a35bd7261 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Thu, 18 Apr 2024 11:16:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sushi/Sushi/FormCreateOrder.Designer.cs | 64 +++++++++-- Sushi/Sushi/FormCreateOrder.cs | 80 ++++++------- Sushi/Sushi/FormMain.Designer.cs | 18 ++- Sushi/Sushi/FormMain.cs | 108 +++++++++++++----- Sushi/Sushi/FormSushi.cs | 3 +- Sushi/Sushi/FormSushiComponent.cs | 3 +- Sushi/Sushi/Program.cs | 1 + Sushi/SushiBusinessLogic/OrderLogic.cs | 62 +++++----- Sushi/SushiBusinessLogic/SushiLogic.cs | 2 +- .../BusinessLogicContracts/IOrderLogic.cs | 8 +- .../ViewModels/OrderViewModel.cs | 6 + Sushi/SushiDataModels/IOrderModel.cs | 2 + .../Implement/OrderStorage.cs | 22 +++- ... 20240404102840_InitialCreate.Designer.cs} | 14 ++- ...ate.cs => 20240404102840_InitialCreate.cs} | 10 +- .../Migrations/SushiDatabaseModelSnapshot.cs | 12 +- Sushi/SushiDatabaseImplement/Models/Order.cs | 10 ++ 17 files changed, 281 insertions(+), 144 deletions(-) rename Sushi/SushiDatabaseImplement/Migrations/{20240403234311_InitialCreate.Designer.cs => 20240404102840_InitialCreate.Designer.cs} (94%) rename Sushi/SushiDatabaseImplement/Migrations/{20240403234311_InitialCreate.cs => 20240404102840_InitialCreate.cs} (96%) diff --git a/Sushi/Sushi/FormCreateOrder.Designer.cs b/Sushi/Sushi/FormCreateOrder.Designer.cs index 492078c..1b52ba4 100644 --- a/Sushi/Sushi/FormCreateOrder.Designer.cs +++ b/Sushi/Sushi/FormCreateOrder.Designer.cs @@ -34,8 +34,12 @@ labelSushi = new Label(); labelClient = new Label(); labelEmployee = new Label(); + labelSum = new Label(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + labelCount = new Label(); SuspendLayout(); // // comboBoxSushi @@ -46,6 +50,8 @@ comboBoxSushi.Name = "comboBoxSushi"; comboBoxSushi.Size = new Size(353, 28); comboBoxSushi.TabIndex = 0; + comboBoxSushi.SelectedIndexChanged += ComboBoxRepair_SelectedIndexChanged; + comboBoxSushi.Click += ComboBoxRepair_SelectedIndexChanged; // // comboBoxClient // @@ -59,7 +65,7 @@ // comboBoxEmployee // comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxEmployee.Location = new Point(130, 87); + comboBoxEmployee.Location = new Point(130, 123); comboBoxEmployee.Name = "comboBoxEmployee"; comboBoxEmployee.Size = new Size(353, 28); comboBoxEmployee.TabIndex = 8; @@ -69,9 +75,9 @@ labelSushi.AutoSize = true; labelSushi.Location = new Point(21, 22); labelSushi.Name = "labelSushi"; - labelSushi.Size = new Size(54, 20); + labelSushi.Size = new Size(46, 20); labelSushi.TabIndex = 3; - labelSushi.Text = "Услуга"; + labelSushi.Text = "Суши"; // // labelClient // @@ -85,11 +91,38 @@ // labelEmployee // labelEmployee.AutoSize = true; - labelEmployee.Location = new Point(21, 90); + labelEmployee.Location = new Point(21, 123); labelEmployee.Name = "labelEmployee"; - labelEmployee.Size = new Size(60, 20); + labelEmployee.Size = new Size(80, 20); labelEmployee.TabIndex = 3; - labelEmployee.Text = "Мастер"; + labelEmployee.Text = "Официант"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(306, 93); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(58, 20); + labelSum.TabIndex = 3; + labelSum.Text = "Сумма:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(130, 87); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(170, 27); + textBoxCount.TabIndex = 4; + textBoxCount.Click += TextBoxCount_TextChanged; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(370, 90); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(113, 27); + textBoxSum.TabIndex = 5; + textBoxSum.TextChanged += TextBoxSum_TextChanged; // // buttonSave // @@ -111,15 +144,28 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // - // FormCreateAppointment + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(21, 90); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 10; + labelCount.Text = "Количество"; + // + // FormCreateOrder // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(515, 202); + Controls.Add(labelCount); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(labelSushi); Controls.Add(comboBoxSushi); + Controls.Add(textBoxCount); + Controls.Add(textBoxSum); + Controls.Add(labelSum); Controls.Add(labelEmployee); Controls.Add(comboBoxEmployee); Controls.Add(labelClient); @@ -139,7 +185,11 @@ private Label labelSushi; private Label labelClient; private Label labelEmployee; + private Label labelSum; + private TextBox textBoxCount; + private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; + private Label labelCount; } } \ No newline at end of file diff --git a/Sushi/Sushi/FormCreateOrder.cs b/Sushi/Sushi/FormCreateOrder.cs index fbc06d3..3cb376e 100644 --- a/Sushi/Sushi/FormCreateOrder.cs +++ b/Sushi/Sushi/FormCreateOrder.cs @@ -62,59 +62,59 @@ namespace Sushi MessageBoxIcon.Error); } } - //private void CalcSum() - //{ - // if (comboBoxRepair.SelectedValue != null && - // !string.IsNullOrEmpty(textBoxCount.Text)) - // { - // try - // { - // int id = Convert.ToInt32(comboBoxRepair.SelectedValue); - // var repair = _logicS.ReadElement(new SushiSearchModel - // { - // Id - // = id - // }); - // int count = Convert.ToInt32(textBoxCount.Text); - // textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0), - // 2).ToString(); - // _logger.LogInformation("Расчет суммы заказа"); - // } - // catch (Exception ex) - // { - // _logger.LogError(ex, "Ошибка расчета суммы заказа"); - // MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - // MessageBoxIcon.Error); - // } - // } - //} - //private void TextBoxCount_TextChanged(object sender, EventArgs e) - //{ - // CalcSum(); - //} - //private void TextBoxSum_TextChanged(object sender, EventArgs e) - //{ - // CalcSum(); - //} - //private void ComboBoxRepair_SelectedIndexChanged(object sender, EventArgs e) - //{ - // CalcSum(); - //} + private void CalcSum() + { + if (comboBoxSushi.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSushi.SelectedValue); + var repair = _logicS.ReadElement(new SushiSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void TextBoxSum_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxRepair_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } private void ButtonSave_Click(object sender, EventArgs e) { if (comboBoxSushi.SelectedValue == null || comboBoxClient.SelectedValue == null || comboBoxEmployee.SelectedValue == null) { - MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите блюдо", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Создание заказа"); try { - var operationResult = _logicO.Create(new OrderBindingModel + var operationResult = _logicO.CreateOrder(new OrderBindingModel { SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), EmployeeId = Convert.ToInt32(comboBoxEmployee.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text), Time = DateTime.UtcNow }); if (!operationResult) diff --git a/Sushi/Sushi/FormMain.Designer.cs b/Sushi/Sushi/FormMain.Designer.cs index 6096e83..7f923d1 100644 --- a/Sushi/Sushi/FormMain.Designer.cs +++ b/Sushi/Sushi/FormMain.Designer.cs @@ -49,7 +49,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1209, 28); + menuStrip.Size = new Size(1547, 28); menuStrip.TabIndex = 0; menuStrip.Text = "Меню справочников"; // @@ -85,7 +85,7 @@ // мастераToolStripMenuItem.Name = "мастераToolStripMenuItem"; мастераToolStripMenuItem.Size = new Size(224, 26); - мастераToolStripMenuItem.Text = "Мастера"; + мастераToolStripMenuItem.Text = "Официант"; мастераToolStripMenuItem.Click += EmployeesStripMenuItem_Click; // // dataGridView @@ -95,12 +95,12 @@ dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(970, 419); + dataGridView.Size = new Size(1235, 419); dataGridView.TabIndex = 1; // // buttonCreate // - buttonCreate.Location = new Point(999, 46); + buttonCreate.Location = new Point(1309, 55); buttonCreate.Name = "buttonCreate"; buttonCreate.Size = new Size(187, 37); buttonCreate.TabIndex = 2; @@ -110,27 +110,25 @@ // // buttonUpdate // - buttonUpdate.Location = new Point(999, 123); + buttonUpdate.Location = new Point(1309, 136); buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Size = new Size(187, 37); buttonUpdate.TabIndex = 3; buttonUpdate.Text = "Отдать на выполнение"; buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += ButtonUpd_Click; // // buttonDelete // - buttonDelete.Location = new Point(999, 196); + buttonDelete.Location = new Point(1309, 216); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(187, 37); buttonDelete.TabIndex = 4; buttonDelete.Text = "Заказ готов"; buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += ButtonDelete_Click; // // buttonRefresh // - buttonRefresh.Location = new Point(999, 272); + buttonRefresh.Location = new Point(1309, 303); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(187, 37); buttonRefresh.TabIndex = 6; @@ -142,7 +140,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1209, 450); + ClientSize = new Size(1547, 450); Controls.Add(buttonRefresh); Controls.Add(buttonDelete); Controls.Add(buttonUpdate); diff --git a/Sushi/Sushi/FormMain.cs b/Sushi/Sushi/FormMain.cs index 72734e4..f9504f5 100644 --- a/Sushi/Sushi/FormMain.cs +++ b/Sushi/Sushi/FormMain.cs @@ -2,6 +2,8 @@ using Microsoft.Extensions.Logging; using SushiContracts.BindingModels; using SushiContracts.BusinessLogicsContracts; +using SushiBusinessLogic; +using SushiDataModels.Enums; namespace Sushi { @@ -57,10 +59,12 @@ namespace Sushi if (list != null) { dataGridView.DataSource = list; - dataGridView.Columns["ServiceId"].Visible = false; + dataGridView.Columns["SushiId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["EmployeeId"].Visible = false; - dataGridView.Columns["ServiceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["EmployeeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -90,50 +94,94 @@ namespace Sushi } } - private void ButtonUpd_Click(object sender, EventArgs e) + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //EmployeeId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["EmployeeId"].Value), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - LoadData(); + var operationResult = _OrderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } - - private void ButtonDelete_Click(object sender, EventArgs e) + private void ButtonOrderReady_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); - try + var operationResult = _OrderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) { - if (!_OrderLogic.Delete(new OrderBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _OrderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } - private void RefreshButton_Click(object sender, EventArgs e) { LoadData(); diff --git a/Sushi/Sushi/FormSushi.cs b/Sushi/Sushi/FormSushi.cs index 709efa8..61ba9a7 100644 --- a/Sushi/Sushi/FormSushi.cs +++ b/Sushi/Sushi/FormSushi.cs @@ -71,8 +71,7 @@ namespace Sushi } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); if (service is FormSushiComponent form) { if (form.ShowDialog() == DialogResult.OK) diff --git a/Sushi/Sushi/FormSushiComponent.cs b/Sushi/Sushi/FormSushiComponent.cs index 1f282b5..1470dc4 100644 --- a/Sushi/Sushi/FormSushiComponent.cs +++ b/Sushi/Sushi/FormSushiComponent.cs @@ -1,5 +1,4 @@ - -using SushiContracts.BusinessLogicContracts; +using SushiContracts.BusinessLogicContracts; using SushiContracts.ViewModels; using SushiDataModels; diff --git a/Sushi/Sushi/Program.cs b/Sushi/Sushi/Program.cs index bc914a5..175cab6 100644 --- a/Sushi/Sushi/Program.cs +++ b/Sushi/Sushi/Program.cs @@ -56,6 +56,7 @@ namespace Sushi services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); } diff --git a/Sushi/SushiBusinessLogic/OrderLogic.cs b/Sushi/SushiBusinessLogic/OrderLogic.cs index dd1082f..a29d790 100644 --- a/Sushi/SushiBusinessLogic/OrderLogic.cs +++ b/Sushi/SushiBusinessLogic/OrderLogic.cs @@ -22,7 +22,8 @@ namespace SushiBusinessLogic public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + var list = model == null ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -32,26 +33,11 @@ namespace SushiBusinessLogic return list; } - public OrderViewModel? ReadElement(OrderSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); - var element = _orderStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - - public bool Create(OrderBindingModel model) + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -60,27 +46,39 @@ namespace SushiBusinessLogic return true; } - public bool Delete(OrderBindingModel model) + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_orderStorage.Delete(model) == null) + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) { - _logger.LogWarning("Delete operation failed"); + _logger.LogWarning("Read operation failed"); return false; } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); return true; } - public bool Update(OrderBindingModel model) + public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model); - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); } private void CheckModel(OrderBindingModel model, bool withParams = true) diff --git a/Sushi/SushiBusinessLogic/SushiLogic.cs b/Sushi/SushiBusinessLogic/SushiLogic.cs index d829276..aadf2e2 100644 --- a/Sushi/SushiBusinessLogic/SushiLogic.cs +++ b/Sushi/SushiBusinessLogic/SushiLogic.cs @@ -97,7 +97,7 @@ namespace SushiBusinessLogic } if (model.Price <= 0) { - throw new ArgumentNullException("Цена блюдо должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена блюдa должна быть больше 0", nameof(model.Price)); } _logger.LogInformation("Dish. Dish:{Dish}. Price:{ Price }. Id: { Id}", model.SushiName, model.Price, model.Id); var element = _DishStorage.GetElement(new SushiSearchModel diff --git a/Sushi/SushiContracts/BusinessLogicContracts/IOrderLogic.cs b/Sushi/SushiContracts/BusinessLogicContracts/IOrderLogic.cs index f45a5f6..033d60d 100644 --- a/Sushi/SushiContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/Sushi/SushiContracts/BusinessLogicContracts/IOrderLogic.cs @@ -7,10 +7,10 @@ namespace SushiContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - OrderViewModel? ReadElement(OrderSearchModel model); - bool Create(OrderBindingModel model); - bool Update(OrderBindingModel model); - bool Delete(OrderBindingModel model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); } } diff --git a/Sushi/SushiContracts/ViewModels/OrderViewModel.cs b/Sushi/SushiContracts/ViewModels/OrderViewModel.cs index 28fb3c2..d84ce4b 100644 --- a/Sushi/SushiContracts/ViewModels/OrderViewModel.cs +++ b/Sushi/SushiContracts/ViewModels/OrderViewModel.cs @@ -8,6 +8,12 @@ namespace SushiContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int ClientId { get; set; } + [DisplayName("Имя клиента")] + public string ClientName { get; set; } = string.Empty; + public int EmployeeId { get; set; } + [DisplayName("Имя сотрудника")] + public string EmployeeName { get; set; } = string.Empty; public int SushiId { get; set; } [DisplayName("Блюдо")] public string SushiName { get; set; } = string.Empty; diff --git a/Sushi/SushiDataModels/IOrderModel.cs b/Sushi/SushiDataModels/IOrderModel.cs index 069fbee..9e72a0a 100644 --- a/Sushi/SushiDataModels/IOrderModel.cs +++ b/Sushi/SushiDataModels/IOrderModel.cs @@ -5,6 +5,8 @@ namespace SushiDataModels public interface IOrderModel { int SushiId { get; } + int ClientId { get; } + int EmployeeId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/Sushi/SushiDatabaseImplement/Implement/OrderStorage.cs b/Sushi/SushiDatabaseImplement/Implement/OrderStorage.cs index 7c84f52..a81cf02 100644 --- a/Sushi/SushiDatabaseImplement/Implement/OrderStorage.cs +++ b/Sushi/SushiDatabaseImplement/Implement/OrderStorage.cs @@ -81,11 +81,27 @@ namespace SushiShopDatabaseImplement.Implements if (model == null) return null; using var context = new SushiDatabase(); - foreach (var Sushis in context.Sushies) + foreach (var Sushies in context.Sushies) { - if (Sushis.Id == model.SushiId) + if (Sushies.Id == model.SushiId) { - model.SushiName = Sushis.SushiName; + model.SushiName = Sushies.SushiName; + break; + } + } + foreach (var Clients in context.Clients) + { + if (Clients.Id == model.ClientId) + { + model.ClientName = Clients.ClientName; + break; + } + } + foreach (var Employees in context.Employees) + { + if (Employees.Id == model.EmployeeId) + { + model.EmployeeName = Employees.EmployeeName; break; } } diff --git a/Sushi/SushiDatabaseImplement/Migrations/20240403234311_InitialCreate.Designer.cs b/Sushi/SushiDatabaseImplement/Migrations/20240404102840_InitialCreate.Designer.cs similarity index 94% rename from Sushi/SushiDatabaseImplement/Migrations/20240403234311_InitialCreate.Designer.cs rename to Sushi/SushiDatabaseImplement/Migrations/20240404102840_InitialCreate.Designer.cs index aa4fe38..308deb6 100644 --- a/Sushi/SushiDatabaseImplement/Migrations/20240403234311_InitialCreate.Designer.cs +++ b/Sushi/SushiDatabaseImplement/Migrations/20240404102840_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using SushiDatabaseImplement; namespace SushiDatabaseImplement.Migrations { [DbContext(typeof(SushiDatabase))] - [Migration("20240403234311_InitialCreate")] + [Migration("20240404102840_InitialCreate")] partial class InitialCreate { /// @@ -114,7 +114,7 @@ namespace SushiDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -126,7 +126,7 @@ namespace SushiDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); - b.Property("EmployeeId") + b.Property("EmployeeId") .HasColumnType("int"); b.Property("Status") @@ -179,11 +179,15 @@ namespace SushiDatabaseImplement.Migrations { b.HasOne("SushiDatabaseImplement.Models.Client", null) .WithMany("Order") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("SushiDatabaseImplement.Models.Employee", null) .WithMany("Order") - .HasForeignKey("EmployeeId"); + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("SushiDatabaseImplement.Models.Sushi", null) .WithMany("Order") diff --git a/Sushi/SushiDatabaseImplement/Migrations/20240403234311_InitialCreate.cs b/Sushi/SushiDatabaseImplement/Migrations/20240404102840_InitialCreate.cs similarity index 96% rename from Sushi/SushiDatabaseImplement/Migrations/20240403234311_InitialCreate.cs rename to Sushi/SushiDatabaseImplement/Migrations/20240404102840_InitialCreate.cs index 6bc9914..26a1c79 100644 --- a/Sushi/SushiDatabaseImplement/Migrations/20240403234311_InitialCreate.cs +++ b/Sushi/SushiDatabaseImplement/Migrations/20240404102840_InitialCreate.cs @@ -79,8 +79,8 @@ namespace SushiDatabaseImplement.Migrations DateCreate = table.Column(type: "datetime2", nullable: false), DateImplement = table.Column(type: "datetime2", nullable: true), SushiId = table.Column(type: "int", nullable: false), - ClientId = table.Column(type: "int", nullable: true), - EmployeeId = table.Column(type: "int", nullable: true) + ClientId = table.Column(type: "int", nullable: false), + EmployeeId = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -89,12 +89,14 @@ namespace SushiDatabaseImplement.Migrations name: "FK_Orders_Clients_ClientId", column: x => x.ClientId, principalTable: "Clients", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Orders_Employees_EmployeeId", column: x => x.EmployeeId, principalTable: "Employees", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Orders_Sushies_SushiId", column: x => x.SushiId, diff --git a/Sushi/SushiDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs b/Sushi/SushiDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs index ce06a59..da9c725 100644 --- a/Sushi/SushiDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs +++ b/Sushi/SushiDatabaseImplement/Migrations/SushiDatabaseModelSnapshot.cs @@ -111,7 +111,7 @@ namespace SushiDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -123,7 +123,7 @@ namespace SushiDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); - b.Property("EmployeeId") + b.Property("EmployeeId") .HasColumnType("int"); b.Property("Status") @@ -176,11 +176,15 @@ namespace SushiDatabaseImplement.Migrations { b.HasOne("SushiDatabaseImplement.Models.Client", null) .WithMany("Order") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("SushiDatabaseImplement.Models.Employee", null) .WithMany("Order") - .HasForeignKey("EmployeeId"); + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("SushiDatabaseImplement.Models.Sushi", null) .WithMany("Order") diff --git a/Sushi/SushiDatabaseImplement/Models/Order.cs b/Sushi/SushiDatabaseImplement/Models/Order.cs index df3310d..2e4bf61 100644 --- a/Sushi/SushiDatabaseImplement/Models/Order.cs +++ b/Sushi/SushiDatabaseImplement/Models/Order.cs @@ -19,6 +19,10 @@ namespace SushiShopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [Required] public int SushiId { get; private set; } + [Required] + public int ClientId { get; private set; } + [Required] + public int EmployeeId { get; private set; } public static Order? Create(OrderBindingModel model) { @@ -31,6 +35,8 @@ namespace SushiShopDatabaseImplement.Models Id = model.Id, Count = model.Count, Sum = model.Sum, + ClientId = model.ClientId, + EmployeeId = model.EmployeeId, Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, @@ -44,6 +50,8 @@ namespace SushiShopDatabaseImplement.Models { return; } + ClientId = model.ClientId; + EmployeeId = model.EmployeeId; Status = model.Status; DateImplement = model.DateImplement; } @@ -51,6 +59,8 @@ namespace SushiShopDatabaseImplement.Models public OrderViewModel GetViewModel => new() { SushiId = SushiId, + ClientId = ClientId, + EmployeeId = EmployeeId, Count = Count, Sum = Sum, Status = Status,