From 6b664e242c1ed3f59405d03f40911bb6e995f1b9 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Fri, 9 Feb 2024 22:05:46 +0400 Subject: [PATCH] memento labs --- ComputersShop/ComputersShop.sln | 26 +++- .../ComputersShop/ComputersShop.csproj | 9 ++ ComputersShop/ComputersShop/Form1.Designer.cs | 39 ------ ComputersShop/ComputersShop/Form1.cs | 10 -- .../ComputersShop/FormComponent.Designer.cs | 118 +++++++++++++++++ ComputersShop/ComputersShop/FormComponent.cs | 84 ++++++++++++ .../{Form1.resx => FormComponent.resx} | 50 ++++---- .../ComputersShop/FormComponents.Designer.cs | 115 +++++++++++++++++ ComputersShop/ComputersShop/FormComponents.cs | 100 +++++++++++++++ .../ComputersShop/FormComponents.resx | 120 ++++++++++++++++++ .../FormComputerComponent.Designer.cs | 118 +++++++++++++++++ .../ComputersShop/FormComputerComponent.cs | 90 +++++++++++++ .../ComputersShop/FormComputerComponent.resx | 120 ++++++++++++++++++ ComputersShop/ComputersShop/Program.cs | 41 +++++- .../BusinessLogics/ComponentLogic.cs | 109 ++++++++++++++++ .../BusinessLogics/ComputerLogic.cs | 112 ++++++++++++++++ .../BusinessLogics/OrderLogic.cs | 105 +++++++++++++++ .../ComputersShopBusinessLogic.csproj | 17 +++ .../BindingModels/ComponentBindingModel.cs | 11 ++ .../BindingModels/ComputerBindingModel.cs | 12 ++ .../BindingModels/OrderBindingModel.cs | 16 +++ .../BisnessLogicsContracts/IComponentLogic.cs | 15 +++ .../BisnessLogicsContracts/IComputerLogic.cs | 15 +++ .../BisnessLogicsContracts/IOrderLogic.cs | 15 +++ .../ComputersShopContracts.csproj | 13 ++ .../SearchModels/ComponentSearchModel.cs | 8 ++ .../SearchModels/ComputerSearchModel.cs | 8 ++ .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/IComponentStorage.cs | 17 +++ .../StoragesContracts/IComputerStorage.cs | 16 +++ .../StoragesContracts/IOrderStorage.cs | 16 +++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/ComputerViewModel.cs | 15 +++ .../ViewModels/OrderViewModel.cs | 25 ++++ .../ComputersShopDataModels.csproj | 9 ++ .../IComponentModel.cs | 14 ++ .../ComputersShopDataModels/IComputerModel.cs | 15 +++ ComputersShop/ComputersShopDataModels/IId.cs | 13 ++ .../ComputersShopDataModels/IOrderModel.cs | 19 +++ .../ComputersShopDataModels/OrderStatus.cs | 11 ++ .../ComputersShopListImplement.csproj | 14 ++ .../DataListSingleton.cs | 26 ++++ .../Implements/ComponentStorage.cs | 103 +++++++++++++++ .../Implements/ComputerStorage.cs | 102 +++++++++++++++ .../Implements/OrderStorage.cs | 113 +++++++++++++++++ .../Models/Component.cs | 42 ++++++ .../Models/Computer.cs | 45 +++++++ .../Models/Order.cs | 60 +++++++++ 48 files changed, 2115 insertions(+), 77 deletions(-) delete mode 100644 ComputersShop/ComputersShop/Form1.Designer.cs delete mode 100644 ComputersShop/ComputersShop/Form1.cs create mode 100644 ComputersShop/ComputersShop/FormComponent.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComponent.cs rename ComputersShop/ComputersShop/{Form1.resx => FormComponent.resx} (93%) create mode 100644 ComputersShop/ComputersShop/FormComponents.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComponents.cs create mode 100644 ComputersShop/ComputersShop/FormComponents.resx create mode 100644 ComputersShop/ComputersShop/FormComputerComponent.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComputerComponent.cs create mode 100644 ComputersShop/ComputersShop/FormComputerComponent.resx create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComponentLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComputerLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IOrderLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj create mode 100644 ComputersShop/ComputersShopDataModels/IComponentModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/IComputerModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/IId.cs create mode 100644 ComputersShop/ComputersShopDataModels/IOrderModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/OrderStatus.cs create mode 100644 ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj create mode 100644 ComputersShop/ComputersShopListImplement/DataListSingleton.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Component.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Computer.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Order.cs diff --git a/ComputersShop/ComputersShop.sln b/ComputersShop/ComputersShop.sln index 33f1ff3..914fdb8 100644 --- a/ComputersShop/ComputersShop.sln +++ b/ComputersShop/ComputersShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop\ComputersShop.csproj", "{6C2333FF-312C-4539-869D-2BF1F8743BD7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShop", "ComputersShop\ComputersShop.csproj", "{6C2333FF-312C-4539-869D-2BF1F8743BD7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopDataModels", "ComputersShopDataModels\ComputersShopDataModels.csproj", "{BB721FA2-6985-4A54-8616-86EFD69A6FD0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopContracts", "ComputersShopContracts\ComputersShopContracts.csproj", "{37B7052B-3ADF-4D42-AEC9-4CD7F5C7A602}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopBusinessLogic", "ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj", "{382729DA-F6E1-40AC-ADDA-4AACC1A3E103}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopListImplement", "ComputersShopListImplement\ComputersShopListImplement.csproj", "{97A1B877-DBB2-44B3-AB63-A32946B07EDE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {6C2333FF-312C-4539-869D-2BF1F8743BD7}.Debug|Any CPU.Build.0 = Debug|Any CPU {6C2333FF-312C-4539-869D-2BF1F8743BD7}.Release|Any CPU.ActiveCfg = Release|Any CPU {6C2333FF-312C-4539-869D-2BF1F8743BD7}.Release|Any CPU.Build.0 = Release|Any CPU + {BB721FA2-6985-4A54-8616-86EFD69A6FD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BB721FA2-6985-4A54-8616-86EFD69A6FD0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BB721FA2-6985-4A54-8616-86EFD69A6FD0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BB721FA2-6985-4A54-8616-86EFD69A6FD0}.Release|Any CPU.Build.0 = Release|Any CPU + {37B7052B-3ADF-4D42-AEC9-4CD7F5C7A602}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37B7052B-3ADF-4D42-AEC9-4CD7F5C7A602}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37B7052B-3ADF-4D42-AEC9-4CD7F5C7A602}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37B7052B-3ADF-4D42-AEC9-4CD7F5C7A602}.Release|Any CPU.Build.0 = Release|Any CPU + {382729DA-F6E1-40AC-ADDA-4AACC1A3E103}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {382729DA-F6E1-40AC-ADDA-4AACC1A3E103}.Debug|Any CPU.Build.0 = Debug|Any CPU + {382729DA-F6E1-40AC-ADDA-4AACC1A3E103}.Release|Any CPU.ActiveCfg = Release|Any CPU + {382729DA-F6E1-40AC-ADDA-4AACC1A3E103}.Release|Any CPU.Build.0 = Release|Any CPU + {97A1B877-DBB2-44B3-AB63-A32946B07EDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97A1B877-DBB2-44B3-AB63-A32946B07EDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97A1B877-DBB2-44B3-AB63-A32946B07EDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97A1B877-DBB2-44B3-AB63-A32946B07EDE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ComputersShop/ComputersShop/ComputersShop.csproj b/ComputersShop/ComputersShop/ComputersShop.csproj index b57c89e..bce5394 100644 --- a/ComputersShop/ComputersShop/ComputersShop.csproj +++ b/ComputersShop/ComputersShop/ComputersShop.csproj @@ -8,4 +8,13 @@ enable + + + + + + + + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Form1.Designer.cs b/ComputersShop/ComputersShop/Form1.Designer.cs deleted file mode 100644 index 8127802..0000000 --- a/ComputersShop/ComputersShop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ComputersShop -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Form1.cs b/ComputersShop/ComputersShop/Form1.cs deleted file mode 100644 index 85dadf8..0000000 --- a/ComputersShop/ComputersShop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ComputersShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComponent.Designer.cs b/ComputersShop/ComputersShop/FormComponent.Designer.cs new file mode 100644 index 0000000..bdcba6b --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace ComputersShop +{ + partial class FormComponent + { + /// + /// 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() + { + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(110, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(255, 27); + textBoxName.TabIndex = 0; + // + // textBoxCost + // + textBoxCost.Location = new Point(110, 60); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(162, 27); + textBoxCost.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 2; + labelName.Text = "Название"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(16, 63); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(45, 20); + labelCost.TabIndex = 3; + labelCost.Text = "Цена"; + // + // buttonSave + // + buttonSave.Location = new Point(154, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(271, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(390, 142); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelName; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComponent.cs b/ComputersShop/ComputersShop/FormComponent.cs new file mode 100644 index 0000000..4f9fef6 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponent.cs @@ -0,0 +1,84 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace ComputersShop +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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(textBoxName.Text)) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Form1.resx b/ComputersShop/ComputersShop/FormComponent.resx similarity index 93% rename from ComputersShop/ComputersShop/Form1.resx rename to ComputersShop/ComputersShop/FormComponent.resx index 1af7de1..af32865 100644 --- a/ComputersShop/ComputersShop/Form1.resx +++ b/ComputersShop/ComputersShop/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/ComputersShop/ComputersShop/FormComponents.Designer.cs b/ComputersShop/ComputersShop/FormComponents.Designer.cs new file mode 100644 index 0000000..8a45c9a --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace ComputersShop +{ + partial class FormComponents + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonChange = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(2, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(503, 452); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(581, 38); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(159, 55); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonChange + // + buttonChange.Location = new Point(581, 123); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(159, 55); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(581, 212); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(159, 55); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(581, 313); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(159, 55); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComponents.cs b/ComputersShop/ComputersShop/FormComponents.cs new file mode 100644 index 0000000..5c35a34 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponents.cs @@ -0,0 +1,100 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace ComputersShop +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_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["ComponentName"].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(FormComponent)); + if (service is FormComponent 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(FormComponent)); + if (service is FormComponent 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 ComponentBindingModel + { + 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/ComputersShop/ComputersShop/FormComponents.resx b/ComputersShop/ComputersShop/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputerComponent.Designer.cs b/ComputersShop/ComputersShop/FormComputerComponent.Designer.cs new file mode 100644 index 0000000..69ca9ba --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputerComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace ComputersShop +{ + partial class FormComputerComponent + { + /// + /// 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() + { + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + labelComponent = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(163, 30); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(298, 28); + comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(163, 84); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(298, 27); + textBoxCount.TabIndex = 1; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(32, 33); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(88, 20); + labelComponent.TabIndex = 2; + labelComponent.Text = "Компонент"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(32, 87); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 3; + labelCount.Text = "Количество"; + // + // buttonSave + // + buttonSave.Location = new Point(181, 132); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(139, 30); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(326, 132); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(139, 30); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComputerComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(493, 174); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Name = "FormComputerComponent"; + Text = "Компоненты компьютера"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputerComponent.cs b/ComputersShop/ComputersShop/FormComputerComponent.cs new file mode 100644 index 0000000..a4d2a5c --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputerComponent.cs @@ -0,0 +1,90 @@ +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ComputersShop +{ + public partial class FormComputerComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormComputerComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/ComputersShop/ComputersShop/FormComputerComponent.resx b/ComputersShop/ComputersShop/FormComputerComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputerComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Program.cs b/ComputersShop/ComputersShop/Program.cs index 6394a0e..041e443 100644 --- a/ComputersShop/ComputersShop/Program.cs +++ b/ComputersShop/ComputersShop/Program.cs @@ -1,9 +1,21 @@ +using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.StoragesContracts; +using ComputersShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; +using System; + namespace ComputersShop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +23,32 @@ namespace ComputersShop // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..fa601e7 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,109 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + internal class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs new file mode 100644 index 0000000..f96788f --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -0,0 +1,112 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class ComputerLogic : IComputerLogic + { + private readonly ILogger _logger; + private readonly IComputerStorage _ComputerStorage; + public ComputerLogic(ILogger logger, IComputerStorage ComputerStorage) + { + _logger = logger; + _ComputerStorage = ComputerStorage; + } + + public List? ReadList(ComputerSearchModel? model) + { + _logger.LogInformation("ReadList. ComputerName:{ComputerName}. Id:{ Id}", model?.ComputerName, model?.Id); + var list = model == null ? _ComputerStorage.GetFullList() : _ComputerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComputerViewModel? ReadElement(ComputerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComputerName:{ComputerName}.Id:{ Id}", model.ComputerName, model.Id); + var element = _ComputerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComputerBindingModel model) + { + CheckModel(model); + if (_ComputerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComputerBindingModel model) + { + CheckModel(model); + if (_ComputerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComputerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_ComputerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComputerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComputerName)) + { + throw new ArgumentNullException("Нет названия мороженного", + nameof(model.ComputerName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена мороженного должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Computer. Computer:{Computer}. Price:{ Price }. Id: { Id}", model.ComputerName, model.Price, model.Id); + var element = _ComputerStorage.GetElement(new ComputerSearchModel + { + ComputerName = model.ComputerName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..23307d6 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,105 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj new file mode 100644 index 0000000..9254d93 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..539942f --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using ComputersShopDataModels; + +namespace ComputersShopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs new file mode 100644 index 0000000..63e2b06 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs @@ -0,0 +1,12 @@ +using ComputersShopDataModels; + +namespace ComputersShopContracts.BindingModels +{ + public class ComputerBindingModel : IComputerModel + { + public int Id { get; set; } + public string ComputerName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ComputerComponents{ get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..f169b97 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using ComputersShopDataModels; +using ComputersShopDataModels.Enums; + +namespace ComputersShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ComputerId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComponentLogic.cs b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..9e47ef5 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.BisnessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComputerLogic.cs b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComputerLogic.cs new file mode 100644 index 0000000..c858be4 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IComputerLogic.cs @@ -0,0 +1,15 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.BisnessLogicsContracts +{ + public interface IComputerLogic + { + List? ReadList(ComputerSearchModel? model); + ComputerViewModel? ReadElement(ComputerSearchModel model); + bool Create(ComputerBindingModel model); + bool Update(ComputerBindingModel model); + bool Delete(ComputerBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..47db7af --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.BisnessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj new file mode 100644 index 0000000..9c95599 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..cdea093 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace ComputersShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs new file mode 100644 index 0000000..c9a082a --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs @@ -0,0 +1,8 @@ +namespace ComputersShopContracts.SearchModels +{ + public class ComputerSearchModel + { + public int? Id { get; set; } + public string? ComputerName { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..3b3d9f6 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace ComputersShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..5cec769 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs new file mode 100644 index 0000000..dda93bd --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs @@ -0,0 +1,16 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComputerStorage + { + List GetFullList(); + List GetFilteredList(ComputerSearchModel model); + ComputerViewModel? GetElement(ComputerSearchModel model); + ComputerViewModel? Insert(ComputerBindingModel model); + ComputerViewModel? Update(ComputerBindingModel model); + ComputerViewModel? Delete(ComputerBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..512bb9d --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..7621abe --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using ComputersShopDataModels; +using System.ComponentModel; + +namespace ComputersShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs new file mode 100644 index 0000000..f8f6aa0 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs @@ -0,0 +1,15 @@ +using ComputersShopDataModels; +using System.ComponentModel; + +namespace ComputersShopContracts.ViewModels +{ + public class ComputerViewModel : IComputerModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ComputerName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ComputerComponents{ get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..83e3e8a --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using ComputersShopDataModels; +using ComputersShopDataModels.Enums; +using System.ComponentModel; + +namespace ComputersShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ComputerId { get; set; } + [DisplayName("Изделие")] + public string ComputerName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj b/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/ComputersShop/ComputersShopDataModels/IComponentModel.cs b/ComputersShop/ComputersShopDataModels/IComponentModel.cs new file mode 100644 index 0000000..c9b9df7 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/IComputerModel.cs b/ComputersShop/ComputersShopDataModels/IComputerModel.cs new file mode 100644 index 0000000..7d0fac9 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IComputerModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels +{ + public interface IComputerModel : IId + { + string ComputerName { get; } + double Price { get; } + Dictionary ComputerComponents { get; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/IId.cs b/ComputersShop/ComputersShopDataModels/IId.cs new file mode 100644 index 0000000..99b74e8 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/IOrderModel.cs b/ComputersShop/ComputersShopDataModels/IOrderModel.cs new file mode 100644 index 0000000..c1897e1 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IOrderModel.cs @@ -0,0 +1,19 @@ +using ComputersShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels +{ + public interface IOrderModel : IId + { + int ComputerId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/OrderStatus.cs b/ComputersShop/ComputersShopDataModels/OrderStatus.cs new file mode 100644 index 0000000..348af9b --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace ComputersShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj b/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj new file mode 100644 index 0000000..8eb14fb --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..1b0012b --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Computers { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Computers = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..8e3924a --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,103 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; +namespace ComputersShopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } + +} diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs new file mode 100644 index 0000000..35f52ec --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs @@ -0,0 +1,102 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement.Implements +{ + public class ComputerStorage : IComputerStorage + { + private readonly DataListSingleton _source; + public ComputerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Computer in _source.Computers) + { + result.Add(Computer.GetViewModel); + } + return result; + } + public List GetFilteredList(ComputerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComputerName)) + { + return result; + } + foreach (var Computer in _source.Computers) + { + if (Computer.ComputerName.Contains(model.ComputerName)) + { + result.Add(Computer.GetViewModel); + } + } + return result; + } + public ComputerViewModel? GetElement(ComputerSearchModel model) + { + if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue) + { + return null; + } + foreach (var Computer in _source.Computers) + { + if ((!string.IsNullOrEmpty(model.ComputerName) && + Computer.ComputerName == model.ComputerName) || + (model.Id.HasValue && Computer.Id == model.Id)) + { + return Computer.GetViewModel; + } + } + return null; + } + public ComputerViewModel? Insert(ComputerBindingModel model) + { + model.Id = 1; + foreach (var Computer in _source.Computers) + { + if (model.Id <= Computer.Id) + { + model.Id = Computer.Id + 1; + } + } + var newComputer = Computer.Create(model); + if (newComputer == null) + { + return null; + } + _source.Computers.Add(newComputer); + return newComputer.GetViewModel; + } + public ComputerViewModel? Update(ComputerBindingModel model) + { + foreach (var Computer in _source.Computers) + { + if (Computer.Id == model.Id) + { + Computer.Update(model); + return Computer.GetViewModel; + } + } + return null; + } + public ComputerViewModel? Delete(ComputerBindingModel model) + { + for (int i = 0; i < _source.Computers.Count; ++i) + { + if (_source.Computers[i].Id == model.Id) + { + var element = _source.Computers[i]; + _source.Computers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..30e0f42 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,113 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AccessComputerStorage(order.GetViewModel)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AccessComputerStorage(order.GetViewModel)); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public OrderViewModel AccessComputerStorage(OrderViewModel model) + { + foreach (var Computer in _source.Computers) + { + if (Computer.Id == model.ComputerId) + { + model.ComputerName = Computer.ComputerName; + break; + } + } + return model; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Component.cs b/ComputersShop/ComputersShopListImplement/Models/Component.cs new file mode 100644 index 0000000..9f6d6dc --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Component.cs @@ -0,0 +1,42 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; + +namespace ComputersShopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } + +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Computer.cs b/ComputersShop/ComputersShopListImplement/Models/Computer.cs new file mode 100644 index 0000000..f663847 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Computer.cs @@ -0,0 +1,45 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; + +namespace ComputersShopListImplement.Models +{ + public class Computer : IComputerModel + { + public int Id { get; private set; } + public string ComputerName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ComputerComponents{ get; private set; } = new Dictionary(); + public static Computer? Create(ComputerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Computer() + { + Id = model.Id, + ComputerName = model.ComputerName, + Price = model.Price, + ComputerComponents = model.ComputerComponents + }; + } + public void Update(ComputerBindingModel? model) + { + if (model == null) + { + return; + } + ComputerName = model.ComputerName; + Price = model.Price; + ComputerComponents = model.ComputerComponents; + } + public ComputerViewModel GetViewModel => new() + { + Id = Id, + ComputerName = ComputerName, + Price = Price, + ComputerComponents = ComputerComponents + }; + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Order.cs b/ComputersShop/ComputersShopListImplement/Models/Order.cs new file mode 100644 index 0000000..74d361d --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Order.cs @@ -0,0 +1,60 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using ComputersShopDataModels; + +namespace ComputersShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ComputerId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ComputerId = model.ComputerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + ComputerId = model.ComputerId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ComputerId = ComputerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +}