diff --git a/PrecastConcreteFileImplement/DataFileSingleton.cs b/PrecastConcreteFileImplement/DataFileSingleton.cs index bab2756..683c67f 100644 --- a/PrecastConcreteFileImplement/DataFileSingleton.cs +++ b/PrecastConcreteFileImplement/DataFileSingleton.cs @@ -15,11 +15,13 @@ namespace PrecastConcretePlantFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ReinforcedFileName = "Reinforced.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Reinforceds { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public List Shops { get; private set; } public static DataFileSingleton GetInstance() { @@ -37,6 +39,8 @@ namespace PrecastConcretePlantFileImplement => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x + => x.GetXElement); public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { @@ -46,6 +50,7 @@ namespace PrecastConcretePlantFileImplement Reinforced.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers=LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, diff --git a/PrecastConcreteFileImplement/Implements/ImplementerStorage.cs b/PrecastConcreteFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..e16961c --- /dev/null +++ b/PrecastConcreteFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + } +} diff --git a/PrecastConcreteFileImplement/Implements/OrderStorage.cs b/PrecastConcreteFileImplement/Implements/OrderStorage.cs index 5e98405..d6a7c66 100644 --- a/PrecastConcreteFileImplement/Implements/OrderStorage.cs +++ b/PrecastConcreteFileImplement/Implements/OrderStorage.cs @@ -37,6 +37,20 @@ namespace PrecastConcretePlantFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statuses.Contains(x.Status)) + ?.GetViewModel; + } + + if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } if (!model.Id.HasValue) { return null; diff --git a/PrecastConcreteFileImplement/Models/Implementer.cs b/PrecastConcreteFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..cb887cb --- /dev/null +++ b/PrecastConcreteFileImplement/Models/Implementer.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/PrecastConcreteFileImplement/Models/Order.cs b/PrecastConcreteFileImplement/Models/Order.cs index c7db726..b0f336a 100644 --- a/PrecastConcreteFileImplement/Models/Order.cs +++ b/PrecastConcreteFileImplement/Models/Order.cs @@ -13,6 +13,7 @@ namespace PrecastConcretePlantFileImplement.Models { public class Order : IOrderModel { + public int? ImplementerId { get; set; } public int ClientId { get; private set; } public int ReinforcedId { get; private set; } public int Count { get; private set; } @@ -36,6 +37,7 @@ namespace PrecastConcretePlantFileImplement.Models return new Order() { Id = model.Id, + ImplementerId = model.ImplementerId, ClientId = model.ClientId, ReinforcedId = model.ReinforcedId, Count = model.Count, @@ -56,8 +58,9 @@ namespace PrecastConcretePlantFileImplement.Models var order = new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), - ClientId=Convert.ToInt32(element.Element("ClientId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -85,6 +88,7 @@ namespace PrecastConcretePlantFileImplement.Models { Id = Id, ClientId = ClientId, + ImplementerId = ImplementerId, ReinforcedId = ReinforcedId, Count = Count, Sum = Sum, @@ -95,7 +99,8 @@ namespace PrecastConcretePlantFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), - new XAttribute("ClientId",ClientId.ToString()), + new XAttribute("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("ReinforcedId", ReinforcedId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), diff --git a/PrecastConcretePlant/FormImplementer.Designer.cs b/PrecastConcretePlant/FormImplementer.Designer.cs new file mode 100644 index 0000000..ff1dbf1 --- /dev/null +++ b/PrecastConcretePlant/FormImplementer.Designer.cs @@ -0,0 +1,178 @@ +namespace PrecastConcretePlantView +{ + partial class FormImplementer + { + /// + /// 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() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxFio = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(108, 151); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(89, 33); + this.buttonSave.TabIndex = 19; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(219, 151); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(89, 33); + this.buttonCancel.TabIndex = 18; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // numericUpDownQualification + // + this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownQualification.Location = new System.Drawing.Point(116, 97); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(264, 23); + this.numericUpDownQualification.TabIndex = 17; + // + // numericUpDownWorkExperience + // + this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownWorkExperience.Location = new System.Drawing.Point(116, 68); + this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + this.numericUpDownWorkExperience.Size = new System.Drawing.Size(264, 23); + this.numericUpDownWorkExperience.TabIndex = 16; + // + // textBoxPassword + // + this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxPassword.Location = new System.Drawing.Point(116, 40); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.PasswordChar = '*'; + this.textBoxPassword.Size = new System.Drawing.Size(264, 23); + this.textBoxPassword.TabIndex = 15; + // + // textBoxFio + // + this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxFio.Location = new System.Drawing.Point(116, 11); + this.textBoxFio.Name = "textBoxFio"; + this.textBoxFio.Size = new System.Drawing.Size(264, 23); + this.textBoxFio.TabIndex = 14; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(14, 99); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(91, 15); + this.label4.TabIndex = 13; + this.label4.Text = "Квалификация:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(67, 70); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(38, 15); + this.label3.TabIndex = 12; + this.label3.Text = "Стаж:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(58, 43); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(52, 15); + this.label2.TabIndex = 11; + this.label2.Text = "Пароль:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(68, 14); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(37, 15); + this.label1.TabIndex = 10; + this.label1.Text = "ФИО:"; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(402, 196); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFio); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormImplementer"; + this.Text = "FormImplementer"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExperience; + private TextBox textBoxPassword; + private TextBox textBoxFio; + private Label label4; + private Label label3; + private Label label2; + private Label label1; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormImplementer.cs b/PrecastConcretePlant/FormImplementer.cs new file mode 100644 index 0000000..2aa54fd --- /dev/null +++ b/PrecastConcretePlant/FormImplementer.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; + +namespace PrecastConcretePlantView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExperience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExperience.Value, + }; + 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 ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/PrecastConcretePlant/FormImplementer.resx b/PrecastConcretePlant/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormImplementer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/FormImplementers.Designer.cs b/PrecastConcretePlant/FormImplementers.Designer.cs new file mode 100644 index 0000000..b9269a9 --- /dev/null +++ b/PrecastConcretePlant/FormImplementers.Designer.cs @@ -0,0 +1,121 @@ +namespace PrecastConcretePlantView +{ + partial class FormImplementers + { + /// + /// 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() + { + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(532, 149); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 37); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDel.Location = new System.Drawing.Point(532, 110); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 33); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpd.Location = new System.Drawing.Point(532, 70); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 34); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAdd.Location = new System.Drawing.Point(532, 34); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 30); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(469, 290); + this.dataGridView.TabIndex = 10; + // + // FormViewImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(634, 314); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormViewImplementers"; + this.Text = "FormViewImplementers"; + this.Load += new System.EventHandler(this.FormViewImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormImplementers.cs b/PrecastConcretePlant/FormImplementers.cs new file mode 100644 index 0000000..81fb05c --- /dev/null +++ b/PrecastConcretePlant/FormImplementers.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlant; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; + +namespace PrecastConcretePlantView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormViewImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + 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 ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/FormImplementers.resx b/PrecastConcretePlant/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormImplementers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/FormMain.Designer.cs index 8e80e95..f1957ca 100644 --- a/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/FormMain.Designer.cs @@ -28,6 +28,26 @@ /// private void InitializeComponent() { + MenuStrip = 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(); + DataGridView = new DataGridView(); + CreateOrderButton = new Button(); + TakeOrderInWorkButton = new Button(); + OrderReadyButton = new Button(); + IssuedOrderButton = new Button(); + UpdateListButton = new Button(); + MenuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); MenuStrip = new MenuStrip(); СправочникиToolStripMenuItem = new ToolStripMenuItem(); ИзделияToolStripMenuItem = new ToolStripMenuItem(); @@ -72,6 +92,12 @@ // // MenuStrip // + MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); + MenuStrip.Location = new Point(0, 0); + MenuStrip.Name = "MenuStrip"; + MenuStrip.Size = new Size(953, 24); + MenuStrip.TabIndex = 0; + MenuStrip.Text = "menuStrip1"; MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem }); MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; @@ -81,6 +107,10 @@ // // СправочникиToolStripMenuItem // + СправочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ИзделияToolStripMenuItem, КомпонентыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); + СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; + СправочникиToolStripMenuItem.Size = new Size(94, 20); + СправочникиToolStripMenuItem.Text = "Cправочники"; this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ИзделияToolStripMenuItem, this.КомпонентыToolStripMenuItem, @@ -96,6 +126,10 @@ // ИзделияToolStripMenuItem // ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + ИзделияToolStripMenuItem.Size = new Size(180, 22); + ИзделияToolStripMenuItem.Text = "ЖБИ"; + ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; ИзделияToolStripMenuItem.Size = new Size(145, 22); ИзделияToolStripMenuItem.Text = "ЖБИ"; ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; @@ -103,10 +137,28 @@ // КомпонентыToolStripMenuItem // КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; КомпонентыToolStripMenuItem.Size = new Size(145, 22); КомпонентыToolStripMenuItem.Text = "Компоненты"; КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(180, 22); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // // магазиныToolStripMenuItem // магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; @@ -116,6 +168,10 @@ // // отчетыToolStripMenuItem // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЖБИToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЖБИToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem, списокМагазиновToolStripMenuItem, загруженностьМагазиновToolStripMenuItem, заказыПоДатамToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(60, 20); @@ -124,6 +180,10 @@ // списокЖБИToolStripMenuItem // списокЖБИToolStripMenuItem.Name = "списокЖБИToolStripMenuItem"; + списокЖБИToolStripMenuItem.Size = new Size(197, 22); + списокЖБИToolStripMenuItem.Text = "Список ЖБИ"; + списокЖБИToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; + списокЖБИToolStripMenuItem.Name = "списокЖБИToolStripMenuItem"; списокЖБИToolStripMenuItem.Size = new Size(219, 22); списокЖБИToolStripMenuItem.Text = "Список ЖБИ"; списокЖБИToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; @@ -131,6 +191,10 @@ // компонентыПоИзделиямToolStripMenuItem // компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; + компонентыПоИзделиямToolStripMenuItem.Size = new Size(197, 22); + компонентыПоИзделиямToolStripMenuItem.Text = "ЖБИ по компонентам"; + компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; + компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; компонентыПоИзделиямToolStripMenuItem.Size = new Size(219, 22); компонентыПоИзделиямToolStripMenuItem.Text = "ЖБИ по компонентам"; компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; @@ -138,6 +202,17 @@ // списокЗаказовToolStripMenuItem // списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(197, 22); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(92, 20); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; списокЗаказовToolStripMenuItem.Size = new Size(219, 22); списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; @@ -200,6 +275,13 @@ UpdateListButton.Text = "Обновить список"; UpdateListButton.UseVisualStyleBackColor = true; UpdateListButton.Click += UpdateListButton_Click; + UpdateListButton.Location = new Point(825, 189); + UpdateListButton.Name = "UpdateListButton"; + UpdateListButton.Size = new Size(104, 33); + UpdateListButton.TabIndex = 6; + UpdateListButton.Text = "Обновить список"; + UpdateListButton.UseVisualStyleBackColor = true; + UpdateListButton.Click += UpdateListButton_Click; // // AddShopButton // @@ -254,6 +336,25 @@ AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(953, 450); + Controls.Add(UpdateListButton); + Controls.Add(IssuedOrderButton); + Controls.Add(OrderReadyButton); + Controls.Add(TakeOrderInWorkButton); + Controls.Add(CreateOrderButton); + Controls.Add(DataGridView); + Controls.Add(MenuStrip); + MainMenuStrip = MenuStrip; + Name = "FormMain"; + Text = "Завод ЖБИ"; + Load += FormMain_Load; + MenuStrip.ResumeLayout(false); + MenuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(953, 450); Controls.Add(ButtonSell); Controls.Add(AddShopButton); Controls.Add(UpdateListButton); @@ -291,6 +392,8 @@ private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private Button AddShopButton; private Button ButtonSell; diff --git a/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/FormMain.cs index e8bcfde..39ccb7a 100644 --- a/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/FormMain.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using PrecastConcretePlant; +using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantDataModels.Enums; @@ -21,13 +22,15 @@ namespace PrecastConcretePlantView 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) @@ -48,6 +51,7 @@ namespace PrecastConcretePlantView DataGridView.DataSource = list; DataGridView.Columns["ReinforcedId"].Visible = false; DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["ImplementerId"].Visible = false; DataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } @@ -221,6 +225,23 @@ namespace PrecastConcretePlantView } } + 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(); + } + } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/Program.cs index 2ce8f58..6f29dee 100644 --- a/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/Program.cs @@ -45,6 +45,9 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -61,6 +64,8 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..619aeb9 --- /dev/null +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,127 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogic +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + 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 List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. 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 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 (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация должна быть больше 0", nameof(model.Qualification)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж должен быть не меньше 0", nameof(model.WorkExperience)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля", nameof(model.Password)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. Qualification:{Qualification}. WorkExperience:{WorkExperience}. Id:{Id}", + model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index ffa9699..a8a6084 100644 --- a/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -50,8 +50,35 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic return true; } + public OrderViewModel? ReadElement(OrderSearchModel model) private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DateFrom:{DateFrom}. DateTo:{DateTo}. Id:{Id}", model.DateFrom, model.DateTo, 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; + } + + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + throw new InvalidOperationException(); var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (viewModel == null) { @@ -66,6 +93,16 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = viewModel.DateImplement; + } + if (viewModel.ImplementerId.HasValue) + { + model.ImplementerId = viewModel.ImplementerId.Value; + } + CheckModel(model, false); var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId }); if (reinforced == null) { @@ -88,6 +125,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } return true; } + public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); @@ -99,6 +137,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool FinishOrder(OrderBindingModel model) { + model.DateImplement=DateTime.Now; return StatusUpdate(model, OrderStatus.Выдан); } public List? ReadList(OrderSearchModel? model) diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..ed20a97 --- /dev/null +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,140 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogic +{ + 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 = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs b/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..1c55a14 --- /dev/null +++ b/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class ImplementerBindingModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs index 7b2701e..d903ac4 100644 --- a/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs +++ b/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs @@ -18,5 +18,6 @@ namespace PrecastConcretePlantContracts.BindingModels public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..37fbec9 --- /dev/null +++ b/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs index 5b3c94b..3895100 100644 --- a/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel? model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..d69bed0 --- /dev/null +++ b/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,17 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogic +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs b/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..8e9b321 --- /dev/null +++ b/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs index 1897b6b..7748c55 100644 --- a/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs +++ b/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using PrecastConcretePlantDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,8 +11,10 @@ namespace PrecastConcretePlantContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public List? Statuses { get; set; } } } diff --git a/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs b/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..a0c0e80 --- /dev/null +++ b/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs b/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..b41daf9 --- /dev/null +++ b/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs index a37bd83..4ef43de 100644 --- a/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs +++ b/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -16,6 +16,9 @@ namespace PrecastConcretePlantContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("ФИО исполнителя")] + public string? ImplementerFIO { get; set; } = string.Empty; public int ReinforcedId { get; set; } [DisplayName("ЖБИ")] public string ReinforcedName { get; set; } = string.Empty; diff --git a/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs b/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..7027c5d --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs @@ -0,0 +1,116 @@ +using Microsoft.EntityFrameworkCore; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new PrecastConcretePlantDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var implementer = GetElement(model); + + return implementer != null ? new() { implementer } : new(); + } + + if (model.ImplementerFIO != null) + { + using var context = new SoftwareInstallationDataBase(); + + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new PrecastConcretePlantDatabase(); + if (model.Id.HasValue) + return context.Implementers + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + ?.GetViewModel; + + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDatabase(); + var implementer = Implementer.Create(model); + + if (implementer != null) + { + context.Implementers.Add(implementer); + context.SaveChanges(); + } + + return implementer?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDatabase(); + var implementer = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + + if (implementer != null) + { + implementer.Update(model); + context.SaveChanges(); + } + + return implementer?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDatabase(); + var implementer = context.Implementers + .FirstOrDefault(rec => rec.Id == model.Id); + if (implementer != null) + { + context.Implementers.Remove(implementer); + context.SaveChanges(); + } + return implementer?.GetViewModel; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs b/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs index a968731..0f0b757 100644 --- a/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs +++ b/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs @@ -17,19 +17,21 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new PrecastConcretePlantDatabase(); + var element = context.Orders + .Include(x => x.Reinforced) + .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) { - var deletedElement = context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; context.Orders.Remove(element); context.SaveChanges(); + return element.GetViewModel; } + return null; } @@ -39,90 +41,103 @@ namespace PrecastConcretePlantDatabaseImplement.Implements { return null; } + using var context = new PrecastConcretePlantDatabase(); - return context.Orders.Include(x => x.Reinforced).Include(x => x.Client) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + + return context.Orders.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id + )?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - using var context = new PrecastConcretePlantDatabase(); if (model.Id.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + var result = GetElement(model); + return result != null ? new() { result } : new(); } - else if (model.DateFrom != null && model.DateTo != null) + + using var context = new PrecastConcretePlantDatabase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + queryWhere = context.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && + x.DateCreate.Date <= model.DateTo); } + + else if (model.Statuses != null) + { + queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status)); + } + else if (model.ClientId.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); + queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId); } + else { return new(); } + + return queryWhere + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new PrecastConcretePlantDatabase(); + return context.Orders .Include(x => x.Reinforced) .Include(x => x.Client) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Implementer) + .Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { var newOrder = Order.Create(model); + if (newOrder == null) { return null; } + using var context = new PrecastConcretePlantDatabase(); + context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == newOrder.Id) - ?.GetViewModel; + + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new PrecastConcretePlantDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + + var order = context.Orders + .Include(x => x.Reinforced) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id); + if (order == null) { return null; } + order.Update(model); context.SaveChanges(); - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + + return order.GetViewModel; } } -} +} \ No newline at end of file diff --git a/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs new file mode 100644 index 0000000..f93519f --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDatabaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDatabase))] + [Migration("20230419193952_implementeradd")] + partial class implementeradd + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.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("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs new file mode 100644 index 0000000..a67685a --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + /// + public partial class implementeradd : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs b/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs index 0702242..26e79e6 100644 --- a/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs +++ b/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.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("PrecastConcretePlantDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ReinforcedId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ReinforcedId"); b.ToTable("Orders"); @@ -212,6 +244,10 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") .HasForeignKey("ReinforcedId") @@ -220,6 +256,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Reinforced"); }); @@ -271,6 +309,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("ReinforcedComponents"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => { b.Navigation("Components"); diff --git a/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs b/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs new file mode 100644 index 0000000..0db20f3 --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs @@ -0,0 +1,70 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.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; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + 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/PrecastConcretePlantDataBaseImplemet/Models/Order.cs b/PrecastConcretePlantDataBaseImplemet/Models/Order.cs index cdca361..2ecc9a1 100644 --- a/PrecastConcretePlantDataBaseImplemet/Models/Order.cs +++ b/PrecastConcretePlantDataBaseImplemet/Models/Order.cs @@ -20,6 +20,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models public int ReinforcedId { get; private set; } [Required] public int Count { get; private set; } + public int? ImplementerId { get; set; } + [Required] public double Sum { get; private set; } [Required] @@ -29,8 +31,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Reinforced Reinforced { get; set; } public virtual Client Client { get; set; } - - public static Order? Create(OrderBindingModel model) + public virtual Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { @@ -41,6 +43,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models Id = model.Id, ClientId=model.ClientId, ReinforcedId = model.ReinforcedId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,20 +60,30 @@ namespace PrecastConcretePlantDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } - public OrderViewModel GetViewModel => new() - { - Id = Id, - ClientId=ClientId, - ClientFIO=Client.ClientFIO, - ReinforcedId = ReinforcedId, - ReinforcedName = Reinforced.ReinforcedName, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; + public OrderViewModel GetViewModel + { + get + { + using var context = new PrecastConcretePlantDatabase(); + return new OrderViewModel + { + Id = Id, + ReinforcedId = ReinforcedId, + ClientId = ClientId, + ImplementerId = ImplementerId, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty + }; + } + } } } diff --git a/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs b/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs index 4a90a99..b8448b3 100644 --- a/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs +++ b/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs @@ -24,6 +24,7 @@ namespace PrecastConcretePlantDatabaseImplement public virtual DbSet ReinforcedComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } public virtual DbSet Shops { set; get; } public virtual DbSet ShopReinforceds { set; get; } } diff --git a/PrecastConcretePlantDataModels/Models/IImplementerModel.cs b/PrecastConcretePlantDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..7386da8 --- /dev/null +++ b/PrecastConcretePlantDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/PrecastConcretePlantDataModels/Models/IOrderModel.cs b/PrecastConcretePlantDataModels/Models/IOrderModel.cs index d1aa7b0..0c0b46f 100644 --- a/PrecastConcretePlantDataModels/Models/IOrderModel.cs +++ b/PrecastConcretePlantDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantDataModels.Models { int ReinforcedId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlantListImplement/DataListSingleton.cs index 875a027..21f5884 100644 --- a/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -14,6 +14,7 @@ namespace PrecastConcretePlantListImplement public List Orders { get; set; } public List Reinforceds { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } public List Shops { get; set; } private DataListSingleton() { @@ -21,6 +22,7 @@ namespace PrecastConcretePlantListImplement Orders = new List(); Reinforceds = new List(); Clients = new List(); + Implementers = new List(); Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs b/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..fdb06d6 --- /dev/null +++ b/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,130 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && + x.Password.Equals(model.Password)) + return x.GetViewModel; + + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/PrecastConcretePlantListImplement/Implements/OrderStorage.cs b/PrecastConcretePlantListImplement/Implements/OrderStorage.cs index f368705..3ededc3 100644 --- a/PrecastConcretePlantListImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlantListImplement/Implements/OrderStorage.cs @@ -47,6 +47,18 @@ namespace PrecastConcretePlantListImplement.Implements { return order.GetViewModel; } + else if (model.ImplementerId.HasValue && model.Statuses != null && + order.ImplementerId == model.ImplementerId && + model.Statuses.Contains(order.Status)) + { + return GetViewModel(order); + } + + else if (model.ImplementerId.HasValue && + model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } } return null; @@ -69,6 +81,15 @@ namespace PrecastConcretePlantListImplement.Implements { result.Add(order.GetViewModel); } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(order.GetViewModel); + } + + else if (model.Status != null && model.Status.Contains(order.Status)) + { + result.Add(order.GetViewModel); + } } } else if (model.DateFrom != null && model.DateTo != null) diff --git a/PrecastConcretePlantListImplement/Models/Implementer.cs b/PrecastConcretePlantListImplement/Models/Implementer.cs new file mode 100644 index 0000000..132554e --- /dev/null +++ b/PrecastConcretePlantListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public 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, + }; + } +} diff --git a/PrecastConcretePlantListImplement/Models/Order.cs b/PrecastConcretePlantListImplement/Models/Order.cs index 66b52a6..ad64030 100644 --- a/PrecastConcretePlantListImplement/Models/Order.cs +++ b/PrecastConcretePlantListImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace PrecastConcretePlantListImplement.Models { public int ClientId { get; private set; } public int ReinforcedId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -41,7 +42,8 @@ namespace PrecastConcretePlantListImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId }; } @@ -64,6 +66,7 @@ namespace PrecastConcretePlantListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, + ImplementerId= ImplementerId, DateImplement = DateImplement }; } diff --git a/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs b/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..c2a7709 --- /dev/null +++ b/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,104 @@ +using Microsoft.AspNetCore.Mvc; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; + +namespace PrecastConcretePlantRestApi.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 = new() { OrderStatus.Принят } + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } +}