diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs index 13f1e1b..cc9620f 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs @@ -12,10 +12,12 @@ namespace BlackcmithWorkshopFileImplement private readonly string ShopFileName = "Shops.xml"; public List Shops { get; private set; } 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 Manufactures { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -34,6 +36,8 @@ namespace BlackcmithWorkshopFileImplement "Shops", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, + "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => @@ -46,6 +50,8 @@ namespace BlackcmithWorkshopFileImplement Shop.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/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..ccae9ad --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,79 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implementers + .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || + x.ImplementerFIO.Contains(model.ImplementerFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + return source.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password))? + .GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + return null; + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + return null; + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs index 30e2f4f..cb9c984 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -28,14 +28,14 @@ namespace BlacksmithWorkshopFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { return source.Orders - .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) && - (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && - (!model.ClientId.HasValue || x.ClientId == model.ClientId) - ) + .Where(x => + (!model.Id.HasValue || x.Id == model.Id) && + (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && + (!model.ClientId.HasValue || x.ClientId == model.ClientId) && + (!model.Status.HasValue || x.Status == model.Status) ) - .Select(x => AccessStorage(x.GetViewModel)) + .Select(x => AccessStorage(x.GetViewModel) ?? new()) .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -44,9 +44,12 @@ namespace BlacksmithWorkshopFileImplement.Implements { return null; } - return AccessStorage(source.Orders.FirstOrDefault( - x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel - ); + return AccessStorage(source.Orders + .FirstOrDefault( + x => (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status))? + .GetViewModel ?? new()); } public OrderViewModel? Insert(OrderBindingModel model) { @@ -85,19 +88,15 @@ namespace BlacksmithWorkshopFileImplement.Implements } public OrderViewModel? AccessStorage(OrderViewModel model) { - if (model == null) - return null; + var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (manufacture != null) + model.ManufactureName = manufacture.ManufactureName; if (client != null) model.ClientFIO = client.ClientFIO; - foreach (var Manufacture in source.Manufactures) - { - if (Manufacture.Id == model.ManufactureId) - { - model.ManufactureName = Manufacture.ManufactureName; - break; - } - } + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } } diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..241bebf --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs @@ -0,0 +1,76 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int Qualification { get; set; } = 0; + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs index b3031c8..98b409b 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs @@ -16,6 +16,7 @@ namespace BlacksmithWorkshopFileImplement.Models public int Id { get; private set; } public int ManufactureId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } = null; public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -32,6 +33,7 @@ namespace BlacksmithWorkshopFileImplement.Models { Id = model.Id, ManufactureId = model.ManufactureId, + ImplementerId = model.ImplementerId, ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, @@ -50,6 +52,7 @@ namespace BlacksmithWorkshopFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), @@ -71,6 +74,7 @@ namespace BlacksmithWorkshopFileImplement.Models { Id = Id, ManufactureId = ManufactureId, + ImplementerId = ImplementerId, ClientId = ClientId, Count = Count, Sum = Sum, @@ -82,6 +86,7 @@ namespace BlacksmithWorkshopFileImplement.Models new XAttribute("Id", Id), new XElement("ManufactureId", ManufactureId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Sum", Sum.ToString()), new XElement("Count", Count), new XElement("Status", Status.ToString()), diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 1aa1218..6a311b5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -35,6 +35,9 @@ ShopsToolStripMenuItem = new ToolStripMenuItem(); SupplyToolStripMenuItem = new ToolStripMenuItem(); SalesToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + StartWorkingToolStripMenuItem = new ToolStripMenuItem(); ReportsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesListToolStripMenuItem = new ToolStripMenuItem(); ManufacturesComponentsListToolStripMenuItem = new ToolStripMenuItem(); @@ -58,12 +61,13 @@ menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1011, 24); + menuStrip.Size = new Size(1267, 24); menuStrip.TabIndex = 0; menuStrip.Text = "Меню"; // // GuidesToolStripMenuItem // + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem, StartWorkingToolStripMenuItem }); GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyToolStripMenuItem, SalesToolStripMenuItem }); GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem}); GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; @@ -73,17 +77,38 @@ // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(198, 22); + ComponentsToolStripMenuItem.Size = new Size(181, 22); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // ManufacturesToolStripMenuItem // ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(198, 22); + ManufacturesToolStripMenuItem.Size = new Size(181, 22); ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(181, 22); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(181, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // + // StartWorkingToolStripMenuItem + // + StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; + StartWorkingToolStripMenuItem.Size = new Size(181, 22); + StartWorkingToolStripMenuItem.Text = "Старт работ"; + StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; + // // ShopsToolStripMenuItem // ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; @@ -107,6 +132,7 @@ // // ReportsToolStripMenuItem // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem }); ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem, DatesOrdersListToolStripMenuItem, ShopsListToolStripMenuItem, ShopsManufacturesListToolStripMenuItem }); ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem}); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; @@ -140,12 +166,12 @@ dataGridView.Location = new Point(0, 23); dataGridView.Name = "dataGridView"; dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(847, 427); + dataGridView.Size = new Size(1101, 427); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(853, 38); + buttonCreateOrder.Location = new Point(1107, 27); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(148, 31); buttonCreateOrder.TabIndex = 2; @@ -155,7 +181,7 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(853, 186); + buttonRefresh.Location = new Point(1107, 175); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(148, 31); buttonRefresh.TabIndex = 3; @@ -165,7 +191,7 @@ // // buttonIssued // - buttonIssued.Location = new Point(853, 149); + buttonIssued.Location = new Point(1107, 138); buttonIssued.Name = "buttonIssued"; buttonIssued.Size = new Size(148, 31); buttonIssued.TabIndex = 4; @@ -175,7 +201,7 @@ // // buttonReady // - buttonReady.Location = new Point(853, 112); + buttonReady.Location = new Point(1107, 101); buttonReady.Name = "buttonReady"; buttonReady.Size = new Size(148, 31); buttonReady.TabIndex = 5; @@ -185,7 +211,7 @@ // // buttonTakeInWork // - buttonTakeInWork.Location = new Point(853, 75); + buttonTakeInWork.Location = new Point(1107, 64); buttonTakeInWork.Name = "buttonTakeInWork"; buttonTakeInWork.Size = new Size(148, 31); buttonTakeInWork.TabIndex = 6; @@ -225,7 +251,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1011, 450); + ClientSize = new Size(1267, 450); Controls.Add(buttonTakeInWork); Controls.Add(buttonReady); Controls.Add(buttonIssued); @@ -268,5 +294,7 @@ private ToolStripMenuItem ShopsListToolStripMenuItem; private ToolStripMenuItem ShopsManufacturesListToolStripMenuItem; private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem ImplementersToolStripMenuItem; + private ToolStripMenuItem StartWorkingToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 904eb26..c9bb42c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -19,12 +19,15 @@ namespace BlacksmithWorkshop private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, + IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void ComponentsStripMenuItem_Click(object sender, EventArgs e) { @@ -48,8 +51,11 @@ namespace BlacksmithWorkshop { dataGridView.DataSource = list; dataGridView.Columns["ManufactureId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -93,8 +99,7 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { @@ -257,5 +262,18 @@ namespace BlacksmithWorkshop form.ShowDialog(); } } + private void StartWorkingToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm)); + if (service is ImplementersForm form) + { + form.ShowDialog(); + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs new file mode 100644 index 0000000..854012b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs @@ -0,0 +1,172 @@ +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace BlacksmithWorkshop +{ + partial class ImplementerForm + { + /// + /// 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() + { + FIOTextBox = new TextBox(); + PasswordTextBox = new TextBox(); + QualificationTextBox = new TextBox(); + WorkExperienceTextBox = new TextBox(); + labelFio = new Label(); + labelPassword = new Label(); + labelQualification = new Label(); + labelExperience = new Label(); + SaveButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // FIOTextBox + // + FIOTextBox.Location = new Point(108, 14); + FIOTextBox.Margin = new Padding(3, 2, 3, 2); + FIOTextBox.Name = "FIOTextBox"; + FIOTextBox.Size = new Size(360, 23); + FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + PasswordTextBox.Location = new Point(108, 39); + PasswordTextBox.Margin = new Padding(3, 2, 3, 2); + PasswordTextBox.Name = "PasswordTextBox"; + PasswordTextBox.Size = new Size(360, 23); + PasswordTextBox.TabIndex = 1; + // + // QualificationTextBox + // + QualificationTextBox.Location = new Point(108, 64); + QualificationTextBox.Margin = new Padding(3, 2, 3, 2); + QualificationTextBox.Name = "QualificationTextBox"; + QualificationTextBox.Size = new Size(360, 23); + QualificationTextBox.TabIndex = 2; + // + // WorkExperienceTextBox + // + WorkExperienceTextBox.Location = new Point(108, 88); + WorkExperienceTextBox.Margin = new Padding(3, 2, 3, 2); + WorkExperienceTextBox.Name = "WorkExperienceTextBox"; + WorkExperienceTextBox.Size = new Size(360, 23); + WorkExperienceTextBox.TabIndex = 3; + // + // labelFio + // + labelFio.AutoSize = true; + labelFio.Location = new Point(8, 14); + labelFio.Name = "labelFio"; + labelFio.Size = new Size(34, 15); + labelFio.TabIndex = 4; + labelFio.Text = "ФИО"; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(8, 39); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(49, 15); + labelPassword.TabIndex = 5; + labelPassword.Text = "Пароль"; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(8, 64); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(88, 15); + labelQualification.TabIndex = 6; + labelQualification.Text = "Квалификация"; + // + // labelExperience + // + labelExperience.AutoSize = true; + labelExperience.Location = new Point(8, 88); + labelExperience.Name = "labelExperience"; + labelExperience.Size = new Size(79, 15); + labelExperience.TabIndex = 7; + labelExperience.Text = "Стаж работы"; + // + // SaveButton + // + SaveButton.Location = new Point(298, 113); + SaveButton.Margin = new Padding(3, 2, 3, 2); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(82, 22); + SaveButton.TabIndex = 8; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(386, 113); + CancelButton.Margin = new Padding(3, 2, 3, 2); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(82, 22); + CancelButton.TabIndex = 9; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // ImplementerForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(480, 140); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(labelExperience); + Controls.Add(labelQualification); + Controls.Add(labelPassword); + Controls.Add(labelFio); + Controls.Add(WorkExperienceTextBox); + Controls.Add(QualificationTextBox); + Controls.Add(PasswordTextBox); + Controls.Add(FIOTextBox); + Margin = new Padding(3, 2, 3, 2); + Name = "ImplementerForm"; + Text = "Исполнитель"; + Load += ImplementerForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private TextBox QualificationTextBox; + private TextBox WorkExperienceTextBox; + private Label labelFio; + private Label labelPassword; + private Label labelQualification; + private Label labelExperience; + private Button SaveButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs new file mode 100644 index 0000000..55e8944 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs @@ -0,0 +1,102 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class ImplementerForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public ImplementerForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementerForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationTextBox.Text = view.Qualification.ToString(); + WorkExperienceTextBox.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = Convert.ToInt32(QualificationTextBox.Text), + WorkExperience = Convert.ToInt32(WorkExperienceTextBox.Text), + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.resx b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs new file mode 100644 index 0000000..e1890c9 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs @@ -0,0 +1,114 @@ +namespace BlacksmithWorkshop +{ + partial class ImplementersForm + { + /// + /// 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() + { + dataGridView1 = new DataGridView(); + CreateButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + RefreshButton = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 12); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.RowTemplate.Height = 29; + dataGridView1.Size = new Size(565, 426); + dataGridView1.TabIndex = 0; + // + // CreateButton + // + CreateButton.Location = new Point(583, 12); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(205, 29); + CreateButton.TabIndex = 1; + CreateButton.Text = "Создать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += CreateButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(583, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(205, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(583, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(205, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(583, 117); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(205, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // ImplementersForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(RefreshButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(CreateButton); + Controls.Add(dataGridView1); + Name = "ImplementersForm"; + Text = "Исполнители"; + Load += ImplementersForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView1; + private Button CreateButton; + private Button ChangeButton; + private Button DeleteButton; + private Button RefreshButton; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs new file mode 100644 index 0000000..7a6934e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs @@ -0,0 +1,113 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class ImplementersForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public ImplementersForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void ImplementersForm_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["Id"].Visible = false; + dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CreateButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.resx b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 17cd428..fb8cc78 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -50,6 +50,9 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -66,6 +69,8 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..e74c712 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,126 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ClientFIO}. Id:{ Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Id:{ Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ImplementerBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", + nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", + nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж меньше 0", + nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}." + + "Password:{ Password}. WorkExperience:{ WorkExperience}. Qualification:{ Qualification}. Id: { Id} ", + model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 57f094a..f0c7a01 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -21,6 +21,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics private readonly IShopLogic _shopLogic; private readonly IManufactureStorage _manufactureStorage; private readonly IShopStorage _shopStorage; + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage, IManufactureStorage manufactureStorage, IShopLogic shopLogic, IShopStorage shopStorage) { @@ -30,7 +31,22 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _shopLogic = shopLogic; _shopStorage = shopStorage; } - + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); @@ -44,7 +60,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -60,56 +75,56 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics private bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - CheckModel(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 != status - 1) + if (!(element.Status == status - 1 || element.Status == OrderStatus.Готов)) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - if (element.Status == OrderStatus.Готов) + if (element.Status == OrderStatus.Готов || element.Status == OrderStatus.Ожидает) { - var manufacture = _manufactureStorage.GetElement(new ManufactureSearchModel() { Id = model.ManufactureId }); + var manufacture = _manufactureStorage.GetElement(new ManufactureSearchModel() { Id = element.ManufactureId }); if (manufacture == null) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found."); return false; } - if (CheckSupply(manufacture, model.Count) == false) + if (!CheckSupply(manufacture, element.Count)) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error."); - return false; + status = OrderStatus.Ожидает; } } model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (element.ImplementerId.HasValue) + model.ImplementerId = element.ImplementerId; _orderStorage.Update(model); return true; } - public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } - public bool FinishOrder(OrderBindingModel model) { return ChangeStatus(model, OrderStatus.Готов); } - public bool DeliveryOrder(OrderBindingModel model) { return ChangeStatus(model, OrderStatus.Выдан); } - - private void CheckModel(OrderBindingModel model, bool withParams = - true) + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..738afc1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,189 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.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 deliveredOrders = _orderLogic.ReadList(new OrderSearchModel + { + Status = OrderStatus.Выдан + }); + var allOrders = _orderLogic.ReadList(null); + if (deliveredOrders == null || allOrders == null || deliveredOrders.Count == allOrders.Count) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + deliveredOrders.ForEach(x => allOrders.Remove(x)); + _logger.LogDebug("DoWork for {Count} orders", allOrders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, allOrders)); + } + } + /// Иммитация работы исполнителя + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await DeliverWaitingOrder(implementer); + 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 + }); + _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) + { + 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 + }); + _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; + } + } + /// Обрабатываем заказ, которые в ожидании (вдруг место освободилось) + private async Task DeliverWaitingOrder(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Ожидает + })); + if (waitingOrders == null || waitingOrders.Count == 0) + { + return; + } + _logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count); + foreach (var waitingOrder in waitingOrders) + { + try + { + _logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id); + var res = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = waitingOrder.Id + }); + } + catch (ArgumentException ex) + { + _logger.LogWarning(ex, "DeliverWaitingOrder. Fault"); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try deliver order"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..7a3ec35 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public string Password { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs index 7bd89c8..f8da514 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs @@ -18,6 +18,7 @@ namespace BlacksmithWorkshopContracts.BindingModels public int Count { get; set; } public double Sum { get; set; } + public int? ImplementerId { get; set; } = null; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..551bcf1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerBindingModel model); + bool Update(ImplementerBindingModel model); + bool Delete(ImplementerBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs index bdd54b4..0634b84 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -16,5 +16,6 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..8b5f34a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..eae8594 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs index e0e42b2..1027069 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using BlacksmithWorkshopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace BlacksmithWorkshopContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..9dadb14 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + List GetFilteredList(ImplementerSearchModel model); + ImplementerViewModel? GetElement(ImplementerSearchModel model); + ImplementerViewModel? Insert(ImplementerBindingModel model); + ImplementerViewModel? Update(ImplementerBindingModel model); + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..58ee191 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } = 0; + [DisplayName("Квалификация")] + public int Qualification { get; set; } = 0; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index d895345..0cd267f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -13,6 +13,7 @@ namespace BlacksmithWorkshopContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int? ImplementerId { get; set; } = null; public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; @@ -25,6 +26,8 @@ namespace BlacksmithWorkshopContracts.ViewModels public double Sum { get; set; } [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs index 4777cd9..6d7015c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs @@ -10,6 +10,8 @@ Готов = 2, - Выдан = 3 + Ожидает = 3, + + Выдан = 4 } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..c8e1951 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IImplementerModel + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 58c843d..29c8fff 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -13,6 +13,7 @@ namespace BlacksmithWorkshopDataModels.Models int ClientId { get; } int Count { get; } double Sum { get; } + int? ImplementerId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs index 2eab2a8..bfd5e29 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs @@ -1,4 +1,5 @@ using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopDataModels.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -25,5 +26,7 @@ namespace BlacksmithWorkshopDatabaseImplement public virtual DbSet Shops { set; get; } public virtual DbSet ShopManufactures { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..77b15ab --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,82 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + 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) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + return new(); + } + public List GetFullList() + { + using var context = new BlacksmithWorkshopDataBase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + 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 BlacksmithWorkshopDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index c976717..26e0798 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -20,6 +20,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -29,12 +30,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && - (!model.ClientId.HasValue || x.ClientId == model.ClientId) - ) + (!model.ClientId.HasValue || x.ClientId == model.ClientId) && + (!model.Status.HasValue || x.Status == model.Status)) ) .Select(x => x.GetViewModel) .ToList(); @@ -47,9 +49,14 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Include(x => x.Manufacture) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + .Include(x => x.Manufacture) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault( + x => (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status))? + .GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -69,6 +76,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements var order = context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id); if (order == null) { @@ -84,6 +92,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements var element = context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.Designer.cs similarity index 86% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.Designer.cs index 6808a76..bcf11bf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240421170619_initialCreate")] - partial class initialCreate + [Migration("20240507165329_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -25,6 +25,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("BlacksmithWorkshopDataModels.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("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ManufactureId") .HasColumnType("int"); @@ -149,6 +179,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ManufactureId"); b.ToTable("Orders"); @@ -234,6 +266,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") @@ -242,6 +278,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Manufacture"); }); @@ -264,6 +302,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Shop"); }); + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Navigation("Orders"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.cs similarity index 86% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.cs index a30604d..7483112 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace BlacksmithWorkshopDatabaseImplement.Migrations { /// - public partial class initialCreate : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -40,6 +40,22 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + 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), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Manufactures", columns: table => new @@ -109,7 +125,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations Status = table.Column(type: "int", nullable: false), DateCreate = table.Column(type: "datetime2", nullable: false), DateImplement = table.Column(type: "datetime2", nullable: true), - ManufactureId = table.Column(type: "int", nullable: false) + ManufactureId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true) }, constraints: table => { @@ -120,6 +137,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations 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_Manufactures_ManufactureId", column: x => x.ManufactureId, @@ -170,6 +192,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ManufactureId", table: "Orders", @@ -204,6 +231,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Manufactures"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs index fffa9c0..8b9cb14 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -22,6 +22,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("BlacksmithWorkshopDataModels.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("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Property("Id") @@ -133,6 +160,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ManufactureId") .HasColumnType("int"); @@ -146,6 +176,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ManufactureId"); b.ToTable("Orders"); @@ -231,6 +263,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") @@ -239,6 +275,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Manufacture"); }); @@ -261,6 +299,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Shop"); }); + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Navigation("Orders"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..7d07cf7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +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; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopDataModels.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public int Qualification { get; set; } = 0; + [Required] + public int WorkExperience { get; set; } = 0; + [ForeignKey("ImplementerId")] + public virtual List Orders { get; 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/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 377e303..852f053 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -29,6 +29,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models [Required] public int ManufactureId { get; private set; } public virtual Manufacture? Manufacture { get; set; } + public int? ImplementerId { get; private set; } = null; + public virtual Implementer? Implementer { get; private set; } public static Order Create(OrderBindingModel model) { @@ -42,6 +44,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models DateImplement = model.DateImplement, ManufactureId = model.ManufactureId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, }; } public void Update(OrderBindingModel? model) @@ -51,7 +54,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; + DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -65,6 +69,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Id = Id, ClientId = ClientId, ClientFIO = Client?.ClientFIO ?? string.Empty, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : string.Empty }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 7483d0b..023bc09 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -15,6 +15,7 @@ namespace BlacksmithWorkshopListImplement public List Manufactures { get; set; } public List Shops { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); @@ -22,6 +23,7 @@ namespace BlacksmithWorkshopListImplement Manufactures = new List(); Shops = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..cda5043 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,102 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (model.ImplementerFIO != null && implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var implementer in _source.Implementers) + { + if ((string.IsNullOrEmpty(model.ImplementerFIO) || implementer.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || implementer.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + { + return implementer.GetViewModel; + } + } + return null; + } + 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 newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (model.Id == implementer.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + 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; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 4b3aeac..98df2cc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -36,7 +36,8 @@ namespace BlacksmithWorkshopListImplement.Implements if ((!model.Id.HasValue || order.Id == model.Id) && (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || order.DateCreate <= model.DateTo) && - (!model.ClientId.HasValue || order.ClientId == model.ClientId)) + (!model.ClientId.HasValue || order.ClientId == model.ClientId) && + (!model.Status.HasValue || order.Status == model.Status)) { result.Add(AccessStorage(order.GetViewModel)); } @@ -51,9 +52,11 @@ namespace BlacksmithWorkshopListImplement.Implements } foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) + if ((model.Id.HasValue && order.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + order.ImplementerId == model.ImplementerId && order.Status == model.Status)) { - return order.GetViewModel; + return AccessStorage(order.GetViewModel); } } return null; @@ -103,17 +106,17 @@ namespace BlacksmithWorkshopListImplement.Implements } public OrderViewModel AccessStorage(OrderViewModel model) { - var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId); + if (model == null) + return null; + var manufacture = _source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + var client = _source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = _source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (manufacture != null) + model.ManufactureName = manufacture.ManufactureName; if (client != null) model.ClientFIO = client.ClientFIO; - foreach (var Manufacture in _source.Manufactures) - { - if (Manufacture.Id == model.ManufactureId) - { - model.ManufactureName = Manufacture.ManufactureName; - break; - } - } + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..79c8a4e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs @@ -0,0 +1,54 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs index a41914d..843ed78 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs @@ -15,6 +15,7 @@ namespace BlacksmithWorkshopListImplement.Models public int Id { get; private set; } public int ManufactureId { 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; } @@ -37,6 +38,7 @@ namespace BlacksmithWorkshopListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId }; } public void Update(OrderBindingModel? model) @@ -47,6 +49,7 @@ namespace BlacksmithWorkshopListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -58,6 +61,7 @@ namespace BlacksmithWorkshopListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, + ImplementerId = ImplementerId, }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..1fd2db5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : ControllerBase + { + 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; + } + } + } +}