diff --git a/Forum/Forum/FormAddTopic.Designer.cs b/Forum/Forum/FormAddTopic.Designer.cs
new file mode 100644
index 0000000..4052661
--- /dev/null
+++ b/Forum/Forum/FormAddTopic.Designer.cs
@@ -0,0 +1,82 @@
+namespace Forum
+{
+ partial class FormAddTopic
+ {
+ ///
+ /// 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.textBoxTopic = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxTopic
+ //
+ this.textBoxTopic.Location = new System.Drawing.Point(20, 12);
+ this.textBoxTopic.Name = "textBoxTopic";
+ this.textBoxTopic.Size = new System.Drawing.Size(218, 27);
+ this.textBoxTopic.TabIndex = 0;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(20, 45);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 1;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(144, 45);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 2;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ //
+ // FormAddTopic
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(251, 84);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxTopic);
+ this.Name = "FormAddTopic";
+ this.Text = "Тема";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private TextBox textBoxTopic;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Forum/Forum/FormAddTopic.cs b/Forum/Forum/FormAddTopic.cs
new file mode 100644
index 0000000..68e2279
--- /dev/null
+++ b/Forum/Forum/FormAddTopic.cs
@@ -0,0 +1,20 @@
+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 Forum
+{
+ public partial class FormAddTopic : Form
+ {
+ public FormAddTopic()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Forum/Forum/FormAddTopic.resx b/Forum/Forum/FormAddTopic.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Forum/Forum/FormAddTopic.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/Forum/Forum/FormAddTopics.Designer.cs b/Forum/Forum/FormAddTopics.Designer.cs
new file mode 100644
index 0000000..dcf0410
--- /dev/null
+++ b/Forum/Forum/FormAddTopics.Designer.cs
@@ -0,0 +1,126 @@
+namespace Forum
+{
+ partial class FormAddTopics
+ {
+ ///
+ /// 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.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.textBoxCategory = new System.Windows.Forms.TextBox();
+ this.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonChange = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Location = new System.Drawing.Point(12, 54);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.RowHeadersWidth = 51;
+ this.dataGridView1.RowTemplate.Height = 29;
+ this.dataGridView1.Size = new System.Drawing.Size(408, 188);
+ this.dataGridView1.TabIndex = 0;
+ //
+ // textBoxCategory
+ //
+ this.textBoxCategory.Location = new System.Drawing.Point(12, 12);
+ this.textBoxCategory.Name = "textBoxCategory";
+ this.textBoxCategory.Size = new System.Drawing.Size(125, 27);
+ this.textBoxCategory.TabIndex = 1;
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Location = new System.Drawing.Point(435, 54);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(94, 29);
+ this.buttonCreate.TabIndex = 2;
+ this.buttonCreate.Text = "Создать";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ //
+ // buttonChange
+ //
+ this.buttonChange.Location = new System.Drawing.Point(435, 89);
+ this.buttonChange.Name = "buttonChange";
+ this.buttonChange.Size = new System.Drawing.Size(94, 29);
+ this.buttonChange.TabIndex = 3;
+ this.buttonChange.Text = "Изменить";
+ this.buttonChange.UseVisualStyleBackColor = true;
+ this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(435, 124);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(94, 29);
+ this.buttonDelete.TabIndex = 4;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(435, 159);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(94, 29);
+ this.buttonUpdate.TabIndex = 5;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
+ //
+ // FormAddTopic
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(536, 253);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonChange);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.textBoxCategory);
+ this.Controls.Add(this.dataGridView1);
+ this.Name = "FormAddTopic";
+ this.Text = "Добавление тем";
+ this.Load += new System.EventHandler(this.FormAddTopic_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView1;
+ private TextBox textBoxCategory;
+ private Button buttonCreate;
+ private Button buttonChange;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/Forum/Forum/FormAddTopics.cs b/Forum/Forum/FormAddTopics.cs
new file mode 100644
index 0000000..260b44f
--- /dev/null
+++ b/Forum/Forum/FormAddTopics.cs
@@ -0,0 +1,78 @@
+using ForumContracts.BusinessLogicContracts;
+using ForumContracts.SearchModels;
+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 Forum
+{
+ public partial class FormAddTopics : Form
+ {
+ private readonly ICategoryLogic _categoryLogic;
+ private readonly ITopicLogic _topicLogic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormAddTopics(ITopicLogic topicLogic, ICategoryLogic categoryLogic)
+ {
+ InitializeComponent();
+ _topicLogic = topicLogic;
+ _categoryLogic = categoryLogic;
+ }
+
+ private void FormAddTopic_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ var view = _categoryLogic.ReadElement(new CategorySearchModel { Id = _id.Value });
+
+ if (view != null)
+ {
+ textBoxCategory.Text = view.Name;
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormAddTopic));
+
+ if (service is FormAddTopic form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ throw new NotImplementedException();
+ }
+
+ private void buttonChange_Click(object sender, EventArgs e)
+ {
+
+ }
+
+ private void buttonDelete_Click(object sender, EventArgs e)
+ {
+
+ }
+
+ private void buttonUpdate_Click(object sender, EventArgs e)
+ {
+
+ }
+ }
+}
diff --git a/Forum/Forum/FormAddTopics.resx b/Forum/Forum/FormAddTopics.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Forum/Forum/FormAddTopics.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/Forum/Forum/FormCategories.Designer.cs b/Forum/Forum/FormCategories.Designer.cs
new file mode 100644
index 0000000..6eb83b5
--- /dev/null
+++ b/Forum/Forum/FormCategories.Designer.cs
@@ -0,0 +1,128 @@
+namespace Forum
+{
+ partial class FormCategories
+ {
+ ///
+ /// 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.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonChange = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ this.buttonAddTopicInCategory = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(300, 188);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Location = new System.Drawing.Point(330, 12);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(94, 29);
+ this.buttonCreate.TabIndex = 1;
+ this.buttonCreate.Text = "Создать";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ //
+ // buttonChange
+ //
+ this.buttonChange.Location = new System.Drawing.Point(330, 47);
+ this.buttonChange.Name = "buttonChange";
+ this.buttonChange.Size = new System.Drawing.Size(94, 29);
+ this.buttonChange.TabIndex = 2;
+ this.buttonChange.Text = "Изменить";
+ this.buttonChange.UseVisualStyleBackColor = true;
+ this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(330, 82);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(94, 29);
+ this.buttonDelete.TabIndex = 3;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(330, 117);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(94, 29);
+ this.buttonUpdate.TabIndex = 4;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
+ //
+ // buttonAddTopicInCategory
+ //
+ this.buttonAddTopicInCategory.Location = new System.Drawing.Point(330, 152);
+ this.buttonAddTopicInCategory.Name = "buttonAddTopicInCategory";
+ this.buttonAddTopicInCategory.Size = new System.Drawing.Size(94, 54);
+ this.buttonAddTopicInCategory.TabIndex = 5;
+ this.buttonAddTopicInCategory.Text = "Добавить темы";
+ this.buttonAddTopicInCategory.UseVisualStyleBackColor = true;
+ this.buttonAddTopicInCategory.Click += new System.EventHandler(this.buttonAddTopicInCategory_Click);
+ //
+ // FormCategories
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(438, 211);
+ this.Controls.Add(this.buttonAddTopicInCategory);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonChange);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormCategories";
+ this.Text = "Категории";
+ this.Load += new System.EventHandler(this.FormCategories_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonCreate;
+ private Button buttonChange;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ private Button buttonAddTopicInCategory;
+ }
+}
\ No newline at end of file
diff --git a/Forum/Forum/FormCategories.cs b/Forum/Forum/FormCategories.cs
new file mode 100644
index 0000000..afcee17
--- /dev/null
+++ b/Forum/Forum/FormCategories.cs
@@ -0,0 +1,129 @@
+using ForumContracts.BindingModels;
+using ForumContracts.BusinessLogicContracts;
+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 Forum
+{
+ public partial class FormCategories : Form
+ {
+ private readonly ICategoryLogic _categoryLogic;
+ public FormCategories(ICategoryLogic categoryLogic)
+ {
+ InitializeComponent();
+ _categoryLogic = categoryLogic;
+ }
+
+
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCategory));
+
+ if (service is FormCategory form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _categoryLogic.ReadList(null);
+
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ }
+ catch (Exception)
+ { }
+ }
+
+ private void FormCategories_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void buttonDelete_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);
+
+ try
+ {
+ if (!_categoryLogic.Delete(new CategoryBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void buttonChange_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCategory));
+
+ if (service is FormCategory form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void buttonAddTopicInCategory_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormAddTopics));
+
+ if (service is FormAddTopics form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Forum/Forum/FormCategories.resx b/Forum/Forum/FormCategories.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Forum/Forum/FormCategories.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/Forum/Forum/FormCategory.Designer.cs b/Forum/Forum/FormCategory.Designer.cs
new file mode 100644
index 0000000..b27e7bc
--- /dev/null
+++ b/Forum/Forum/FormCategory.Designer.cs
@@ -0,0 +1,85 @@
+namespace Forum
+{
+ partial class FormCategory
+ {
+ ///
+ /// 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.textBoxCategory = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxCategory
+ //
+ this.textBoxCategory.Location = new System.Drawing.Point(12, 12);
+ this.textBoxCategory.Name = "textBoxCategory";
+ this.textBoxCategory.Size = new System.Drawing.Size(194, 27);
+ this.textBoxCategory.TabIndex = 0;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(12, 45);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 1;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(112, 45);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 2;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // FormCategory
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(222, 82);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCategory);
+ this.Name = "FormCategory";
+ this.Text = "Категория";
+ this.Click += new System.EventHandler(this.FormCategory_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private TextBox textBoxCategory;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Forum/Forum/FormCategory.cs b/Forum/Forum/FormCategory.cs
new file mode 100644
index 0000000..d436f7e
--- /dev/null
+++ b/Forum/Forum/FormCategory.cs
@@ -0,0 +1,88 @@
+using ForumContracts.BindingModels;
+using ForumContracts.BusinessLogicContracts;
+using ForumContracts.SearchModels;
+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 Forum
+{
+ public partial class FormCategory : Form
+ {
+ private readonly ICategoryLogic _categoryLogic;
+
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormCategory(ICategoryLogic categoryLogic)
+ {
+ InitializeComponent();
+ _categoryLogic = categoryLogic;
+
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCategory.Text))
+ {
+ MessageBox.Show("Введите название роли", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+ try
+ {
+ var model = new CategoryBindingModel
+ {
+ Id = _id ?? 0,
+ Name = textBoxCategory.Text
+ };
+
+ var operationResult = _id.HasValue ? _categoryLogic.Update(model) : _categoryLogic.Create(model);
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранеии.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ private void FormCategory_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ var view = _categoryLogic.ReadElement(new CategorySearchModel { Id = _id.Value });
+
+ if (view != null)
+ {
+ textBoxCategory.Text = view.Name;
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+}
diff --git a/Forum/Forum/FormCategory.resx b/Forum/Forum/FormCategory.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Forum/Forum/FormCategory.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/Forum/Forum/FormMain.Designer.cs b/Forum/Forum/FormMain.Designer.cs
index 87d0cda..1f48017 100644
--- a/Forum/Forum/FormMain.Designer.cs
+++ b/Forum/Forum/FormMain.Designer.cs
@@ -32,6 +32,7 @@
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.ролиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.пользователиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.категорииToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -51,7 +52,8 @@
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ролиToolStripMenuItem,
- this.пользователиToolStripMenuItem});
+ this.пользователиToolStripMenuItem,
+ this.категорииToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(800, 28);
@@ -72,6 +74,13 @@
this.пользователиToolStripMenuItem.Text = "Пользователи";
this.пользователиToolStripMenuItem.Click += new System.EventHandler(this.пользователиToolStripMenuItem_Click);
//
+ // категорииToolStripMenuItem
+ //
+ this.категорииToolStripMenuItem.Name = "категорииToolStripMenuItem";
+ this.категорииToolStripMenuItem.Size = new System.Drawing.Size(96, 24);
+ this.категорииToolStripMenuItem.Text = "Категории";
+ this.категорииToolStripMenuItem.Click += new System.EventHandler(this.категорииToolStripMenuItem_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
@@ -96,5 +105,6 @@
private MenuStrip menuStrip1;
private ToolStripMenuItem ролиToolStripMenuItem;
private ToolStripMenuItem пользователиToolStripMenuItem;
+ private ToolStripMenuItem категорииToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/Forum/Forum/FormMain.cs b/Forum/Forum/FormMain.cs
index f25e000..c511ec0 100644
--- a/Forum/Forum/FormMain.cs
+++ b/Forum/Forum/FormMain.cs
@@ -26,5 +26,15 @@ namespace Forum
form.ShowDialog();
}
}
+
+ private void ToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCategories));
+
+ if (service is FormCategories form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Forum/Forum/FormUser.cs b/Forum/Forum/FormUser.cs
index 2b061b6..aff3e76 100644
--- a/Forum/Forum/FormUser.cs
+++ b/Forum/Forum/FormUser.cs
@@ -1,5 +1,6 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
+using ForumContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -16,6 +17,9 @@ namespace Forum
{
private readonly IUserLogic _userLogic;
private readonly IRoleLogic _roleLogic;
+
+ private int? _id;
+ public int Id { set { _id = value; } }
public FormUser(IRoleLogic roleLogic, IUserLogic userLogic)
{
InitializeComponent();
@@ -47,14 +51,16 @@ namespace Forum
}
try
{
- var operationResult = _userLogic.Create(new UserBindingModel
+ var model = new UserBindingModel
{
+ Id = _id ?? 0,
Username = textBoxUsername.Text,
Email = textBoxLogin.Text,
Password = textBoxPassword.Text,
RegistrationDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
RoleId = Convert.ToInt32(comboBoxSelectRole.SelectedValue),
- });
+ };
+ var operationResult = _id.HasValue ? _userLogic.Update(model) : _userLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при создании пользователя.");
@@ -76,6 +82,29 @@ namespace Forum
}
private void FormUser_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ if (_id.HasValue)
+ {
+ try
+ {
+ var view = _userLogic.ReadElement(new UserSearchModel { Id = _id.Value });
+
+ if (view != null)
+ {
+ textBoxLogin.Text = view.Email;
+ textBoxPassword.Text = view.Password;
+ textBoxUsername.Text = view.Username;
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
{
try
{
diff --git a/Forum/Forum/FormUsers.cs b/Forum/Forum/FormUsers.cs
index 5f6d6cc..c229f7c 100644
--- a/Forum/Forum/FormUsers.cs
+++ b/Forum/Forum/FormUsers.cs
@@ -1,4 +1,6 @@
-using ForumContracts.BusinessLogicContracts;
+using ForumBusinessLogic;
+using ForumContracts.BindingModels;
+using ForumContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -59,12 +61,48 @@ namespace Forum
private void buttonChange_Click(object sender, EventArgs e)
{
- this.Close();
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormUser));
+
+ if (service is FormUser form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
}
private void buttonDelete_Click(object sender, EventArgs e)
{
- this.Close();
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ try
+ {
+ if (!_userLogic.Delete(new UserBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
private void buttonUpdate_Click(object sender, EventArgs e)
diff --git a/Forum/Forum/Program.cs b/Forum/Forum/Program.cs
index f8b9029..8087916 100644
--- a/Forum/Forum/Program.cs
+++ b/Forum/Forum/Program.cs
@@ -44,6 +44,10 @@ namespace Forum
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/Forum/ForumContracts/SearchModels/TopicSearchModel.cs b/Forum/ForumContracts/SearchModels/TopicSearchModel.cs
index 56f53a5..5385d52 100644
--- a/Forum/ForumContracts/SearchModels/TopicSearchModel.cs
+++ b/Forum/ForumContracts/SearchModels/TopicSearchModel.cs
@@ -8,7 +8,7 @@ namespace ForumContracts.SearchModels
{
public class TopicSearchModel
{
- public int Id { get; set; }
+ public int? Id { get; set; }
public string? Name { get; set; }
}
}
diff --git a/Forum/ForumDatabase/Implements/CategoryStorage.cs b/Forum/ForumDatabase/Implements/CategoryStorage.cs
index cded997..01b8365 100644
--- a/Forum/ForumDatabase/Implements/CategoryStorage.cs
+++ b/Forum/ForumDatabase/Implements/CategoryStorage.cs
@@ -2,6 +2,7 @@
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
+using ForumDatabase.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,32 +15,77 @@ namespace ForumDatabase.Implements
{
public CategoryViewModel? Delete(CategoryBindingModel model)
{
- throw new NotImplementedException();
+ using var context = new ForumDatabase();
+ var element = context.Categories.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Categories.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
}
public CategoryViewModel? GetElement(CategorySearchModel model)
{
- throw new NotImplementedException();
+ if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new ForumDatabase();
+ return context.Categories
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.Name) && x.Name ==
+ model.Name) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
}
public List GetFilteredList(CategorySearchModel model)
{
- throw new NotImplementedException();
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return new();
+ }
+ using var context = new ForumDatabase();
+ return context.Categories
+ .Where(x => x.Name.Contains(model.Name))
+ .Select(x => x.GetViewModel)
+ .ToList();
}
public List GetFullList()
{
- throw new NotImplementedException();
+ using var context = new ForumDatabase();
+ return context.Categories
+ .Select(x => x.GetViewModel)
+ .ToList();
}
public CategoryViewModel? Insert(CategoryBindingModel model)
{
- throw new NotImplementedException();
+ var newCategory = Category.Create(model);
+ if (newCategory == null)
+ {
+ return null;
+ }
+ using var context = new ForumDatabase();
+ context.Categories.Add(newCategory);
+ context.SaveChanges();
+ return newCategory.GetViewModel;
}
public CategoryViewModel? Update(CategoryBindingModel model)
{
- throw new NotImplementedException();
+ using var context = new ForumDatabase();
+ var component = context.Categories.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ context.SaveChanges();
+ return component.GetViewModel;
}
}
}
diff --git a/Forum/ForumDatabase/Implements/TopicStorage.cs b/Forum/ForumDatabase/Implements/TopicStorage.cs
index 4cd49d4..e02a7cf 100644
--- a/Forum/ForumDatabase/Implements/TopicStorage.cs
+++ b/Forum/ForumDatabase/Implements/TopicStorage.cs
@@ -2,6 +2,7 @@
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
+using ForumDatabase.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,32 +15,77 @@ namespace ForumDatabase.Implements
{
public TopicViewModel? Delete(TopicBindingModel model)
{
- throw new NotImplementedException();
+ using var context = new ForumDatabase();
+ var element = context.Topics.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Topics.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
}
public TopicViewModel? GetElement(TopicSearchModel model)
{
- throw new NotImplementedException();
+ if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new ForumDatabase();
+ return context.Topics
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.Name) && x.Name ==
+ model.Name) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
}
public List GetFilteredList(TopicSearchModel model)
{
- throw new NotImplementedException();
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return new();
+ }
+ using var context = new ForumDatabase();
+ return context.Topics
+ .Where(x => x.Name.Contains(model.Name))
+ .Select(x => x.GetViewModel)
+ .ToList();
}
public List GetFullList()
{
- throw new NotImplementedException();
+ using var context = new ForumDatabase();
+ return context.Topics
+ .Select(x => x.GetViewModel)
+ .ToList();
}
public TopicViewModel? Insert(TopicBindingModel model)
{
- throw new NotImplementedException();
+ var newTopic = Topic.Create(model);
+ if (newTopic == null)
+ {
+ return null;
+ }
+ using var context = new ForumDatabase();
+ context.Topics.Add(newTopic);
+ context.SaveChanges();
+ return newTopic.GetViewModel;
}
public TopicViewModel? Update(TopicBindingModel model)
{
- throw new NotImplementedException();
+ using var context = new ForumDatabase();
+ var component = context.Topics.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ context.SaveChanges();
+ return component.GetViewModel;
}
}
}