From 249aa8e55191dcf885d8a7a7fcd01ff87cb2da1f Mon Sep 17 00:00:00 2001 From: Anastasia Date: Sat, 13 May 2023 09:52:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=206=20=D0=BB=D0=B0=D0=B1.=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/IOrderModel.cs | 1 + .../JewelryStore/FormMain.Designer.cs | 62 ++--- JewelryStore/JewelryStore/FormMain.cs | 23 +- JewelryStore/JewelryStore/Program.cs | 1 + .../BusinessLogics/OrderLogic.cs | 125 +++++---- .../BusinessLogics/WorkModeling.cs | 140 ++++++++++ .../Views/Home/Create.cshtml | 16 +- .../Views/Home/Index.cshtml | 110 ++++---- .../Views/Home/Privacy.cshtml | 3 +- .../BusinessLogicsContracts/IWorkProcess.cs | 16 ++ .../Implements/ImplementerStorage.cs | 99 +++++++ .../Implements/OrderStorage.cs | 37 ++- .../JewelryStoreDatabase.cs | 1 + .../20230513055059_AddImplementer.Designer.cs | 257 ++++++++++++++++++ .../20230513055059_AddImplementer.cs | 67 +++++ .../JewelryStoreDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 71 +++++ .../Models/Order.cs | 9 +- .../DataFileSingleton.cs | 8 + .../Implements/ImplementerStorage.cs | 108 ++++++++ .../Implements/OrderStorage.cs | 14 +- .../JewelryStoreFileImplement.csproj | 4 + .../Models/Implementer.cs | 86 ++++++ .../JewelryStoreFileImplement/Models/Order.cs | 5 + .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 131 +++++++++ .../Implements/OrderStorage.cs | 19 ++ .../Models/Implementer.cs | 61 +++++ .../JewelryStoreListImplement/Models/Order.cs | 5 +- .../Controllers/ImplementerController.cs | 103 +++++++ 30 files changed, 1440 insertions(+), 187 deletions(-) create mode 100644 JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs create mode 100644 JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs create mode 100644 JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs create mode 100644 JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs create mode 100644 JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Models/Implementer.cs create mode 100644 JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs diff --git a/JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs b/JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs index d0fd099..601e0cb 100644 --- a/JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs +++ b/JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs @@ -8,6 +8,7 @@ namespace JewelryStoreDataModels.Models int JewelId { get; } int Count { get; } double Sum { get; } + int? ImplementerId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/JewelryStore/JewelryStore/FormMain.Designer.cs b/JewelryStore/JewelryStore/FormMain.Designer.cs index 2fb53a5..82e1799 100644 --- a/JewelryStore/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/JewelryStore/FormMain.Designer.cs @@ -36,13 +36,12 @@ this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -53,7 +52,7 @@ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.СправочникиToolStripMenuItem, this.отчетыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.запускРаботToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1121, 33); @@ -64,7 +63,8 @@ // this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.КомпонентыToolStripMenuItem, - this.ИзделияToolStripMenuItem}); + this.ИзделияToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.СправочникиToolStripMenuItem.Text = "Справочники"; @@ -72,14 +72,14 @@ // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.ИзделияToolStripMenuItem.Text = "Изделия"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // @@ -114,6 +114,13 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.СписокЗаказовToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(136, 29); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.ЗапускРаботToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -139,29 +146,9 @@ this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(884, 150); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(210, 34); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(884, 221); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(210, 34); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(884, 292); + this.buttonIssuedOrder.Location = new System.Drawing.Point(884, 160); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(210, 34); this.buttonIssuedOrder.TabIndex = 5; @@ -171,7 +158,7 @@ // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(884, 361); + this.buttonRefresh.Location = new System.Drawing.Point(884, 242); this.buttonRefresh.Name = "buttonRefresh"; this.buttonRefresh.Size = new System.Drawing.Size(210, 34); this.buttonRefresh.TabIndex = 6; @@ -179,12 +166,12 @@ this.buttonRefresh.UseVisualStyleBackColor = true; this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); // - // клиентыToolStripMenuItem + // исполнителиToolStripMenuItem // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(96, 29); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.КлиентыToolStripMenuItem_Click); + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ИсполнителиToolStripMenuItem_Click); // // FormMain // @@ -193,8 +180,6 @@ this.ClientSize = new System.Drawing.Size(1121, 450); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); @@ -218,14 +203,13 @@ private ToolStripMenuItem ИзделияToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem списокИзделийToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; - private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/JewelryStore/JewelryStore/FormMain.cs b/JewelryStore/JewelryStore/FormMain.cs index 4f5f8cd..a16a802 100644 --- a/JewelryStore/JewelryStore/FormMain.cs +++ b/JewelryStore/JewelryStore/FormMain.cs @@ -12,14 +12,15 @@ namespace JewelryStore private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -37,6 +38,7 @@ namespace JewelryStore dataGridView.DataSource = list; dataGridView.Columns["JewelId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -199,5 +201,22 @@ namespace JewelryStore form.ShowDialog(); } } + + private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void ИсполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + } } \ No newline at end of file diff --git a/JewelryStore/JewelryStore/Program.cs b/JewelryStore/JewelryStore/Program.cs index f444c53..db85ec7 100644 --- a/JewelryStore/JewelryStore/Program.cs +++ b/JewelryStore/JewelryStore/Program.cs @@ -46,6 +46,7 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index aeba2c9..e08b552 100644 --- a/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -32,49 +32,54 @@ namespace JewelryStoreBusinessLogic.BusinessLogics return true; } - public bool DeliveryOrder(OrderBindingModel model) + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel + var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); + if (vmodel == null) { - Id = model.Id - }); - if (element == null) + throw new ArgumentNullException(nameof(model)); + } + + if ((int)vmodel.Status + 1 != (int)newStatus) { - _logger.LogWarning("Read operation failed"); + throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " + + $"Текущий статус: {vmodel.Status} \n" + + $"Планируемый статус: {newStatus} \n" + + $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}"); + } + + model.Status = newStatus; + model.DateCreate = vmodel.DateCreate; + if (model.DateImplement == null) + { + model.DateImplement = vmodel.DateImplement; + } + if (vmodel.ImplementerId.HasValue) + { + model.ImplementerId = vmodel.ImplementerId; + } + model.JewelId = vmodel.JewelId; + model.Sum = vmodel.Sum; + model.Count = vmodel.Count; + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; } - if (element.Status != OrderStatus.Готов) - { - _logger.LogWarning("Status change operation failed"); - throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); - } - model.Status = OrderStatus.Выдан; - model.DateImplement = DateTime.Now; - _orderStorage.Update(model); return true; } + public bool DeliveryOrder(OrderBindingModel model) + { + model.DateImplement = DateTime.Now; + return StatusUpdate(model, OrderStatus.Готов); + } + public bool FinishOrder(OrderBindingModel model) { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (element == null) - { - _logger.LogWarning("Read operation failed"); - return false; - } - if (element.Status != OrderStatus.Выполняется) - { - _logger.LogWarning("Status change operation failed"); - throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); - } - model.Status = OrderStatus.Готов; - _orderStorage.Update(model); - return true; + return StatusUpdate(model, OrderStatus.Выдан); } public List? ReadList(OrderSearchModel? model) @@ -92,53 +97,45 @@ namespace JewelryStoreBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (element == null) - { - _logger.LogWarning("Read operation failed"); - return false; - } - if (element.Status != OrderStatus.Принят) - { - _logger.LogWarning("Status change operation failed"); - throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); - } - model.Status = OrderStatus.Выполняется; - _orderStorage.Update(model); - return true; + return StatusUpdate(model, OrderStatus.Выполняется); } - private void CheckModel(OrderBindingModel model, bool withParams = true) + private bool CheckModel(OrderBindingModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - if (!withParams) + if (model.Count <= 0) { - return; + throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); } if (model.Sum <= 0) { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); } - if (model.Count <= 0) + if (model.DateCreate > model.DateImplement) { - throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); } - _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id); - var element = _orderStorage.GetElement(new OrderSearchModel + return true; + } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) { - Id = model.Id - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Заказ с таким ID уже существует"); + 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; } } } \ No newline at end of file diff --git a/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..bd5dfb0 --- /dev/null +++ b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,140 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + + var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} + diff --git a/JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml b/JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml index 3bd3745..4e71a4c 100644 --- a/JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml +++ b/JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml @@ -1,4 +1,4 @@ -@{ +@{ ViewData["Title"] = "Create"; }
@@ -8,12 +8,12 @@
Изделие:
- +
Количество:
-
+
Сумма:
@@ -25,7 +25,7 @@
+ \ No newline at end of file diff --git a/JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml b/JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml index 188284f..e657f98 100644 --- a/JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml +++ b/JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml @@ -1,4 +1,4 @@ -@using JewelryStoreContracts.ViewModels +@using JewelryStoreContracts.ViewModels @model List @{ ViewData["Title"] = "Home Page"; @@ -10,60 +10,60 @@ @{ if (Model == null) { -

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

+

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

return; } -

- Создать заказ -

- - - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - - } - -
- Номер - - Изделие - - Дата создания - - Количество - - Сумма - - Статус -
- @Html.DisplayFor(modelItem => item.Id) - - @Html.DisplayFor(modelItem => item.JewelName) - - @Html.DisplayFor(modelItem => item.DateCreate) - - @Html.DisplayFor(modelItem => item.Count) - - @Html.DisplayFor(modelItem => item.Sum) - - @Html.DisplayFor(modelItem => item.Status) -
+

+ Создать заказ +

+ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
+ Номер + + Изделие + + Дата создания + + Количество + + Сумма + + Статус +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.JewelName) + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.Count) + + @Html.DisplayFor(modelItem => item.Sum) + + @Html.DisplayFor(modelItem => item.Status) +
} -
+ \ No newline at end of file diff --git a/JewelryStore/JewelryStoreClientApp/Views/Home/Privacy.cshtml b/JewelryStore/JewelryStoreClientApp/Views/Home/Privacy.cshtml index 1d4a585..c32eb69 100644 --- a/JewelryStore/JewelryStoreClientApp/Views/Home/Privacy.cshtml +++ b/JewelryStore/JewelryStoreClientApp/Views/Home/Privacy.cshtml @@ -1,4 +1,5 @@ -@model ClientViewModel +@using JewelryStoreContracts.ViewModels +@model ClientViewModel @{ ViewData["Title"] = "Privacy Policy"; } diff --git a/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..bae0fa7 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs b/JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..a3fc2d9 --- /dev/null +++ b/JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,99 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new JewelryStoreDatabase(); + + if (model.Id.HasValue) + { + return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null) + { + return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)&&x.Password.Equals(model.Password)) + ?.GetViewModel; + } + if (model.ImplementerFIO != null) + { + return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (model.ImplementerFIO != null) + { + using var context = new JewelryStoreDatabase(); + return context.Implementers.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel).ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new JewelryStoreDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs b/JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs index 2f1b045..0278588 100644 --- a/JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs +++ b/JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs @@ -17,26 +17,34 @@ namespace JewelryStoreDatabaseImplement.Implements public List GetFullList() { using var context = new JewelryStoreDatabase(); - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (model.Id.HasValue) { - return new(); + var result = GetElement(model); + return result != null ? new() { result } : new(); } using var context = new JewelryStoreDatabase(); - if (model.DateFrom.HasValue) + IQueryable? queryWhere = null; + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel).ToList(); + queryWhere = context.Orders.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate.Date <= model.DateTo); + } + else if (model.Statuses != null) + { + queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status)); } else if (model.ClientId.HasValue) { - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel).ToList(); - } - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId); + } + else + { + return new(); + } + return queryWhere.Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -45,7 +53,8 @@ namespace JewelryStoreDatabaseImplement.Implements return new(); } using var context = new JewelryStoreDatabase(); - return AccessJewelStorage(context.Orders.Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel, context); + return AccessJewelStorage(context.Orders.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x =>(model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || model.Id.HasValue && x.Id == model.Id)?.GetViewModel, context); } public OrderViewModel? Insert(OrderBindingModel model) { @@ -57,12 +66,12 @@ namespace JewelryStoreDatabaseImplement.Implements using var context = new JewelryStoreDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return AccessJewelStorage(context.Orders.Include(x => x.Jewel).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel, context); + return AccessJewelStorage(context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel, context); } public OrderViewModel? Update(OrderBindingModel model) { using var context = new JewelryStoreDatabase(); - var order = context.Orders.Include(x => x.Jewel).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); + var order = context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -74,7 +83,7 @@ namespace JewelryStoreDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new JewelryStoreDatabase(); - var element = context.Orders.Include(x => x.Jewel).Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs b/JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs index af9f174..27767da 100644 --- a/JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs +++ b/JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs @@ -24,6 +24,7 @@ namespace JewelryStoreDatabaseImplement public virtual DbSet JewelComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs b/JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs new file mode 100644 index 0000000..edecbf5 --- /dev/null +++ b/JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using JewelryStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace JewelryStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(JewelryStoreDatabase))] + [Migration("20230513055059_AddImplementer")] + partial class AddImplementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("JewelName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Jewels"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("JewelId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("JewelId"); + + b.ToTable("JewelComponents"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("JewelId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("JewelId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b => + { + b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component") + .WithMany("JewelComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") + .WithMany("Components") + .HasForeignKey("JewelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Jewel"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b => + { + b.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") + .WithMany("Orders") + .HasForeignKey("JewelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Jewel"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("JewelComponents"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs b/JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs new file mode 100644 index 0000000..2ba9600 --- /dev/null +++ b/JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace JewelryStoreDatabaseImplement.Migrations +{ + /// + public partial class AddImplementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs b/JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs index 8e76316..2314e2d 100644 --- a/JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs +++ b/JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Property("Id") @@ -133,6 +160,9 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("JewelId") .HasColumnType("int"); @@ -146,6 +176,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("JewelId"); b.ToTable("Orders"); @@ -178,6 +210,10 @@ namespace JewelryStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") .WithMany("Orders") .HasForeignKey("JewelId") @@ -186,6 +222,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Jewel"); }); @@ -199,6 +237,11 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("JewelComponents"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Navigation("Components"); diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs b/JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..eb6fd12 --- /dev/null +++ b/JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,71 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.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 JewelryStoreDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + public int Id { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} + diff --git a/JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs b/JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs index ed397be..b488724 100644 --- a/JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs +++ b/JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs @@ -30,6 +30,9 @@ namespace JewelryStoreDatabaseImplement.Models public DateTime? DateImplement { get; set; } public Jewel Jewel { get; set; } public Client Client { get; set; } + public int? ImplementerId { get; private set; } + public Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) { @@ -42,6 +45,7 @@ namespace JewelryStoreDatabaseImplement.Models Id = model.Id, JewelId = model.JewelId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -56,7 +60,8 @@ namespace JewelryStoreDatabaseImplement.Models return; } Status = model.Status; - if (model.DateImplement.HasValue) DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel { @@ -69,6 +74,8 @@ namespace JewelryStoreDatabaseImplement.Models JewelId = JewelId, ClientId = ClientId, ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty, Count = Count, Sum = Sum, diff --git a/JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs index d9cc46f..5d4a5b6 100644 --- a/JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs +++ b/JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs @@ -10,10 +10,13 @@ namespace JewelryStoreFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string JewelFileName = "Jewel.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Jewels { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { @@ -32,12 +35,17 @@ namespace JewelryStoreFileImplement public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement); + + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs b/JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..ba1dd16 --- /dev/null +++ b/JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,108 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + } +} diff --git a/JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs b/JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs index 6515a8f..04c48c2 100644 --- a/JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs +++ b/JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs @@ -1,4 +1,5 @@ -using JewelryStoreContracts.BindingModels; +using DocumentFormat.OpenXml.Bibliography; +using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; @@ -40,11 +41,20 @@ namespace JewelryStoreFileImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return _source.Orders .FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&model.Statuses.Contains(x.Status))?.GetViewModel; + } + if (model.ImplementerId.HasValue) + { + return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; + } + if (!model.Id.HasValue) { return null; } - return SAddJewelName(_source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel); + return SAddJewelName(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel); } public OrderViewModel? Insert(OrderBindingModel model) { diff --git a/JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj index 8995315..ff6099f 100644 --- a/JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj +++ b/JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs b/JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..e6b305f --- /dev/null +++ b/JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs @@ -0,0 +1,86 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewelryStoreFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/JewelryStore/JewelryStoreFileImplement/Models/Order.cs b/JewelryStore/JewelryStoreFileImplement/Models/Order.cs index 5239547..373e56d 100644 --- a/JewelryStore/JewelryStoreFileImplement/Models/Order.cs +++ b/JewelryStore/JewelryStoreFileImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace JewelryStoreFileImplement.Models { public int JewelId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -33,6 +34,7 @@ namespace JewelryStoreFileImplement.Models Id = model.Id, JewelId = model.JewelId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -53,6 +55,7 @@ namespace JewelryStoreFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), JewelId = Convert.ToInt32(element.Element("JewelId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -80,6 +83,7 @@ namespace JewelryStoreFileImplement.Models Id = Id, JewelId = JewelId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -91,6 +95,7 @@ namespace JewelryStoreFileImplement.Models new XAttribute("Id", Id), new XElement("JewelId", JewelId), new XElement("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs index a222065..e93ed5c 100644 --- a/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs +++ b/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs @@ -9,6 +9,7 @@ namespace JewelryStoreListImplement public List Orders { get; set; } public List Jewels { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { @@ -16,6 +17,7 @@ namespace JewelryStoreListImplement Orders = new List(); Jewels = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..c0f22fc --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,131 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && + x.Password.Equals(model.Password)) + return x.GetViewModel; + + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs index 6f53bfc..0a0b12c 100644 --- a/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs +++ b/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -57,6 +57,15 @@ namespace JewelryStoreListImplement.Implements { result.Add(GetViewModel(order)); } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + + else if (model.Statuses != null && model.Statuses.Contains(order.Status)) + { + result.Add(GetViewModel(order)); + } } } return result; @@ -74,6 +83,16 @@ namespace JewelryStoreListImplement.Implements { return AccessJewelStorage(order.GetViewModel); } + else if (model.ImplementerId.HasValue && model.Statuses != null && order.ImplementerId == model.ImplementerId && + model.Statuses.Contains(order.Status)) + { + return GetViewModel(order); + } + + else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } } return null; } diff --git a/JewelryStore/JewelryStoreListImplement/Models/Implementer.cs b/JewelryStore/JewelryStoreListImplement/Models/Implementer.cs new file mode 100644 index 0000000..51ee23a --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Models/Implementer.cs @@ -0,0 +1,61 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} diff --git a/JewelryStore/JewelryStoreListImplement/Models/Order.cs b/JewelryStore/JewelryStoreListImplement/Models/Order.cs index 189031e..5690f09 100644 --- a/JewelryStore/JewelryStoreListImplement/Models/Order.cs +++ b/JewelryStore/JewelryStoreListImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace JewelryStoreListImplement.Models public int Id { get; private set; } public int JewelId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -27,6 +28,7 @@ namespace JewelryStoreListImplement.Models Id = model.Id, JewelId = model.JewelId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,7 +59,8 @@ namespace JewelryStoreListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerId = ImplementerId }; } } \ No newline at end of file diff --git a/JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs b/JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..60e8ca0 --- /dev/null +++ b/JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace JewelryStoreRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Statuses = new() { OrderStatus.Принят } + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id); + throw; + } + } + } +}