diff --git a/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs b/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs index 564b4b3..2780d66 100644 --- a/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs @@ -1,31 +1,31 @@ -namespace PlumbingRepairView -{ - partial class FormCreateOrder - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// +namespace PlumbingRepairView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// private void InitializeComponent() { label1 = new Label(); @@ -129,15 +129,15 @@ PerformLayout(); } - #endregion + #endregion - private Label label1; - private Label label2; - private Label label3; - private Button buttonCancel; - private Button buttonSave; - private TextBox textBoxCount; - private TextBox textBoxSum; - private ComboBox comboBoxWork; - } + private Label label1; + private Label label2; + private Label label3; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private TextBox textBoxSum; + private ComboBox comboBoxWork; + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs index 47b8f3b..21b5c3e 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs @@ -1,42 +1,44 @@ -namespace PlumbingRepairView -{ - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// +namespace PlumbingRepairView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// private void InitializeComponent() { menuStrip1 = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); - КлиентыToolStripMenuItem = new ToolStripMenuItem(); работыToolStripMenuItem = new ToolStripMenuItem(); + КлиентыToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоРаботамToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); @@ -50,84 +52,101 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1103, 28); + menuStrip1.Padding = new Padding(8, 2, 0, 2); + menuStrip1.Size = new Size(1379, 33); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, работыToolStripMenuItem, КлиентыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, работыToolStripMenuItem, КлиентыToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Size = new Size(139, 29); справочникиToolStripMenuItem.Text = "Справочники"; // // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Size = new Size(270, 34); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // + // работыToolStripMenuItem + // + работыToolStripMenuItem.Name = "работыToolStripMenuItem"; + работыToolStripMenuItem.Size = new Size(270, 34); + работыToolStripMenuItem.Text = "Работы"; + работыToolStripMenuItem.Click += работыToolStripMenuItem_Click; + // // КлиентыToolStripMenuItem // КлиентыToolStripMenuItem.Name = "КлиентыToolStripMenuItem"; - КлиентыToolStripMenuItem.Size = new Size(182, 26); + КлиентыToolStripMenuItem.Size = new Size(270, 34); КлиентыToolStripMenuItem.Text = "Клиенты"; КлиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; - // - // работыToolStripMenuItem - // - работыToolStripMenuItem.Name = "работыToolStripMenuItem"; - работыToolStripMenuItem.Size = new Size(182, 26); - работыToolStripMenuItem.Text = "Работы"; - работыToolStripMenuItem.Click += работыToolStripMenuItem_Click; // // отчётыToolStripMenuItem // отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоРаботамToolStripMenuItem, списокЗаказовToolStripMenuItem }); отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - отчётыToolStripMenuItem.Size = new Size(73, 24); + отчётыToolStripMenuItem.Size = new Size(88, 29); отчётыToolStripMenuItem.Text = "Отчёты"; // // списокКомпонентовToolStripMenuItem // списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - списокКомпонентовToolStripMenuItem.Size = new Size(268, 26); + списокКомпонентовToolStripMenuItem.Size = new Size(319, 34); списокКомпонентовToolStripMenuItem.Text = "Список работ"; списокКомпонентовToolStripMenuItem.Click += списокРаботToolStripMenuItem_Click; // // компонентыПоРаботамToolStripMenuItem // компонентыПоРаботамToolStripMenuItem.Name = "компонентыПоРаботамToolStripMenuItem"; - компонентыПоРаботамToolStripMenuItem.Size = new Size(268, 26); + компонентыПоРаботамToolStripMenuItem.Size = new Size(319, 34); компонентыПоРаботамToolStripMenuItem.Text = "Компоненты по работам"; компонентыПоРаботамToolStripMenuItem.Click += компонентыПоРаботамToolStripMenuItem_Click; // // списокЗаказовToolStripMenuItem // списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(268, 26); + списокЗаказовToolStripMenuItem.Size = new Size(319, 34); списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 31); + dataGridView.Location = new Point(0, 39); + dataGridView.Margin = new Padding(4); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(878, 420); + dataGridView.Size = new Size(1098, 525); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(903, 54); + buttonCreateOrder.Location = new Point(1129, 68); + buttonCreateOrder.Margin = new Padding(4); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(170, 29); + buttonCreateOrder.Size = new Size(212, 36); buttonCreateOrder.TabIndex = 2; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; @@ -135,9 +154,10 @@ // // buttonTakeOrderInWork // - buttonTakeOrderInWork.Location = new Point(903, 142); + buttonTakeOrderInWork.Location = new Point(1129, 178); + buttonTakeOrderInWork.Margin = new Padding(4); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(170, 50); + buttonTakeOrderInWork.Size = new Size(212, 62); buttonTakeOrderInWork.TabIndex = 3; buttonTakeOrderInWork.Text = "Отдать на выполнение"; buttonTakeOrderInWork.UseVisualStyleBackColor = true; @@ -145,9 +165,10 @@ // // buttonOrderReady // - buttonOrderReady.Location = new Point(903, 233); + buttonOrderReady.Location = new Point(1129, 291); + buttonOrderReady.Margin = new Padding(4); buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(170, 29); + buttonOrderReady.Size = new Size(212, 36); buttonOrderReady.TabIndex = 4; buttonOrderReady.Text = "Заказ готов"; buttonOrderReady.UseVisualStyleBackColor = true; @@ -155,9 +176,10 @@ // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(903, 323); + buttonIssuedOrder.Location = new Point(1129, 404); + buttonIssuedOrder.Margin = new Padding(4); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(170, 29); + buttonIssuedOrder.Size = new Size(212, 36); buttonIssuedOrder.TabIndex = 5; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; @@ -165,9 +187,10 @@ // // buttonUpdateList // - buttonUpdateList.Location = new Point(903, 394); + buttonUpdateList.Location = new Point(1129, 492); + buttonUpdateList.Margin = new Padding(4); buttonUpdateList.Name = "buttonUpdateList"; - buttonUpdateList.Size = new Size(170, 29); + buttonUpdateList.Size = new Size(212, 36); buttonUpdateList.TabIndex = 6; buttonUpdateList.Text = "Обновить список"; buttonUpdateList.UseVisualStyleBackColor = true; @@ -175,9 +198,9 @@ // // FormMain // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1103, 474); + ClientSize = new Size(1379, 592); Controls.Add(buttonUpdateList); Controls.Add(buttonIssuedOrder); Controls.Add(buttonOrderReady); @@ -186,6 +209,7 @@ Controls.Add(dataGridView); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; + Margin = new Padding(4); Name = "FormMain"; Text = "Ремонт сантехники"; Load += FormMain_Load; @@ -196,22 +220,24 @@ PerformLayout(); } - #endregion + #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникиToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonUpdateList; - private ToolStripMenuItem компонентыToolStripMenuItem; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonUpdateList; + private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem работыToolStripMenuItem; 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/PlumbingRepair/PlumbingRepair/FormMain.cs b/PlumbingRepair/PlumbingRepair/FormMain.cs index 4e1d82e..d8c9d2f 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using PlumbingRepair; using PlumbingRepairBusinessLogic.BusinessLogics; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; @@ -20,13 +21,15 @@ namespace PlumbingRepairView 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, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -46,7 +49,8 @@ namespace PlumbingRepairView dataGridView.DataSource = list; dataGridView.Columns["WorkId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - } + dataGridView.Columns["ImplementerId"].Visible = false; + } _logger.LogInformation("Загрузка заказов"); } @@ -240,5 +244,20 @@ namespace PlumbingRepairView 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(); + } + } } } diff --git a/PlumbingRepair/PlumbingRepair/FormMain.resx b/PlumbingRepair/PlumbingRepair/FormMain.resx index 069f056..31c93b8 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.resx +++ b/PlumbingRepair/PlumbingRepair/FormMain.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkModeling.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..fb186a9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,141 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairBusinessLogic.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 { Status = 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); + 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.FinishOrder(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) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + 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.FinishOrder(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/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..c32f697 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/PlumbingRepair/PlumbingRepairDataBaseImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairDataBaseImplement/Implements/ImplementerStorage.cs index 1d92fc7..c63cc83 100644 --- a/PlumbingRepair/PlumbingRepairDataBaseImplement/Implements/ImplementerStorage.cs +++ b/PlumbingRepair/PlumbingRepairDataBaseImplement/Implements/ImplementerStorage.cs @@ -1,4 +1,5 @@ -using PlumbingRepairContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.StoragesContracts; using PlumbingRepairContracts.ViewModels; diff --git a/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240424045110_MigrationWithClient.Designer.cs b/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240503161017_WithImplementers.Designer.cs similarity index 82% rename from PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240424045110_MigrationWithClient.Designer.cs rename to PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240503161017_WithImplementers.Designer.cs index a6e7c5c..67837a8 100644 --- a/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240424045110_MigrationWithClient.Designer.cs +++ b/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240503161017_WithImplementers.Designer.cs @@ -1,218 +1,261 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using PlumbingRepairDataBaseImplement; - -#nullable disable - -namespace PlumbingRepairDataBaseImplement.Migrations -{ - [DbContext(typeof(PlumbingRepairDataBase))] - [Migration("20240424045110_MigrationWithClient")] - partial class MigrationWithClient - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.17") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClientFIO") - .IsRequired() - .HasColumnType("text"); - - b.Property("Email") - .IsRequired() - .HasColumnType("text"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("text"); - - b.Property("Cost") - .HasColumnType("double precision"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("DateCreate") - .HasColumnType("timestamp with time zone"); - - b.Property("DateImplement") - .HasColumnType("timestamp with time zone"); - - b.Property("Status") - .HasColumnType("integer"); - - b.Property("Sum") - .HasColumnType("double precision"); - - b.Property("WorkId") - .HasColumnType("integer"); - - b.Property("WorkName") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("WorkId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Work", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Price") - .HasColumnType("double precision"); - - b.Property("WorkName") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Works"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.WorkComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("WorkId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("WorkId"); - - b.ToTable("WorkComponents"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Order", b => - { - b.HasOne("PlumbingRepairDataBaseImplement.Models.Client", "Client") - .WithMany("Orders") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PlumbingRepairDataBaseImplement.Models.Work", "Work") - .WithMany("Orders") - .HasForeignKey("WorkId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Client"); - - b.Navigation("Work"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.WorkComponent", b => - { - b.HasOne("PlumbingRepairDataBaseImplement.Models.Component", "Component") - .WithMany("WorkComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PlumbingRepairDataBaseImplement.Models.Work", "Work") - .WithMany("Components") - .HasForeignKey("WorkId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Work"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Client", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Component", b => - { - b.Navigation("WorkComponents"); - }); - - modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Work", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PlumbingRepairDataBaseImplement; + +#nullable disable + +namespace PlumbingRepairDataBaseImplement.Migrations +{ + [DbContext(typeof(PlumbingRepairDataBase))] + [Migration("20240503161017_WithImplementers")] + partial class WithImplementers + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp with time zone"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.Property("WorkId") + .HasColumnType("integer"); + + b.Property("WorkName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("WorkId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("WorkName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.WorkComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("WorkId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("WorkId"); + + b.ToTable("WorkComponents"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Order", b => + { + b.HasOne("PlumbingRepairDataBaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PlumbingRepairDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("PlumbingRepairDataBaseImplement.Models.Work", "Work") + .WithMany("Orders") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Work"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.WorkComponent", b => + { + b.HasOne("PlumbingRepairDataBaseImplement.Models.Component", "Component") + .WithMany("WorkComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PlumbingRepairDataBaseImplement.Models.Work", "Work") + .WithMany("Components") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Work"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Component", b => + { + b.Navigation("WorkComponents"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Work", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240424045110_MigrationWithClient.cs b/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240503161017_WithImplementers.cs similarity index 81% rename from PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240424045110_MigrationWithClient.cs rename to PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240503161017_WithImplementers.cs index e2d57d9..52d552a 100644 --- a/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240424045110_MigrationWithClient.cs +++ b/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/20240503161017_WithImplementers.cs @@ -1,157 +1,187 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace PlumbingRepairDataBaseImplement.Migrations -{ - /// - public partial class MigrationWithClient : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ClientFIO = table.Column(type: "text", nullable: false), - Email = table.Column(type: "text", nullable: false), - Password = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ComponentName = table.Column(type: "text", nullable: false), - Cost = table.Column(type: "double precision", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Works", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - WorkName = table.Column(type: "text", nullable: false), - Price = table.Column(type: "double precision", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Works", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - WorkId = table.Column(type: "integer", nullable: false), - ClientId = table.Column(type: "integer", nullable: false), - WorkName = table.Column(type: "text", nullable: false), - Count = table.Column(type: "integer", nullable: false), - Sum = table.Column(type: "double precision", nullable: false), - Status = table.Column(type: "integer", nullable: false), - DateCreate = table.Column(type: "timestamp with time zone", nullable: false), - DateImplement = table.Column(type: "timestamp with time zone", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Clients_ClientId", - column: x => x.ClientId, - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Orders_Works_WorkId", - column: x => x.WorkId, - principalTable: "Works", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "WorkComponents", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - WorkId = table.Column(type: "integer", nullable: false), - ComponentId = table.Column(type: "integer", nullable: false), - Count = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_WorkComponents", x => x.Id); - table.ForeignKey( - name: "FK_WorkComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_WorkComponents_Works_WorkId", - column: x => x.WorkId, - principalTable: "Works", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientId", - table: "Orders", - column: "ClientId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_WorkId", - table: "Orders", - column: "WorkId"); - - migrationBuilder.CreateIndex( - name: "IX_WorkComponents_ComponentId", - table: "WorkComponents", - column: "ComponentId"); - - migrationBuilder.CreateIndex( - name: "IX_WorkComponents_WorkId", - table: "WorkComponents", - column: "WorkId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "WorkComponents"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropTable( - name: "Components"); - - migrationBuilder.DropTable( - name: "Works"); - } - } -} +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace PlumbingRepairDataBaseImplement.Migrations +{ + /// + public partial class WithImplementers : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ClientFIO = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ComponentName = table.Column(type: "text", nullable: false), + Cost = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ImplementerFIO = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + WorkExperience = table.Column(type: "integer", nullable: false), + Qualification = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Works", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + WorkName = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Works", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + WorkId = table.Column(type: "integer", nullable: false), + ClientId = table.Column(type: "integer", nullable: false), + ImplementerId = table.Column(type: "integer", nullable: true), + WorkName = table.Column(type: "text", nullable: false), + Count = table.Column(type: "integer", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + Status = table.Column(type: "integer", nullable: false), + DateCreate = table.Column(type: "timestamp with time zone", nullable: false), + DateImplement = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Orders_Works_WorkId", + column: x => x.WorkId, + principalTable: "Works", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "WorkComponents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + WorkId = table.Column(type: "integer", nullable: false), + ComponentId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WorkComponents", x => x.Id); + table.ForeignKey( + name: "FK_WorkComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_WorkComponents_Works_WorkId", + column: x => x.WorkId, + principalTable: "Works", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_WorkId", + table: "Orders", + column: "WorkId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkComponents_ComponentId", + table: "WorkComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkComponents_WorkId", + table: "WorkComponents", + column: "WorkId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "WorkComponents"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Works"); + } + } +} diff --git a/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs b/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs index f89d049..8f63a2e 100644 --- a/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs +++ b/PlumbingRepair/PlumbingRepairDataBaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace PlumbingRepairDataBaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace PlumbingRepairDataBaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp with time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -104,6 +134,8 @@ namespace PlumbingRepairDataBaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("WorkId"); b.ToTable("Orders"); @@ -163,6 +195,10 @@ namespace PlumbingRepairDataBaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PlumbingRepairDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PlumbingRepairDataBaseImplement.Models.Work", "Work") .WithMany("Orders") .HasForeignKey("WorkId") @@ -171,6 +207,8 @@ namespace PlumbingRepairDataBaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Work"); }); @@ -203,6 +241,11 @@ namespace PlumbingRepairDataBaseImplement.Migrations b.Navigation("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PlumbingRepairDataBaseImplement.Models.Work", b => { b.Navigation("Components"); diff --git a/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs b/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..f4caa4c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,99 @@ +using Microsoft.AspNetCore.Mvc; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepairRestApi.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 + { + Status = 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; + } + } + } +} diff --git a/PlumbingRepair/PlumbingRepairRestApi/Program.cs b/PlumbingRepair/PlumbingRepairRestApi/Program.cs index 1307a20..bcc21ef 100644 --- a/PlumbingRepair/PlumbingRepairRestApi/Program.cs +++ b/PlumbingRepair/PlumbingRepairRestApi/Program.cs @@ -13,8 +13,10 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient();