From 47aa3185927d0215312a78edb8a420265091ac4e Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Mon, 1 May 2023 19:05:49 +0400 Subject: [PATCH] =?UTF-8?q?=D1=8D=D1=82=D0=B0=D0=BF=20=D1=81=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D0=BC=D0=B8=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Forum/Forum/FormAddTopic.Designer.cs | 22 ++- Forum/Forum/FormAddTopic.cs | 51 +++++- Forum/Forum/FormAddTopics.Designer.cs | 62 ++++--- Forum/Forum/FormAddTopics.cs | 45 ++++- Forum/Forum/FormCreateMessage.Designer.cs | 156 ++++++++++++++++++ Forum/Forum/FormCreateMessage.cs | 139 ++++++++++++++++ Forum/Forum/FormCreateMessage.resx | 60 +++++++ Forum/Forum/FormMain.Designer.cs | 81 ++++++--- Forum/Forum/FormMain.cs | 99 ++++++++++- Forum/Forum/Program.cs | 1 + Forum/ForumBusinessLogic/TopicLogic.cs | 4 - .../BindingModels/MessageBindingModel.cs | 4 + .../BindingModels/TopicBindingModel.cs | 2 + .../SearchModels/MessageSearchModel.cs | 2 +- .../SearchModels/TopicSearchModel.cs | 1 + .../ViewModels/MessageViewModel.cs | 10 ++ .../ViewModels/TopicViewModel.cs | 2 + Forum/ForumDataModels/ITopicModel.cs | 2 + .../Implements/MessageStorage.cs | 56 ++++++- .../ForumDatabase/Implements/TopicStorage.cs | 12 +- Forum/ForumDatabase/Implements/UserStorage.cs | 4 + Forum/ForumDatabase/Models/Message.cs | 10 ++ Forum/ForumDatabase/Models/Topic.cs | 4 + 23 files changed, 754 insertions(+), 75 deletions(-) create mode 100644 Forum/Forum/FormCreateMessage.Designer.cs create mode 100644 Forum/Forum/FormCreateMessage.cs create mode 100644 Forum/Forum/FormCreateMessage.resx diff --git a/Forum/Forum/FormAddTopic.Designer.cs b/Forum/Forum/FormAddTopic.Designer.cs index 4052661..ff1e157 100644 --- a/Forum/Forum/FormAddTopic.Designer.cs +++ b/Forum/Forum/FormAddTopic.Designer.cs @@ -35,37 +35,43 @@ // // textBoxTopic // - this.textBoxTopic.Location = new System.Drawing.Point(20, 12); + this.textBoxTopic.Location = new System.Drawing.Point(18, 9); + this.textBoxTopic.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxTopic.Name = "textBoxTopic"; - this.textBoxTopic.Size = new System.Drawing.Size(218, 27); + this.textBoxTopic.Size = new System.Drawing.Size(191, 23); this.textBoxTopic.TabIndex = 0; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(20, 45); + this.buttonSave.Location = new System.Drawing.Point(18, 34); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.Size = new System.Drawing.Size(82, 22); 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(144, 45); + this.buttonCancel.Location = new System.Drawing.Point(126, 34); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.Size = new System.Drawing.Size(82, 22); this.buttonCancel.TabIndex = 2; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // // FormAddTopic // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(251, 84); + this.ClientSize = new System.Drawing.Size(220, 63); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxTopic); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormAddTopic"; this.Text = "Тема"; this.ResumeLayout(false); diff --git a/Forum/Forum/FormAddTopic.cs b/Forum/Forum/FormAddTopic.cs index 68e2279..8d6158a 100644 --- a/Forum/Forum/FormAddTopic.cs +++ b/Forum/Forum/FormAddTopic.cs @@ -1,4 +1,6 @@ -using System; +using ForumContracts.BindingModels; +using ForumContracts.BusinessLogicContracts; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +14,54 @@ namespace Forum { public partial class FormAddTopic : Form { - public FormAddTopic() + private readonly ITopicLogic _topicLogic; + private readonly ICategoryLogic _categoryLogic; + + private int? _id; + public int Id { set { _id = value; } } + public FormAddTopic(ITopicLogic topicLogic, ICategoryLogic categoryLogic) { InitializeComponent(); + _topicLogic = topicLogic; + _categoryLogic = categoryLogic; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxTopic.Text)) + { + MessageBox.Show("Название темы не может быть пустой", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + try + { + var model = new TopicBindingModel + { + Name = textBoxTopic.Text, + CategoryId = _id ?? 0, + }; + var operationResult = _topicLogic.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(); } } } diff --git a/Forum/Forum/FormAddTopics.Designer.cs b/Forum/Forum/FormAddTopics.Designer.cs index dcf0410..3c91076 100644 --- a/Forum/Forum/FormAddTopics.Designer.cs +++ b/Forum/Forum/FormAddTopics.Designer.cs @@ -28,37 +28,41 @@ /// private void InitializeComponent() { - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.dataGridView = 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // - // dataGridView1 + // dataGridView // - 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; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 40); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(357, 141); + this.dataGridView.TabIndex = 0; // // textBoxCategory // - this.textBoxCategory.Location = new System.Drawing.Point(12, 12); + this.textBoxCategory.Location = new System.Drawing.Point(10, 9); + this.textBoxCategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBoxCategory.Name = "textBoxCategory"; - this.textBoxCategory.Size = new System.Drawing.Size(125, 27); + this.textBoxCategory.ReadOnly = true; + this.textBoxCategory.Size = new System.Drawing.Size(110, 23); this.textBoxCategory.TabIndex = 1; // // buttonCreate // - this.buttonCreate.Location = new System.Drawing.Point(435, 54); + this.buttonCreate.Location = new System.Drawing.Point(381, 40); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(94, 29); + this.buttonCreate.Size = new System.Drawing.Size(82, 22); this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Создать"; this.buttonCreate.UseVisualStyleBackColor = true; @@ -66,9 +70,10 @@ // // buttonChange // - this.buttonChange.Location = new System.Drawing.Point(435, 89); + this.buttonChange.Location = new System.Drawing.Point(381, 67); + this.buttonChange.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonChange.Name = "buttonChange"; - this.buttonChange.Size = new System.Drawing.Size(94, 29); + this.buttonChange.Size = new System.Drawing.Size(82, 22); this.buttonChange.TabIndex = 3; this.buttonChange.Text = "Изменить"; this.buttonChange.UseVisualStyleBackColor = true; @@ -76,9 +81,10 @@ // // buttonDelete // - this.buttonDelete.Location = new System.Drawing.Point(435, 124); + this.buttonDelete.Location = new System.Drawing.Point(381, 93); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonDelete.Name = "buttonDelete"; - this.buttonDelete.Size = new System.Drawing.Size(94, 29); + this.buttonDelete.Size = new System.Drawing.Size(82, 22); this.buttonDelete.TabIndex = 4; this.buttonDelete.Text = "Удалить"; this.buttonDelete.UseVisualStyleBackColor = true; @@ -86,29 +92,31 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(435, 159); + this.buttonUpdate.Location = new System.Drawing.Point(381, 119); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(94, 29); + this.buttonUpdate.Size = new System.Drawing.Size(82, 22); this.buttonUpdate.TabIndex = 5; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // - // FormAddTopic + // FormAddTopics // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(536, 253); + this.ClientSize = new System.Drawing.Size(469, 190); 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.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormAddTopics"; this.Text = "Добавление тем"; this.Load += new System.EventHandler(this.FormAddTopic_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -116,7 +124,7 @@ #endregion - private DataGridView dataGridView1; + private DataGridView dataGridView; private TextBox textBoxCategory; private Button buttonCreate; private Button buttonChange; diff --git a/Forum/Forum/FormAddTopics.cs b/Forum/Forum/FormAddTopics.cs index 260b44f..43347fd 100644 --- a/Forum/Forum/FormAddTopics.cs +++ b/Forum/Forum/FormAddTopics.cs @@ -1,4 +1,5 @@ -using ForumContracts.BusinessLogicContracts; +using ForumContracts.BindingModels; +using ForumContracts.BusinessLogicContracts; using ForumContracts.SearchModels; using System; using System.Collections.Generic; @@ -27,6 +28,7 @@ namespace Forum private void FormAddTopic_Load(object sender, EventArgs e) { + LoadData(); try { var view = _categoryLogic.ReadElement(new CategorySearchModel { Id = _id.Value }); @@ -48,6 +50,7 @@ namespace Forum if (service is FormAddTopic form) { + form.Id = _id ?? 0; if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -57,7 +60,20 @@ namespace Forum private void LoadData() { - throw new NotImplementedException(); + try + { + var list = _topicLogic.ReadList(new TopicSearchModel { CategoryId = _id }); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["CategoryId"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception) + { } } private void buttonChange_Click(object sender, EventArgs e) @@ -67,12 +83,35 @@ namespace Forum 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 (!_topicLogic.Delete(new TopicBindingModel + { + 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) { - + LoadData(); } } } diff --git a/Forum/Forum/FormCreateMessage.Designer.cs b/Forum/Forum/FormCreateMessage.Designer.cs new file mode 100644 index 0000000..420c8b6 --- /dev/null +++ b/Forum/Forum/FormCreateMessage.Designer.cs @@ -0,0 +1,156 @@ +namespace Forum +{ + partial class FormCreateMessage + { + /// + /// 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.comboBoxCategory = new System.Windows.Forms.ComboBox(); + this.comboBoxTopic = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.comboBoxUser = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.textBoxMessage = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxCategory + // + this.comboBoxCategory.FormattingEnabled = true; + this.comboBoxCategory.Location = new System.Drawing.Point(141, 6); + this.comboBoxCategory.Name = "comboBoxCategory"; + this.comboBoxCategory.Size = new System.Drawing.Size(147, 23); + this.comboBoxCategory.TabIndex = 0; + this.comboBoxCategory.SelectedIndexChanged += new System.EventHandler(this.comboBoxCategory_SelectedIndexChanged); + // + // comboBoxTopic + // + this.comboBoxTopic.FormattingEnabled = true; + this.comboBoxTopic.Location = new System.Drawing.Point(141, 35); + this.comboBoxTopic.Name = "comboBoxTopic"; + this.comboBoxTopic.Size = new System.Drawing.Size(147, 23); + this.comboBoxTopic.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(123, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Выберите категорию"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 38); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(90, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Выберите тему"; + // + // comboBoxUser + // + this.comboBoxUser.FormattingEnabled = true; + this.comboBoxUser.Location = new System.Drawing.Point(141, 64); + this.comboBoxUser.Name = "comboBoxUser"; + this.comboBoxUser.Size = new System.Drawing.Size(147, 23); + this.comboBoxUser.TabIndex = 4; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 67); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(84, 15); + this.label3.TabIndex = 5; + this.label3.Text = "Пользователь"; + // + // textBoxMessage + // + this.textBoxMessage.Location = new System.Drawing.Point(12, 93); + this.textBoxMessage.Multiline = true; + this.textBoxMessage.Name = "textBoxMessage"; + this.textBoxMessage.Size = new System.Drawing.Size(276, 70); + this.textBoxMessage.TabIndex = 6; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(132, 169); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(213, 169); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 8; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormCreateMessage + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(296, 198); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxMessage); + this.Controls.Add(this.label3); + this.Controls.Add(this.comboBoxUser); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxTopic); + this.Controls.Add(this.comboBoxCategory); + this.Name = "FormCreateMessage"; + this.Text = "Написать сообщение"; + this.Load += new System.EventHandler(this.FormCreateMessage_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxCategory; + private ComboBox comboBoxTopic; + private Label label1; + private Label label2; + private ComboBox comboBoxUser; + private Label label3; + private TextBox textBoxMessage; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Forum/Forum/FormCreateMessage.cs b/Forum/Forum/FormCreateMessage.cs new file mode 100644 index 0000000..d1e43a3 --- /dev/null +++ b/Forum/Forum/FormCreateMessage.cs @@ -0,0 +1,139 @@ +using ForumBusinessLogic; +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 FormCreateMessage : Form + { + private readonly IMessageLogic _messageLogic; + private readonly ICategoryLogic _categoryLogic; + private readonly ITopicLogic _topicLogic; + private readonly IUserLogic _userLogic; + + private int? _id; + public int Id { set { _id = value; } } + public FormCreateMessage(ICategoryLogic categoryLogic, ITopicLogic topicLogic, IUserLogic userLogic, IMessageLogic messageLogic) + { + InitializeComponent(); + _categoryLogic = categoryLogic; + _topicLogic = topicLogic; + _userLogic = userLogic; + _messageLogic = messageLogic; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxCategory.SelectedValue == null) + { + MessageBox.Show("Выберите категорию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxTopic.SelectedValue == null) + { + MessageBox.Show("Выберите тему", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxUser.SelectedValue == null) + { + MessageBox.Show("Выберите пользователя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxMessage.Text)) + { + MessageBox.Show("Напишите сообщение", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new MessageBindingModel + { + Id = _id ?? 0, + Date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + Text = textBoxMessage.Text, + TopicId = Convert.ToInt32(comboBoxTopic.SelectedValue), + UserId = Convert.ToInt32(comboBoxUser.SelectedValue), + }; + var operationResult = _id.HasValue ? _messageLogic.Update(model) : _messageLogic.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) + { + + } + + private void FormCreateMessage_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var user = _userLogic.ReadList(null); + if (user != null) + { + comboBoxUser.DisplayMember = "Username"; + comboBoxUser.ValueMember = "Id"; + comboBoxUser.DataSource = user; + comboBoxUser.SelectedItem = null; + } + var category = _categoryLogic.ReadList(null); + if (category != null) + { + comboBoxCategory.DisplayMember = "Name"; + comboBoxCategory.ValueMember = "Id"; + comboBoxCategory.DataSource = category; + comboBoxCategory.SelectedItem = null; + } + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void comboBoxCategory_SelectedIndexChanged(object sender, EventArgs e) + { + try + { + var topics = _topicLogic.ReadList(new TopicSearchModel { CategoryId = Convert.ToInt32(comboBoxCategory.SelectedValue), }); + if (topics != null) + { + comboBoxTopic.DisplayMember = "Name"; + comboBoxTopic.ValueMember = "Id"; + comboBoxTopic.DataSource = topics; + comboBoxTopic.SelectedItem = null; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Forum/Forum/FormCreateMessage.resx b/Forum/Forum/FormCreateMessage.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Forum/Forum/FormCreateMessage.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 1f48017..e4782be 100644 --- a/Forum/Forum/FormMain.Designer.cs +++ b/Forum/Forum/FormMain.Designer.cs @@ -28,24 +28,28 @@ /// private void InitializeComponent() { - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.dataGridView = new System.Windows.Forms.DataGridView(); 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.buttonCreate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // - // dataGridView1 + // dataGridView // - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Location = new System.Drawing.Point(12, 43); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersWidth = 51; - this.dataGridView1.RowTemplate.Height = 29; - this.dataGridView1.Size = new System.Drawing.Size(776, 395); - this.dataGridView1.TabIndex = 0; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 32); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(554, 296); + this.dataGridView.TabIndex = 0; // // menuStrip1 // @@ -56,42 +60,78 @@ this.категорииToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(800, 28); + this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(653, 24); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // // ролиToolStripMenuItem // this.ролиToolStripMenuItem.Name = "ролиToolStripMenuItem"; - this.ролиToolStripMenuItem.Size = new System.Drawing.Size(57, 24); + this.ролиToolStripMenuItem.Size = new System.Drawing.Size(47, 20); this.ролиToolStripMenuItem.Text = "Роли"; this.ролиToolStripMenuItem.Click += new System.EventHandler(this.ролиToolStripMenuItem_Click); // // пользователиToolStripMenuItem // this.пользователиToolStripMenuItem.Name = "пользователиToolStripMenuItem"; - this.пользователиToolStripMenuItem.Size = new System.Drawing.Size(122, 24); + this.пользователиToolStripMenuItem.Size = new System.Drawing.Size(97, 20); 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.Size = new System.Drawing.Size(76, 20); this.категорииToolStripMenuItem.Text = "Категории"; this.категорииToolStripMenuItem.Click += new System.EventHandler(this.категорииToolStripMenuItem_Click); // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(570, 32); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(570, 61); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(75, 23); + 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(570, 90); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(75, 23); + this.buttonUpdate.TabIndex = 5; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.dataGridView1); + this.ClientSize = new System.Drawing.Size(653, 338); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormMain"; this.Text = "Форум"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); @@ -101,10 +141,13 @@ #endregion - private DataGridView dataGridView1; + private DataGridView dataGridView; private MenuStrip menuStrip1; private ToolStripMenuItem ролиToolStripMenuItem; private ToolStripMenuItem пользователиToolStripMenuItem; private ToolStripMenuItem категорииToolStripMenuItem; + private Button buttonCreate; + private Button buttonDelete; + private Button buttonUpdate; } } \ No newline at end of file diff --git a/Forum/Forum/FormMain.cs b/Forum/Forum/FormMain.cs index c511ec0..a4a617d 100644 --- a/Forum/Forum/FormMain.cs +++ b/Forum/Forum/FormMain.cs @@ -1,10 +1,17 @@ +using ForumBusinessLogic; +using ForumContracts.BindingModels; +using ForumContracts.BusinessLogicContracts; +using System.Windows.Forms; + namespace Forum { public partial class FormMain : Form { - public FormMain() + private readonly IMessageLogic _messageLogic; + public FormMain(IMessageLogic messageLogic) { InitializeComponent(); + _messageLogic = messageLogic; } private void ToolStripMenuItem_Click(object sender, EventArgs e) @@ -36,5 +43,95 @@ namespace Forum form.ShowDialog(); } } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateMessage)); + + if (service is FormCreateMessage form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _messageLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["UserId"].Visible = false; + dataGridView.Columns["TopicId"].Visible = false; + dataGridView.Columns["Username"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["TopicName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + 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 (!_messageLogic.Delete(new MessageBindingModel + { + 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) + { + LoadData(); + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateMessage)); + + if (service is FormCreateMessage form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } } } \ No newline at end of file diff --git a/Forum/Forum/Program.cs b/Forum/Forum/Program.cs index 8087916..a5bbbf4 100644 --- a/Forum/Forum/Program.cs +++ b/Forum/Forum/Program.cs @@ -48,6 +48,7 @@ namespace Forum services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Forum/ForumBusinessLogic/TopicLogic.cs b/Forum/ForumBusinessLogic/TopicLogic.cs index 1391f4c..7e15a7a 100644 --- a/Forum/ForumBusinessLogic/TopicLogic.cs +++ b/Forum/ForumBusinessLogic/TopicLogic.cs @@ -94,10 +94,6 @@ namespace ForumBusinessLogic Name = model.Name } ); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Тема с таким названием уже есть"); - } } } } diff --git a/Forum/ForumContracts/BindingModels/MessageBindingModel.cs b/Forum/ForumContracts/BindingModels/MessageBindingModel.cs index b59165d..8351c66 100644 --- a/Forum/ForumContracts/BindingModels/MessageBindingModel.cs +++ b/Forum/ForumContracts/BindingModels/MessageBindingModel.cs @@ -14,5 +14,9 @@ namespace ForumContracts.BindingModels public DateTime Date { get; set; } public int Id { get; set; } + + public int TopicId { get; set; } + + public int UserId { get; set; } } } diff --git a/Forum/ForumContracts/BindingModels/TopicBindingModel.cs b/Forum/ForumContracts/BindingModels/TopicBindingModel.cs index 00083b6..e2deb6d 100644 --- a/Forum/ForumContracts/BindingModels/TopicBindingModel.cs +++ b/Forum/ForumContracts/BindingModels/TopicBindingModel.cs @@ -12,5 +12,7 @@ namespace ForumContracts.BindingModels public string Name { get; set; } = string.Empty; public int Id { get; set; } + + public int CategoryId { get; set; } } } diff --git a/Forum/ForumContracts/SearchModels/MessageSearchModel.cs b/Forum/ForumContracts/SearchModels/MessageSearchModel.cs index a6c2941..49cd0df 100644 --- a/Forum/ForumContracts/SearchModels/MessageSearchModel.cs +++ b/Forum/ForumContracts/SearchModels/MessageSearchModel.cs @@ -8,7 +8,7 @@ namespace ForumContracts.SearchModels { public class MessageSearchModel { - public int Id { get; set; } + public int? Id { get; set; } public DateTime Date { get; set; } } } diff --git a/Forum/ForumContracts/SearchModels/TopicSearchModel.cs b/Forum/ForumContracts/SearchModels/TopicSearchModel.cs index 5385d52..a1700bd 100644 --- a/Forum/ForumContracts/SearchModels/TopicSearchModel.cs +++ b/Forum/ForumContracts/SearchModels/TopicSearchModel.cs @@ -10,5 +10,6 @@ namespace ForumContracts.SearchModels { public int? Id { get; set; } public string? Name { get; set; } + public int? CategoryId { get; set; } } } diff --git a/Forum/ForumContracts/ViewModels/MessageViewModel.cs b/Forum/ForumContracts/ViewModels/MessageViewModel.cs index 8c0ed77..6f548b5 100644 --- a/Forum/ForumContracts/ViewModels/MessageViewModel.cs +++ b/Forum/ForumContracts/ViewModels/MessageViewModel.cs @@ -10,6 +10,16 @@ namespace ForumContracts.ViewModels { public class MessageViewModel : IMessageModel { + public int UserId { get; set; } + + [DisplayName("Пользователь")] + public string Username { get; set; } = string.Empty; + + public int TopicId { get; set; } + + [DisplayName("Название темы")] + public string TopicName { get; set; } = string.Empty; + [DisplayName("Текст сообщения")] public string Text { get; set; } = string.Empty; diff --git a/Forum/ForumContracts/ViewModels/TopicViewModel.cs b/Forum/ForumContracts/ViewModels/TopicViewModel.cs index 7e2d805..4266b24 100644 --- a/Forum/ForumContracts/ViewModels/TopicViewModel.cs +++ b/Forum/ForumContracts/ViewModels/TopicViewModel.cs @@ -14,5 +14,7 @@ namespace ForumContracts.ViewModels public string Name { get; set; } = string.Empty; public int Id { get; set; } + + public int CategoryId { get; set; } } } diff --git a/Forum/ForumDataModels/ITopicModel.cs b/Forum/ForumDataModels/ITopicModel.cs index ab60620..4f8f2a2 100644 --- a/Forum/ForumDataModels/ITopicModel.cs +++ b/Forum/ForumDataModels/ITopicModel.cs @@ -9,5 +9,7 @@ namespace ForumDataModels public interface ITopicModel : IId { string Name { get; } + + int CategoryId { get; } } } diff --git a/Forum/ForumDatabase/Implements/MessageStorage.cs b/Forum/ForumDatabase/Implements/MessageStorage.cs index 943eaeb..32dace5 100644 --- a/Forum/ForumDatabase/Implements/MessageStorage.cs +++ b/Forum/ForumDatabase/Implements/MessageStorage.cs @@ -2,6 +2,8 @@ using ForumContracts.SearchModels; using ForumContracts.StoragesContracts; using ForumContracts.ViewModels; +using ForumDatabase.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -14,32 +16,74 @@ namespace ForumDatabase.Implements { public MessageViewModel? Delete(MessageBindingModel model) { - throw new NotImplementedException(); + using var context = new ForumDatabase(); + var element = context.Messages.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Messages.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; } public MessageViewModel? GetElement(MessageSearchModel model) { - throw new NotImplementedException(); + if (!model.Id.HasValue) + { + return null; + } + using var context = new ForumDatabase(); + return context.Messages + .Include(x => x.User) + .Include(x => x.Topic) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id).GetViewModel; } public List GetFilteredList(MessageSearchModel model) { - throw new NotImplementedException(); + using var context = new ForumDatabase(); + return context.Messages + .Include(x => x.User) + .Include(x => x.Topic) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { - throw new NotImplementedException(); + using var context = new ForumDatabase(); + return context.Messages + .Include(x => x.User) + .Include(x => x.Topic) + .Select(x => x.GetViewModel) + .ToList(); } public MessageViewModel? Insert(MessageBindingModel model) { - throw new NotImplementedException(); + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + using var context = new ForumDatabase(); + context.Messages.Add(newMessage); + context.SaveChanges(); + return newMessage.GetViewModel; } public MessageViewModel? Update(MessageBindingModel model) { - throw new NotImplementedException(); + using var context = new ForumDatabase(); + var component = context.Messages.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 e02a7cf..74e1e8d 100644 --- a/Forum/ForumDatabase/Implements/TopicStorage.cs +++ b/Forum/ForumDatabase/Implements/TopicStorage.cs @@ -3,6 +3,7 @@ using ForumContracts.SearchModels; using ForumContracts.StoragesContracts; using ForumContracts.ViewModels; using ForumDatabase.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -43,11 +44,14 @@ namespace ForumDatabase.Implements public List GetFilteredList(TopicSearchModel model) { - if (string.IsNullOrEmpty(model.Name)) - { - return new(); - } using var context = new ForumDatabase(); + if (model.CategoryId.HasValue) + { + return context.Topics + .Where(x => x.CategoryId == model.CategoryId) + .Select(x => x.GetViewModel) + .ToList(); + } return context.Topics .Where(x => x.Name.Contains(model.Name)) .Select(x => x.GetViewModel) diff --git a/Forum/ForumDatabase/Implements/UserStorage.cs b/Forum/ForumDatabase/Implements/UserStorage.cs index 6d98bb9..12f0b07 100644 --- a/Forum/ForumDatabase/Implements/UserStorage.cs +++ b/Forum/ForumDatabase/Implements/UserStorage.cs @@ -3,6 +3,7 @@ using ForumContracts.SearchModels; using ForumContracts.StoragesContracts; using ForumContracts.ViewModels; using ForumDatabase.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -34,6 +35,7 @@ namespace ForumDatabase.Implements } using var context = new ForumDatabase(); return context.Users + .Include(x => x.Role) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Username) && x.Username == model.Username) || @@ -49,6 +51,7 @@ namespace ForumDatabase.Implements } using var context = new ForumDatabase(); return context.Users + .Include(x => x.Role) .Where(x => x.Username.Contains(model.Username)) .Select(x => x.GetViewModel) .ToList(); @@ -58,6 +61,7 @@ namespace ForumDatabase.Implements { using var context = new ForumDatabase(); return context.Users + .Include(x => x.Role) .Select(x => x.GetViewModel) .ToList(); } diff --git a/Forum/ForumDatabase/Models/Message.cs b/Forum/ForumDatabase/Models/Message.cs index 0b01032..18935e5 100644 --- a/Forum/ForumDatabase/Models/Message.cs +++ b/Forum/ForumDatabase/Models/Message.cs @@ -27,6 +27,10 @@ namespace ForumDatabase.Models [Required] public int TopicId { get; set; } + public virtual User? User { get; set; } + + public virtual Topic? Topic { get; set; } + public static Message? Create(MessageBindingModel model) { if (model == null) @@ -38,6 +42,8 @@ namespace ForumDatabase.Models Id = model.Id, Text = model.Text, Date = model.Date, + UserId = model.UserId, + TopicId = model.TopicId, }; } public void Update(MessageBindingModel model) @@ -54,6 +60,10 @@ namespace ForumDatabase.Models Id = Id, Text = Text, Date = Date, + TopicId = TopicId, + UserId = UserId, + Username = User == null ? string.Empty : User.Username, + TopicName = Topic == null ? string.Empty : Topic.Name, }; } } diff --git a/Forum/ForumDatabase/Models/Topic.cs b/Forum/ForumDatabase/Models/Topic.cs index 7168cca..3ff3961 100644 --- a/Forum/ForumDatabase/Models/Topic.cs +++ b/Forum/ForumDatabase/Models/Topic.cs @@ -28,6 +28,8 @@ namespace ForumDatabase.Models [ForeignKey("MessageId")] List Messages { get; set; } = new(); + public virtual Category? Category { get; set; } + public static Topic? Create(TopicBindingModel model) { if (model == null) @@ -38,6 +40,7 @@ namespace ForumDatabase.Models { Id = model.Id, Name = model.Name, + CategoryId = model.CategoryId, }; } public void Update(TopicBindingModel model) @@ -53,6 +56,7 @@ namespace ForumDatabase.Models { Id = Id, Name = Name, + CategoryId = CategoryId, }; } }