From 278b4efe7d04c0080db88b8aededadf379144d62 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Fri, 21 Apr 2023 23:21:49 +0400 Subject: [PATCH 1/8] lab 7 complete --- .../BindingModels/ComponentBindingModel.cs | 2 - .../BindingModels/ImplementerBindingModel.cs | 4 - .../BindingModels/MailConfigBindingModel.cs | 18 ++++ .../BindingModels/MailSendInfoBindingModel.cs | 9 ++ .../BindingModels/MessageInfoBindingModel.cs | 19 ++++ .../BindingModels/OrderBindingModel.cs | 8 -- .../BindingModels/PackageBindingModel.cs | 3 - .../IMessageInfoLogic.cs | 13 +++ .../SearchModels/MessageInfoSearchModel.cs | 8 ++ .../StoragesContracts/IMessageInfoStorage.cs | 17 ++++ .../ViewModels/MessageInfoViewModel.cs | 24 +++++ .../SoftwareInstallation/App.config | 11 +++ .../FormMails.Designer.cs | 62 +++++++++++++ .../SoftwareInstallation/FormMails.cs | 47 ++++++++++ .../SoftwareInstallation/FormMails.resx | 60 +++++++++++++ .../SoftwareInstallation/FormMain.Designer.cs | 30 ++++--- .../SoftwareInstallation/FormMain.cs | 9 ++ .../SoftwareInstallation/Program.cs | 28 ++++++ .../BusinessLogic/ClientLogic.cs | 18 ++++ .../BusinessLogic/MessageInfoLogic.cs | 50 +++++++++++ .../BusinessLogic/OrderLogic.cs | 58 +++++++++--- .../MailWorker/AbstractMailWorker.cs | 89 +++++++++++++++++++ .../MailWorker/MailKitWorker.cs | 78 ++++++++++++++++ .../SoftwareInstallationBusinessLogic.csproj | 1 + .../Controllers/HomeController.cs | 10 +++ .../Views/Home/Mails.cshtml | 54 +++++++++++ .../Views/Shared/_Layout.cshtml | 3 + .../Implements/MessageInfoStorage.cs | 51 +++++++++++ ...r.cs => 20230421190828_InitDB.Designer.cs} | 48 +++++++++- ...8_CreateBD.cs => 20230421190828_InitDB.cs} | 32 ++++++- ...ftwareInstallationDataBaseModelSnapshot.cs | 44 +++++++++ .../Models/Client.cs | 3 + .../Models/Message.cs | 51 +++++++++++ .../SoftwareInstallationDataBase.cs | 1 + .../Models/IMessageInfoModel.cs | 12 +++ .../DataFileSingleton.cs | 8 +- .../Implements/MessageInfoStorage.cs | 52 +++++++++++ .../Models/Message.cs | 75 ++++++++++++++++ .../DataListSingleton.cs | 2 + .../Implements/MessageInfoStorage.cs | 68 ++++++++++++++ .../Models/Message.cs | 53 +++++++++++ .../Controllers/ClientController.cs | 22 ++++- .../SoftwareInstallationRestApi/Program.cs | 18 ++++ .../appsettings.json | 9 +- 44 files changed, 1236 insertions(+), 46 deletions(-) create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs create mode 100644 SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/App.config create mode 100644 SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormMails.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormMails.resx create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml create mode 100644 SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230410192808_CreateBD.Designer.cs => 20230421190828_InitDB.Designer.cs} (84%) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230410192808_CreateBD.cs => 20230421190828_InitDB.cs} (84%) create mode 100644 SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ComponentBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ComponentBindingModel.cs index 331ecc3..613d22c 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ComponentBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ComponentBindingModel.cs @@ -5,9 +5,7 @@ namespace SofrwareInstallationContracts.BindingModels public class ComponentBindingModel : IComponentModel { public string ComponentName { get; set; } = string.Empty; - public double Cost { get; set; } - public int Id { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ImplementerBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ImplementerBindingModel.cs index 3326d3a..44f1aa9 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ImplementerBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/ImplementerBindingModel.cs @@ -5,13 +5,9 @@ namespace SofrwareInstallationContracts.BindingModels public class ImplementerBindingModel : IImplementerModel { public int Id { get; set; } - public string ImplementerFIO { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public int WorkExperience { get; set; } - public int Qualification { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailConfigBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..66d66e9 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SofrwareInstallationContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + public string MailPassword { get; set; } = string.Empty; + public string SmtpClientHost { get; set; } = string.Empty; + public int SmtpClientPort { get; set; } + public string PopHost { get; set; } = string.Empty; + public int PopPort { get; set; } + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..8ef8e71 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,9 @@ +namespace SofrwareInstallationContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..e4259c4 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,19 @@ +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SofrwareInstallationContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } + public string SenderName { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Body { get; set; } = string.Empty; + public DateTime DateDelivery { get; set; } + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/OrderBindingModel.cs index a1afb1d..2c07b3a 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/OrderBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -6,22 +6,14 @@ namespace SofrwareInstallationContracts.BindingModels public class OrderBindingModel : IOrderModel { public int PackageId { get; set; } - public int ClientId { 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; } - public int Id { get; set; } public string PackageName { get; set; } = string.Empty; - public int? ImplementerId { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/PackageBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/PackageBindingModel.cs index ab3f646..693e609 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/PackageBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/PackageBindingModel.cs @@ -5,11 +5,8 @@ namespace SofrwareInstallationContracts.BindingModels public class PackageBindingModel : IPackageModel { public string PackageName { get; set; } = string.Empty; - public double Price { get; set; } - public Dictionary PackageComponents { get; set; } = new(); - public int Id { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..f9155c7 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,13 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.SearchModels; +using SofrwareInstallationContracts.ViewModels; + +namespace SofrwareInstallationContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + + bool Create(MessageInfoBindingModel model); + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..e7d3396 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,8 @@ +namespace SofrwareInstallationContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public int? ClientId { get; set; } + public string? MessageId { get; set; } + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs b/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..9d9de85 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,17 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.SearchModels; +using SofrwareInstallationContracts.ViewModels; + +namespace SofrwareInstallationContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + + List GetFilteredList(MessageInfoSearchModel model); + + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..464ecc4 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,24 @@ +using SoftwareInstallationDataModels.Models; +using System.ComponentModel; + +namespace SofrwareInstallationContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [DisplayName("Имя отправителя")] + public string SenderName { get; set; } = string.Empty; + + [DisplayName("Дата отправления")] + public DateTime DateDelivery { get; set; } + + [DisplayName("Тема")] + public string Subject { get; set; } = string.Empty; + + [DisplayName("Содержание")] + public string Body { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/SoftwareInstallation/App.config b/SoftwareInstallation/SoftwareInstallation/App.config new file mode 100644 index 0000000..00e7e59 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs new file mode 100644 index 0000000..30f2ded --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs @@ -0,0 +1,62 @@ +namespace SoftwareInstallationView +{ + partial class FormMails + { + /// + /// 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(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(3, 3); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(794, 445); + this.DataGridView.TabIndex = 0; + // + // FormMails + // + 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.DataGridView); + this.Name = "FormMails"; + this.Text = "Эл. письма"; + this.Load += new System.EventHandler(this.FormMails_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.cs new file mode 100644 index 0000000..ebfb22b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.cs @@ -0,0 +1,47 @@ +using SofrwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormMails : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormMails(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["MessageId"].Visible = false; + DataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка писем"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки писем"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void FormMails_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.resx b/SoftwareInstallation/SoftwareInstallation/FormMails.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.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/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index 629c475..6fd62f8 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -33,6 +33,7 @@ this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -44,7 +45,7 @@ this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); - this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.элПисьмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -54,7 +55,8 @@ this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.СправочникиToolStripMenuItem, this.отчетыToolStripMenuItem, - this.запускРаботToolStripMenuItem}); + this.запускРаботToolStripMenuItem, + this.элПисьмаToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Size = new System.Drawing.Size(865, 24); @@ -75,24 +77,31 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.ИзделияToolStripMenuItem.Text = "Изделия"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -190,12 +199,12 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // исполнителиToolStripMenuItem + // элПисьмаToolStripMenuItem // - this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.исполнителиToolStripMenuItem.Text = "Исполнители"; - this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + this.элПисьмаToolStripMenuItem.Name = "элПисьмаToolStripMenuItem"; + this.элПисьмаToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.элПисьмаToolStripMenuItem.Text = "Эл. Письма"; + this.элПисьмаToolStripMenuItem.Click += new System.EventHandler(this.элПисьмаToolStripMenuItem_Click); // // FormMain // @@ -239,5 +248,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem элПисьмаToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index 6728d71..5a8b1fa 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -236,5 +236,14 @@ namespace SoftwareInstallationView form.ShowDialog(); } } + + private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if (service is FormMails form) + { + form.ShowDialog(); + } + } } } diff --git a/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index 1737baf..364e422 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -7,6 +7,8 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using SoftwareInstallationBusinessLogic.OfficePackage; using SoftwareInstallationBusinessLogic.OfficePackage.Implements; +using SofrwareInstallationContracts.BindingModels; +using SoftwareInstallationBusinessLogic.MailWorker; namespace SoftwareInstallationView { @@ -22,6 +24,26 @@ namespace SoftwareInstallationView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + try + { + var mailSender = _serviceProvider.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); + + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, "Error"); + } Application.Run(_serviceProvider.GetRequiredService()); } @@ -33,12 +55,15 @@ namespace SoftwareInstallationView option.AddNLog("nlog.config"); }); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -59,6 +84,9 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } + + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs index fc5ae1a..0a46a1d 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs @@ -4,6 +4,7 @@ using SofrwareInstallationContracts.BusinessLogicsContracts; using SofrwareInstallationContracts.SearchModels; using SofrwareInstallationContracts.StoragesContracts; using SofrwareInstallationContracts.ViewModels; +using System.Text.RegularExpressions; namespace SoftwareInstallationBusinessLogic.BusinessLogic { @@ -86,27 +87,44 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } + if (!withParams) { return; } + if (string.IsNullOrEmpty(model.ClientFIO)) { throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); } + if (string.IsNullOrEmpty(model.Email)) { throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); } + if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); } + + if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase)) + { + throw new ArgumentException("Неправильно введенный email", nameof(model.Email)); + } + + if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase)) + { + throw new ArgumentException("Неправильно введенный пароль", nameof(model.Password)); + } + _logger.LogInformation("Client. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}", model.ClientFIO, model.Email, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel { Email = model.Email }); + if (element != null && element.Id != model.Id) { throw new InvalidOperationException("Клиент с такой почтой уже есть"); diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs new file mode 100644 index 0000000..5bfdd58 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.SearchModels; +using SofrwareInstallationContracts.StoragesContracts; +using SofrwareInstallationContracts.ViewModels; + +namespace SoftwareInstallationBusinessLogic.BusinessLogic +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _messageStorage; + + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageStorage) + { + _logger = logger; + _messageStorage = messageStorage; + } + + public bool Create(MessageInfoBindingModel model) + { + if (_messageStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId); + var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + + return list; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs index 2aa04aa..28816fd 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,6 +5,7 @@ using SofrwareInstallationContracts.StoragesContracts; using SofrwareInstallationContracts.ViewModels; using Microsoft.Extensions.Logging; using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationBusinessLogic.MailWorker; namespace SoftwareInstallationBusinessLogic.BusinessLogic { @@ -12,11 +13,15 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly AbstractMailWorker _mailWorker; + private readonly IClientLogic _clientLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) { _logger = logger; _orderStorage = orderStorage; + _mailWorker = mailWorker; + _clientLogic = clientLogic; } public bool CreateOrder(OrderBindingModel model) @@ -30,14 +35,17 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic } model.Status = OrderStatus.Принят; + var result = _orderStorage.Insert(model); - if (_orderStorage.Insert(model) == null) + if (result == null) { model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } + SendOrderMessage(result.ClientId, $"Установка ПО, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); + return true; } @@ -71,13 +79,36 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic model.Sum = vmodel.Sum; model.Count = vmodel.Count; - if (_orderStorage.Update(model) == null) + var result = _orderStorage.Update(model); + + if (result == null) { _logger.LogWarning("Update operation failed"); return false; } + + SendOrderMessage(result.ClientId, $"Установка ПО, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}"); + return true; + } + + private bool SendOrderMessage(int clientId, string subject, string text) + { + var client = _clientLogic.ReadElement(new() { Id = clientId }); + + if (client == null) + { + return false; + } + + _mailWorker.MailSendAsync(new() + { + MailAddress = client.Email, + Subject = subject, + Text = text + }); + return true; } @@ -113,26 +144,29 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic return list; } - private bool CheckModel(OrderBindingModel model) + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } + if (!withParams) + { + return; + } + if (model.PackageId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у изделия", nameof(model.PackageId)); + } if (model.Count <= 0) { - throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); } if (model.Sum <= 0) { - throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } - if (model.DateCreate > model.DateImplement) - { - throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); - } - - return true; + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. PackageId: { PackageId}", model.Id, model.Sum, model.PackageId); } public OrderViewModel? ReadElement(OrderSearchModel model) diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..94c7488 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,89 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.BusinessLogicsContracts; + +namespace SoftwareInstallationBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + protected string _mailPassword = string.Empty; + protected string _smtpClientHost = string.Empty; + protected int _smtpClientPort; + protected string _popHost = string.Empty; + protected int _popPort; + private readonly IMessageInfoLogic _messageInfoLogic; + private readonly IClientLogic _clientLogic; + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + { + _logger = logger; + _messageInfoLogic = messageInfoLogic; + _clientLogic = clientLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + + await SendMailAsync(info); + } + + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + + if (_messageInfoLogic == null) + { + return; + } + + var list = await ReceiveMailAsync(); + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + + foreach (var mail in list) + { + mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id; + _messageInfoLogic.Create(mail); + } + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + protected abstract Task> ReceiveMailAsync(); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..ac5084e --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,78 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.BusinessLogicsContracts; +using System.Net.Mail; +using System.Net; +using System.Text; +using MailKit.Net.Pop3; +using MailKit.Security; + +namespace SoftwareInstallationBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) {} + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + + protected override async Task> ReceiveMailAsync() + { + var list = new List(); + using var client = new Pop3Client(); + await Task.Run(() => + { + try + { + client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + client.Authenticate(_mailLogin, _mailPassword); + for (int i = 0; i < client.Count; i++) + { + var message = client.GetMessage(i); + foreach (var mail in message.From.Mailboxes) + { + list.Add(new MessageInfoBindingModel + { + DateDelivery = message.Date.DateTime, + MessageId = message.MessageId, + SenderName = mail.Address, + Subject = message.Subject, + Body = message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + return list; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj index ebfbb91..1f3f49c 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs index 552c267..0dde025 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs @@ -143,5 +143,15 @@ namespace SoftwareInstallationClientApp.Controllers var prod = APIClient.GetRequest($"api/main/getpackage?packageId={package}"); return count * (prod?.Price ?? 1); } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..b151645 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using SofrwareInstallationContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Письма

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Тема + + Содержание +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml index 219e65e..d4a1ebf 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml @@ -25,6 +25,9 @@ + diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..5805cd3 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,51 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.SearchModels; +using SofrwareInstallationContracts.StoragesContracts; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationDataBaseImplement.Models; + +namespace SoftwareInstallationDataBaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId == null) + return null; + using var context = new SoftwareInstallationDataBase(); + return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + return new(); + using var context = new SoftwareInstallationDataBase(); + return context.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SoftwareInstallationDataBase(); + return context.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + using var context = new SoftwareInstallationDataBase(); + context.Messages.Add(newMessage); + context.SaveChanges(); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230410192808_CreateBD.Designer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.Designer.cs similarity index 84% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230410192808_CreateBD.Designer.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.Designer.cs index 485ae55..bac7ab4 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230410192808_CreateBD.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.Designer.cs @@ -12,8 +12,8 @@ using SoftwareInstallationDataBaseImplement; namespace SoftwareInstallationDataBaseImplement.Migrations { [DbContext(typeof(SoftwareInstallationDataBase))] - [Migration("20230410192808_CreateBD")] - partial class CreateBD + [Migration("20230421190828_InitDB")] + partial class InitDB { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -97,6 +97,37 @@ namespace SoftwareInstallationDataBaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -190,6 +221,17 @@ namespace SoftwareInstallationDataBaseImplement.Migrations b.ToTable("PackageComponents"); }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => { b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") @@ -236,6 +278,8 @@ namespace SoftwareInstallationDataBaseImplement.Migrations modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230410192808_CreateBD.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.cs similarity index 84% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230410192808_CreateBD.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.cs index 9862e67..2ff4e95 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230410192808_CreateBD.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace SoftwareInstallationDataBaseImplement.Migrations { /// - public partial class CreateBD : Migration + public partial class InitDB : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -70,6 +70,28 @@ namespace SoftwareInstallationDataBaseImplement.Migrations table.PrimaryKey("PK_Packages", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -135,6 +157,11 @@ namespace SoftwareInstallationDataBaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", @@ -164,6 +191,9 @@ namespace SoftwareInstallationDataBaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Messages"); + migrationBuilder.DropTable( name: "Orders"); diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs index a5b6253..5e5cc27 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs @@ -94,6 +94,37 @@ namespace SoftwareInstallationDataBaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -187,6 +218,17 @@ namespace SoftwareInstallationDataBaseImplement.Migrations b.ToTable("PackageComponents"); }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => { b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") @@ -233,6 +275,8 @@ namespace SoftwareInstallationDataBaseImplement.Migrations modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs index 2d1a8ad..f8a7864 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs @@ -18,6 +18,9 @@ namespace SoftwareInstallationDataBaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) { if (model == null) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs new file mode 100644 index 0000000..2f1b063 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs @@ -0,0 +1,51 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace SoftwareInstallationDataBaseImplement.Models +{ + public class Message : IMessageInfoModel + { + [Key] + public string MessageId { get; private set; } = string.Empty; + public int? ClientId { get; private set; } + [Required] + public string SenderName { get; private set; } = string.Empty; + [Required] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [Required] + public string Subject { get; private set; } = string.Empty; + [Required] + public string Body { get; private set; } = string.Empty; + + public virtual Client Client { get; set; } + + public static Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs index 70cba53..22a15c3 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs @@ -19,5 +19,6 @@ namespace SoftwareInstallationDataBaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } + public virtual DbSet Messages { set; get; } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..a27b3f7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,12 @@ +namespace SoftwareInstallationDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + int? ClientId { get; } + string SenderName { get; } + DateTime DateDelivery { get; } + string Subject { get; } + string Body { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs index e4e17d5..845f159 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs @@ -12,12 +12,14 @@ namespace SoftwareInstallationFileImplement private readonly string PackageFileName = "Package.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageFileName = "Message.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Packages { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List Messages { get; private set; } public static DataFileSingleton GetInstance() { @@ -31,8 +33,9 @@ namespace SoftwareInstallationFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName,"Components", x => x.GetXElement); public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); - public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement); + public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { @@ -41,6 +44,7 @@ namespace SoftwareInstallationFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + Messages = LoadData(MessageFileName, "Message", x => Message.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..7d4eac0 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,52 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.SearchModels; +using SofrwareInstallationContracts.StoragesContracts; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton source; + public MessageInfoStorage() + { + source = DataFileSingleton.GetInstance(); + } + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId == null) + return null; + return source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + return new(); + return source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + source.Messages.Add(newMessage); + source.SaveMessages(); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs new file mode 100644 index 0000000..cb19a04 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs @@ -0,0 +1,75 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Message : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery, + SenderName = model.SenderName, + ClientId = model.ClientId, + MessageId = model.MessageId + }; + } + + public static Message? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + SenderName = element.Attribute("SenderName")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery, + SenderName = SenderName, + ClientId = ClientId, + MessageId = MessageId + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Subject", Subject), + new XAttribute("Body", Body), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs index 4a27ab0..45d033a 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs @@ -10,6 +10,7 @@ namespace SoftwareInstallationListImplement public List Packages { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } private DataListSingleton() { @@ -18,6 +19,7 @@ namespace SoftwareInstallationListImplement Packages = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..2fbee70 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,68 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.SearchModels; +using SofrwareInstallationContracts.StoragesContracts; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; + +namespace SoftwareInstallationListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId == null) + { + return null; + } + foreach (var message in _source.Messages) + { + if (model.MessageId.Equals(message.MessageId)) + return message.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + { + return new(); + } + var result = new List(); + foreach (var item in _source.Messages) + { + if (item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs new file mode 100644 index 0000000..47cfc9e --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs @@ -0,0 +1,53 @@ +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement.Models +{ + public class Message : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery, + SenderName = model.SenderName, + ClientId = model.ClientId, + MessageId = model.MessageId + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery, + SenderName = SenderName, + ClientId = ClientId, + MessageId = MessageId + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs index 1bfc8d9..a777479 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs @@ -13,11 +13,15 @@ namespace SoftwareInstallationRestApi.Controllers { private readonly ILogger _logger; private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } + [HttpGet] public ClientViewModel? Login(string login, string password) { @@ -64,5 +68,21 @@ namespace SoftwareInstallationRestApi.Controllers } } + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } } } diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs index 928f907..5b96c9b 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs @@ -3,6 +3,8 @@ using SofrwareInstallationContracts.BusinessLogicsContracts; using SofrwareInstallationContracts.StoragesContracts; using SoftwareInstallationDataBaseImplement.Implements; using Microsoft.OpenApi.Models; +using SoftwareInstallationBusinessLogic.MailWorker; +using SofrwareInstallationContracts.BindingModels; var builder = WebApplication.CreateBuilder(args); @@ -13,10 +15,14 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -31,6 +37,18 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); + +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json b/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json index 10f68b8..d2cd417 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json +++ b/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "labwork7zhimol@gmail.com", + "MailPassword": "nnsz pcnf xezb gxtc" } -- 2.25.1 From 6dfb15852888a723f700381aad19c4ca16c16417 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Mon, 24 Apr 2023 22:15:12 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D1=8D=D1=82=D0=BE=D1=82=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B8=D1=82=20=D1=8D=D1=82=D0=BE=D1=82=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...828_InitDB.Designer.cs => 20230424175633_InitDB.Designer.cs} | 2 +- .../{20230421190828_InitDB.cs => 20230424175633_InitDB.cs} | 0 .../SoftwareInstallationDataBase.cs | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230421190828_InitDB.Designer.cs => 20230424175633_InitDB.Designer.cs} (99%) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230421190828_InitDB.cs => 20230424175633_InitDB.cs} (100%) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.Designer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.Designer.cs similarity index 99% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.Designer.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.Designer.cs index bac7ab4..a73aad1 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.Designer.cs @@ -12,7 +12,7 @@ using SoftwareInstallationDataBaseImplement; namespace SoftwareInstallationDataBaseImplement.Migrations { [DbContext(typeof(SoftwareInstallationDataBase))] - [Migration("20230421190828_InitDB")] + [Migration("20230424175633_InitDB")] partial class InitDB { /// diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.cs similarity index 100% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230421190828_InitDB.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.cs diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs index 22a15c3..1910dc2 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs @@ -9,7 +9,7 @@ namespace SoftwareInstallationDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VG5USAH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=COMP-AVZH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseFulllab7;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } -- 2.25.1 From fa8a87c95cb8e27d38c02153166acf15ba2d50d1 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Fri, 28 Apr 2023 16:16:56 +0400 Subject: [PATCH 3/8] lab 7 --- ...DB.Designer.cs => 20230428121613_InitDatabase.Designer.cs} | 4 ++-- ...0230424175633_InitDB.cs => 20230428121613_InitDatabase.cs} | 2 +- .../SoftwareInstallationDataBase.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230424175633_InitDB.Designer.cs => 20230428121613_InitDatabase.Designer.cs} (99%) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230424175633_InitDB.cs => 20230428121613_InitDatabase.cs} (99%) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.Designer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230428121613_InitDatabase.Designer.cs similarity index 99% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.Designer.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230428121613_InitDatabase.Designer.cs index a73aad1..6d5970e 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230428121613_InitDatabase.Designer.cs @@ -12,8 +12,8 @@ using SoftwareInstallationDataBaseImplement; namespace SoftwareInstallationDataBaseImplement.Migrations { [DbContext(typeof(SoftwareInstallationDataBase))] - [Migration("20230424175633_InitDB")] - partial class InitDB + [Migration("20230428121613_InitDatabase")] + partial class InitDatabase { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230428121613_InitDatabase.cs similarity index 99% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230428121613_InitDatabase.cs index 2ff4e95..5b7701f 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230424175633_InitDB.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230428121613_InitDatabase.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace SoftwareInstallationDataBaseImplement.Migrations { /// - public partial class InitDB : Migration + public partial class InitDatabase : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs index 1910dc2..22a15c3 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs @@ -9,7 +9,7 @@ namespace SoftwareInstallationDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=COMP-AVZH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseFulllab7;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VG5USAH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } -- 2.25.1 From 4194be73467e5d4424b563f21104a527b51c58ac Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Wed, 3 May 2023 20:50:36 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/MessageInfoBindingModel.cs | 2 + .../IMessageInfoLogic.cs | 4 + .../SearchModels/MessageInfoSearchModel.cs | 2 + .../StoragesContracts/IMessageInfoStorage.cs | 2 + .../ViewModels/MessageInfoViewModel.cs | 6 + .../FormMails.Designer.cs | 44 ++- .../SoftwareInstallation/FormMails.cs | 60 +++- .../FormReplyMail.Designer.cs | 145 ++++++++ .../SoftwareInstallation/FormReplyMail.cs | 86 +++++ .../SoftwareInstallation/FormReplyMail.resx | 60 ++++ .../SoftwareInstallation/Program.cs | 1 + .../BusinessLogic/MessageInfoLogic.cs | 26 ++ .../BusinessLogic/OrderLogic.cs | 25 +- .../APIClient.cs | 2 +- .../Controllers/HomeController.cs | 43 ++- .../Views/Home/Mails.cshtml | 121 ++++--- .../Implements/MessageInfoStorage.cs | 37 +- ...ftwareInstallationDataBaseModelSnapshot.cs | 337 ------------------ .../Models/Message.cs | 18 + .../Models/IMessageInfoModel.cs | 2 + .../DataFileSingleton.cs | 2 - .../Implements/MessageInfoStorage.cs | 25 +- .../Models/Message.cs | 22 ++ .../Implements/MessageInfoStorage.cs | 29 +- .../Models/Message.cs | 18 + .../Controllers/ClientController.cs | 20 ++ 26 files changed, 729 insertions(+), 410 deletions(-) create mode 100644 SoftwareInstallation/SoftwareInstallation/FormReplyMail.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormReplyMail.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormReplyMail.resx delete mode 100644 SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs index e4259c4..ad14e2e 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace SofrwareInstallationContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + public bool HasRead { get; set; } + public string? Reply { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs index f9155c7..26bfa29 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -9,5 +9,9 @@ namespace SofrwareInstallationContracts.BusinessLogicsContracts List? ReadList(MessageInfoSearchModel? model); bool Create(MessageInfoBindingModel model); + + bool Update(MessageInfoBindingModel model); + + MessageInfoViewModel? ReadElement(MessageInfoSearchModel model); } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs index e7d3396..ce9510a 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs @@ -4,5 +4,7 @@ { public int? ClientId { get; set; } public string? MessageId { get; set; } + public int? Page { get; set; } + public int? PageSize { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs b/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs index 9d9de85..e9eb4df 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs @@ -13,5 +13,7 @@ namespace SofrwareInstallationContracts.StoragesContracts MessageInfoViewModel? GetElement(MessageInfoSearchModel model); MessageInfoViewModel? Insert(MessageInfoBindingModel model); + + MessageInfoViewModel? Update(MessageInfoBindingModel model); } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs index 464ecc4..a8a4e5d 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -20,5 +20,11 @@ namespace SofrwareInstallationContracts.ViewModels [DisplayName("Содержание")] public string Body { get; set; } = string.Empty; + + [DisplayName("Прочитано")] + public bool HasRead { get; set; } + + [DisplayName("Ответ")] + public string? Reply { get; set; } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs index 30f2ded..fb6902b 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs @@ -29,34 +29,74 @@ private void InitializeComponent() { this.DataGridView = new System.Windows.Forms.DataGridView(); + this.PrevPageButton = new System.Windows.Forms.Button(); + this.NextPageButton = new System.Windows.Forms.Button(); + this.labelInfoPages = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.DataGridView.Location = new System.Drawing.Point(3, 3); + this.DataGridView.Location = new System.Drawing.Point(57, 3); this.DataGridView.Name = "DataGridView"; this.DataGridView.RowTemplate.Height = 25; - this.DataGridView.Size = new System.Drawing.Size(794, 445); + this.DataGridView.Size = new System.Drawing.Size(687, 411); this.DataGridView.TabIndex = 0; + this.DataGridView.RowHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_RowHeaderMouseClick); + // + // PrevPageButton + // + this.PrevPageButton.Location = new System.Drawing.Point(12, 158); + this.PrevPageButton.Name = "PrevPageButton"; + this.PrevPageButton.Size = new System.Drawing.Size(38, 69); + this.PrevPageButton.TabIndex = 1; + this.PrevPageButton.Text = "<="; + this.PrevPageButton.UseVisualStyleBackColor = true; + this.PrevPageButton.Click += new System.EventHandler(this.PrevPageButton_Click); + // + // NextPageButton + // + this.NextPageButton.Location = new System.Drawing.Point(750, 159); + this.NextPageButton.Name = "NextPageButton"; + this.NextPageButton.Size = new System.Drawing.Size(38, 68); + this.NextPageButton.TabIndex = 2; + this.NextPageButton.Text = "=>"; + this.NextPageButton.UseVisualStyleBackColor = true; + this.NextPageButton.Click += new System.EventHandler(this.NextPageButton_Click); + // + // labelInfoPages + // + this.labelInfoPages.AutoSize = true; + this.labelInfoPages.Location = new System.Drawing.Point(387, 426); + this.labelInfoPages.Name = "labelInfoPages"; + this.labelInfoPages.Size = new System.Drawing.Size(75, 15); + this.labelInfoPages.TabIndex = 3; + this.labelInfoPages.Text = "{0} страница"; // // FormMails // 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.labelInfoPages); + this.Controls.Add(this.NextPageButton); + this.Controls.Add(this.PrevPageButton); this.Controls.Add(this.DataGridView); this.Name = "FormMails"; this.Text = "Эл. письма"; this.Load += new System.EventHandler(this.FormMails_Load); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion private DataGridView DataGridView; + private Button PrevPageButton; + private Button NextPageButton; + private Label labelInfoPages; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.cs index ebfb22b..153d2ba 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMails.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.cs @@ -1,6 +1,7 @@ using SofrwareInstallationContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using System.Windows.Forms; +using SofrwareInstallationContracts.ViewModels; namespace SoftwareInstallationView { @@ -8,20 +9,27 @@ namespace SoftwareInstallationView { private readonly ILogger _logger; private readonly IMessageInfoLogic _logic; + private int currentPage = 1; + public int pageSize = 5; public FormMails(ILogger logger, IMessageInfoLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; + PrevPageButton.Enabled = false; LoadData(); } - private void LoadData() + private bool LoadData() { try { - var list = _logic.ReadList(null); + var list = _logic.ReadList(new() + { + Page = currentPage, + PageSize = pageSize, + }); if (list != null) { DataGridView.DataSource = list; @@ -30,12 +38,15 @@ namespace SoftwareInstallationView DataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка писем"); + labelInfoPages.Text = $"{currentPage} страница"; + return true; } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки писем"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; } } @@ -43,5 +54,50 @@ namespace SoftwareInstallationView { LoadData(); } + + private void PrevPageButton_Click(object sender, EventArgs e) + { + if (currentPage == 1) + { + _logger.LogWarning("Неккоректный номер страницы {page}", currentPage - 1); + return; + } + currentPage--; + if (LoadData()) + { + NextPageButton.Enabled = true; + if (currentPage == 1) + { + PrevPageButton.Enabled = false; + } + } + } + + private void NextPageButton_Click(object sender, EventArgs e) + { + currentPage++; + if (!LoadData() || ((List)DataGridView.DataSource).Count == 0) + { + _logger.LogWarning("Out of range messages"); + currentPage--; + LoadData(); + NextPageButton.Enabled = false; + } + else + { + PrevPageButton.Enabled = true; + } + } + + private void DataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReplyMail)); + if (service is FormReplyMail form) + { + form.MessageId = (string)DataGridView.Rows[e.RowIndex].Cells["MessageId"].Value; + form.ShowDialog(); + LoadData(); + } + } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormReplyMail.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormReplyMail.Designer.cs new file mode 100644 index 0000000..bcec740 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormReplyMail.Designer.cs @@ -0,0 +1,145 @@ +namespace SoftwareInstallationView +{ + partial class FormReplyMail + { + /// + /// 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.HeadTextBox = new System.Windows.Forms.TextBox(); + this.MailTextBox = new System.Windows.Forms.TextBox(); + this.ReplyTextBox = new System.Windows.Forms.TextBox(); + this.ReplyButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(4, 19); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(40, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Тема: "; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(4, 48); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(82, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Содержание: "; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(4, 178); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(44, 15); + this.label3.TabIndex = 2; + this.label3.Text = "Ответ: "; + // + // HeadTextBox + // + this.HeadTextBox.Location = new System.Drawing.Point(92, 16); + this.HeadTextBox.Name = "HeadTextBox"; + this.HeadTextBox.ReadOnly = true; + this.HeadTextBox.Size = new System.Drawing.Size(469, 23); + this.HeadTextBox.TabIndex = 5; + // + // MailTextBox + // + this.MailTextBox.Location = new System.Drawing.Point(92, 45); + this.MailTextBox.Multiline = true; + this.MailTextBox.Name = "MailTextBox"; + this.MailTextBox.ReadOnly = true; + this.MailTextBox.Size = new System.Drawing.Size(469, 93); + this.MailTextBox.TabIndex = 6; + // + // ReplyTextBox + // + this.ReplyTextBox.Location = new System.Drawing.Point(92, 175); + this.ReplyTextBox.Multiline = true; + this.ReplyTextBox.Name = "ReplyTextBox"; + this.ReplyTextBox.Size = new System.Drawing.Size(469, 125); + this.ReplyTextBox.TabIndex = 7; + // + // ReplyButton + // + this.ReplyButton.Location = new System.Drawing.Point(351, 306); + this.ReplyButton.Name = "ReplyButton"; + this.ReplyButton.Size = new System.Drawing.Size(102, 36); + this.ReplyButton.TabIndex = 6; + this.ReplyButton.Text = "Ответить"; + this.ReplyButton.UseVisualStyleBackColor = true; + this.ReplyButton.Click += new System.EventHandler(this.ReplyButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(459, 306); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(102, 36); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormReplyMail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(573, 354); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ReplyButton); + this.Controls.Add(this.ReplyTextBox); + this.Controls.Add(this.MailTextBox); + this.Controls.Add(this.HeadTextBox); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormReplyMail"; + this.Text = "Ответ"; + this.Load += new System.EventHandler(this.FormReplyMail_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private TextBox HeadTextBox; + private TextBox MailTextBox; + private TextBox ReplyTextBox; + private Button ReplyButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormReplyMail.cs b/SoftwareInstallation/SoftwareInstallation/FormReplyMail.cs new file mode 100644 index 0000000..efcecee --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormReplyMail.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.ViewModels; +using SoftwareInstallationBusinessLogic.MailWorker; +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 SoftwareInstallationView +{ + public partial class FormReplyMail : Form + { + private readonly ILogger _logger; + private readonly AbstractMailWorker _mailWorker; + private readonly IMessageInfoLogic _logic; + private MessageInfoViewModel _message; + + public string MessageId { get; set; } = string.Empty; + + public FormReplyMail(ILogger logger, AbstractMailWorker mailWorker, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _mailWorker = mailWorker; + _logic = logic; + } + + private void ReplyButton_Click(object sender, EventArgs e) + { + _mailWorker.MailSendAsync(new() + { + MailAddress = _message.SenderName, + Subject = _message.Subject, + Text = ReplyTextBox.Text, + }); + + _logic.Update(new() + { + MessageId = MessageId, + Reply = ReplyTextBox.Text, + HasRead = true, + }); + + MessageBox.Show("Успешно отправлено письмо", "Отправка письма", MessageBoxButtons.OK); + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormReplyMail_Load(object sender, EventArgs e) + { + try + { + _message = _logic.ReadElement(new() { MessageId = MessageId }); + + if (_message == null) + throw new ArgumentNullException("Письма с таким id не существует"); + + Text += $"для {_message.SenderName}"; + HeadTextBox.Text = _message.Subject; + MailTextBox.Text = _message.Body; + + if (_message.HasRead is false) + { + _logic.Update(new() { MessageId = MessageId, HasRead = true, Reply = _message.Reply }); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения собщения"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallation/FormReplyMail.resx b/SoftwareInstallation/SoftwareInstallation/FormReplyMail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormReplyMail.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/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index b2ff25e..d9de629 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -91,6 +91,7 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs index 5bfdd58..34519e0 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs @@ -46,5 +46,31 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic return list; } + + public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model) + { + var res = _messageStorage.GetElement(model); + + if (res == null) + { + _logger.LogWarning("Read element operation failed"); + + return null; + } + + return res; + } + + public bool Update(MessageInfoBindingModel model) + { + if (_messageStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } } } diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs index c26e360..a4ec9c1 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs @@ -18,8 +18,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic private readonly IStoreLogic _storeLogic; private readonly IPackageStorage _packageStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) - public OrderLogic(ILogger logger, IOrderStorage orderStorage, IPackageStorage packageStorage,IStoreLogic storeLogic) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IPackageStorage packageStorage,IStoreLogic storeLogic, AbstractMailWorker mailWorker, IClientLogic clientLogic) { _logger = logger; _orderStorage = orderStorage; @@ -100,6 +99,9 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic _logger.LogWarning("Update operation failed"); return false; } + + SendOrderMessage(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}"); + return true; } @@ -182,5 +184,24 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic return element; } + + private bool SendOrderMessage(int clientId, string subject, string text) + { + var client = _clientLogic.ReadElement(new() { Id = clientId }); + + if (client == null) + { + return false; + } + + _mailWorker.MailSendAsync(new() + { + MailAddress = client.Email, + Subject = subject, + Text = text + }); + + return true; + } } } diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs b/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs index bff558d..15f1eba 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs +++ b/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs @@ -8,7 +8,7 @@ namespace SoftwareInstallationClientApp public class APIClient { private static readonly HttpClient _client = new(); - + public static int CurrentPage { get; set; } = 0; public static ClientViewModel? Client { get; set; } = null; public static void Connect(IConfiguration configuration) diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs index 0dde025..499d1b7 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs @@ -3,6 +3,9 @@ using SoftwareInstallationClientApp.Models; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using System.Diagnostics; +using System.Text; +using SofrwareInstallationContracts.SearchModels; +using Microsoft.AspNetCore.Mvc.Rendering; namespace SoftwareInstallationClientApp.Controllers { @@ -151,7 +154,45 @@ namespace SoftwareInstallationClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + return View(); + } + + [HttpGet] + public Tuple? SwitchPage(bool isNext) + { + if (isNext) + { + APIClient.CurrentPage++; + } + else + { + if (APIClient.CurrentPage == 1) + { + return null; + } + APIClient.CurrentPage--; + } + + var res = APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client!.Id}&page={APIClient.CurrentPage}"); + + if (isNext && (res == null || res.Count == 0)) + { + APIClient.CurrentPage--; + return Tuple.Create(null, null, APIClient.CurrentPage != 1, false); + } + + StringBuilder htmlTable = new(); + foreach (var mail in res) + { + htmlTable.Append("" + + $"{mail.DateDelivery}" + + $"{mail.Subject}" + + $"{mail.Body}" + + "" + (mail.HasRead ? "Прочитано" : "Непрочитано") + "" + + $"{mail.Reply}" + + ""); + } + return Tuple.Create(htmlTable.ToString(), APIClient.CurrentPage.ToString(), APIClient.CurrentPage != 1, true); } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml index b151645..b0087cf 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml @@ -1,54 +1,79 @@ -@using SofrwareInstallationContracts.ViewModels - -@model List - -@{ - ViewData["Title"] = "Mails"; +@{ + ViewData["Title"] = "Mails"; } -
-

Письма

+

Письма

-
- @{ - if (Model == null) - { -

Авторизируйтесь

- return; - } - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - } - -
- Дата письма - - Тема - - Содержание -
- @Html.DisplayFor(modelItem => item.DateDelivery) - - @Html.DisplayFor(modelItem => item.Subject) - - @Html.DisplayFor(modelItem => item.Body) -
- } + + + + + + + + + + + + +
+ Дата письма + + Тема + + Содержание + + Статус + + Ответ +
+
+ + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs index 5805cd3..b52ff4e 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/MessageInfoStorage.cs @@ -18,13 +18,18 @@ namespace SoftwareInstallationDataBaseImplement.Implements public List GetFilteredList(MessageInfoSearchModel model) { - if (!model.ClientId.HasValue) - return new(); using var context = new SoftwareInstallationDataBase(); - return context.Messages - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); + + var res = context.Messages + .Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId) + .Select(x => x.GetViewModel); + + if (!(model.Page.HasValue && model.PageSize.HasValue)) + { + return res.ToList(); + } + + return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList(); } public List GetFullList() @@ -37,15 +42,31 @@ namespace SoftwareInstallationDataBaseImplement.Implements public MessageInfoViewModel? Insert(MessageInfoBindingModel model) { + using var context = new SoftwareInstallationDataBase(); var newMessage = Message.Create(model); - if (newMessage == null) + + if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) { return null; } - using var context = new SoftwareInstallationDataBase(); + context.Messages.Add(newMessage); context.SaveChanges(); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var res = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId)); + + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + + return res?.GetViewModel; + } } } diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs deleted file mode 100644 index ae1125d..0000000 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs +++ /dev/null @@ -1,337 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using SoftwareInstallationDataBaseImplement; - -#nullable disable - -namespace SoftwareInstallationDataBaseImplement.Migrations -{ - [DbContext(typeof(SoftwareInstallationDataBase))] - partial class SoftwareInstallationDataBaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Implementer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImplementerFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Qualification") - .HasColumnType("int"); - - b.Property("WorkExperience") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Implementers"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ImplementerId") - .HasColumnType("int"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("PackageName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("ImplementerId"); - - b.HasIndex("PackageId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Package", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PackageName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Packages"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.PackageComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("PackageId"); - - b.ToTable("PackageComponents"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Store", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("OpeningDate") - .HasColumnType("datetime2"); - - b.Property("PackageMaxCount") - .HasColumnType("int"); - - b.Property("StoreAdress") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StoreName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Stores"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.StorePackage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("StoreId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PackageId"); - - b.HasIndex("StoreId"); - - b.ToTable("StorePackages"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => - { - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") - .WithMany("Orders") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Implementer", "Implementer") - .WithMany("Orders") - .HasForeignKey("ImplementerId"); - - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") - .WithMany("Orders") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Client"); - - b.Navigation("Implementer"); - - b.Navigation("Package"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.PackageComponent", b => - { - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Component", "Component") - .WithMany("PackageComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") - .WithMany("Components") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Package"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.StorePackage", b => - { - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") - .WithMany("StorePackages") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SoftwareInstallationDataBaseImplement.Models.Store", "Store") - .WithMany("Packages") - .HasForeignKey("StoreId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Package"); - - b.Navigation("Store"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Component", b => - { - b.Navigation("PackageComponents"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Implementer", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Package", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - - b.Navigation("StorePackages"); - }); - - modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Store", b => - { - b.Navigation("Packages"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs index 2f1b063..b389c26 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs @@ -18,6 +18,10 @@ namespace SoftwareInstallationDataBaseImplement.Models public string Subject { get; private set; } = string.Empty; [Required] public string Body { get; private set; } = string.Empty; + [Required] + public bool HasRead { get; private set; } + [Required] + public string? Reply { get; private set; } public virtual Client Client { get; set; } @@ -30,6 +34,8 @@ namespace SoftwareInstallationDataBaseImplement.Models return new() { Body = model.Body, + Reply = model.Reply, + HasRead = model.HasRead, Subject = model.Subject, ClientId = model.ClientId, MessageId = model.MessageId, @@ -38,9 +44,21 @@ namespace SoftwareInstallationDataBaseImplement.Models }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + Reply = model.Reply; + HasRead = model.HasRead; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, + Reply = Reply, + HasRead = HasRead, Subject = Subject, ClientId = ClientId, MessageId = MessageId, diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs index a27b3f7..27dcdbb 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs @@ -8,5 +8,7 @@ DateTime DateDelivery { get; } string Subject { get; } string Body { get; } + public bool HasRead { get; } + public string? Reply { get; } } } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs index 1331af0..7163b91 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs @@ -38,8 +38,6 @@ namespace SoftwareInstallationFileImplement public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x => x.GetXElement); - public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); - public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement); public void SaveStores() => SaveData(Stores, StoreFileName, "Stores", x => x.GetXElement); private DataFileSingleton() diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs index 7d4eac0..5e3fda2 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs @@ -22,12 +22,14 @@ namespace SoftwareInstallationFileImplement.Implements public List GetFilteredList(MessageInfoSearchModel model) { - if (!model.ClientId.HasValue) - return new(); - return source.Messages - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); + var res = source.Messages + .Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId) + .Select(x => x.GetViewModel); + if (!(model.Page.HasValue && model.PageSize.HasValue)) + { + return res.ToList(); + } + return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList(); } public List GetFullList() @@ -48,5 +50,16 @@ namespace SoftwareInstallationFileImplement.Implements source.SaveMessages(); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + var res = source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId)); + if (res != null) + { + res.Update(model); + source.SaveMessages(); + } + return res?.GetViewModel; + } } } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs index cb19a04..7431ba0 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs @@ -19,6 +19,10 @@ namespace SoftwareInstallationFileImplement.Models public string Body { get; private set; } = string.Empty; + public bool HasRead { get; private set; } + + public string? Reply { get; private set; } + public static Message? Create(MessageInfoBindingModel model) { if (model == null) @@ -27,6 +31,8 @@ namespace SoftwareInstallationFileImplement.Models } return new() { + Reply = model.Reply, + HasRead = model.HasRead, Body = model.Body, Subject = model.Subject, DateDelivery = model.DateDelivery, @@ -44,6 +50,8 @@ namespace SoftwareInstallationFileImplement.Models } return new() { + Reply = element.Attribute("Reply")!.Value, + HasRead = Convert.ToBoolean(element.Attribute("HasRead")!.Value), Body = element.Attribute("Body")!.Value, Subject = element.Attribute("Subject")!.Value, DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), @@ -53,10 +61,22 @@ namespace SoftwareInstallationFileImplement.Models }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + Reply = model.Reply; + HasRead = model.HasRead; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, Subject = Subject, + Reply = Reply, + HasRead = HasRead, DateDelivery = DateDelivery, SenderName = SenderName, ClientId = ClientId, @@ -66,6 +86,8 @@ namespace SoftwareInstallationFileImplement.Models public XElement GetXElement => new("MessageInfo", new XAttribute("Subject", Subject), new XAttribute("Body", Body), + new XAttribute("Reply", Reply), + new XAttribute("HasRead", HasRead), new XAttribute("ClientId", ClientId), new XAttribute("MessageId", MessageId), new XAttribute("SenderName", SenderName), diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs index 2fbee70..8e05295 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs @@ -41,7 +41,21 @@ namespace SoftwareInstallationListImplement.Implements result.Add(item.GetViewModel); } } - return result; + + if (!(model.Page.HasValue && model.PageSize.HasValue)) + { + return result; + } + if (model.Page * model.PageSize >= result.Count) + { + return null; + } + List filteredResult = new(); + for (var i = (model.Page.Value - 1) * model.PageSize.Value; i < model.Page.Value * model.PageSize.Value; i++) + { + filteredResult.Add(result[i]); + } + return filteredResult; } public List GetFullList() @@ -64,5 +78,18 @@ namespace SoftwareInstallationListImplement.Implements _source.Messages.Add(newMessage); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + foreach (var message in _source.Messages) + { + if (message.MessageId.Equals(model.MessageId)) + { + message.Update(model); + return message.GetViewModel; + } + } + return null; + } } } diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs index 47cfc9e..a0d1068 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs @@ -23,6 +23,10 @@ namespace SoftwareInstallationListImplement.Models public string Body { get; private set; } = string.Empty; + public bool HasRead { get; private set; } + + public string? Reply { get; private set; } + public static Message? Create(MessageInfoBindingModel model) { if (model == null) @@ -31,6 +35,8 @@ namespace SoftwareInstallationListImplement.Models } return new() { + Reply = model.Reply, + HasRead = model.HasRead, Body = model.Body, Subject = model.Subject, DateDelivery = model.DateDelivery, @@ -40,9 +46,21 @@ namespace SoftwareInstallationListImplement.Models }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + Reply = model.Reply; + HasRead = model.HasRead; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, + Reply = Reply, + HasRead = HasRead, Subject = Subject, DateDelivery = DateDelivery, SenderName = SenderName, diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs index a777479..b2a3209 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs @@ -14,6 +14,7 @@ namespace SoftwareInstallationRestApi.Controllers private readonly ILogger _logger; private readonly IClientLogic _logic; private readonly IMessageInfoLogic _mailLogic; + public int pageSize = 3; public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { @@ -22,6 +23,25 @@ namespace SoftwareInstallationRestApi.Controllers _mailLogic = mailLogic; } + [HttpGet] + public List? GetMessages(int clientId, int page) + { + try + { + return _mailLogic.ReadList(new() + { + ClientId = clientId, + Page = page, + PageSize = pageSize + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } + [HttpGet] public ClientViewModel? Login(string login, string password) { -- 2.25.1 From aef74ec2c01521e440e12fb143ee7c764a235e2e Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Wed, 3 May 2023 22:07:11 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../APIClient.cs | 2 +- .../Views/Shared/_Layout.cshtml | 1 + .../20230503172509_InitDb.Designer.cs | 390 ++++++++++++++++++ .../Migrations/20230503172509_InitDb.cs | 277 +++++++++++++ ...ftwareInstallationDataBaseModelSnapshot.cs | 387 +++++++++++++++++ .../Models/Message.cs | 2 +- .../Controllers/ClientController.cs | 17 - 7 files changed, 1057 insertions(+), 19 deletions(-) create mode 100644 SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs b/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs index 15f1eba..97132c6 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs +++ b/SoftwareInstallation/SoftwareInstallationClientApp/APIClient.cs @@ -8,7 +8,7 @@ namespace SoftwareInstallationClientApp public class APIClient { private static readonly HttpClient _client = new(); - public static int CurrentPage { get; set; } = 0; + public static int CurrentPage { get; set; } = 1; public static ClientViewModel? Client { get; set; } = null; public static void Connect(IConfiguration configuration) diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml index d4a1ebf..c518ca5 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml @@ -7,6 +7,7 @@ +
diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs new file mode 100644 index 0000000..7c37da7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs @@ -0,0 +1,390 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SoftwareInstallationDataBaseImplement; + +#nullable disable + +namespace SoftwareInstallationDataBaseImplement.Migrations +{ + [DbContext(typeof(SoftwareInstallationDataBase))] + [Migration("20230503172509_InitDb")] + partial class InitDb + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("HasRead") + .HasColumnType("bit"); + + b.Property("Reply") + .HasColumnType("nvarchar(max)"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.PackageComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PackageId"); + + b.ToTable("PackageComponents"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Store", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("PackageMaxCount") + .HasColumnType("int"); + + b.Property("StoreAdress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StoreName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.StorePackage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("StoreId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("StoreId"); + + b.ToTable("StorePackages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.PackageComponent", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Component", "Component") + .WithMany("PackageComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") + .WithMany("Components") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.StorePackage", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") + .WithMany("StorePackages") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Store", "Store") + .WithMany("Packages") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Store"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Component", b => + { + b.Navigation("PackageComponents"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Package", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("StorePackages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Store", b => + { + b.Navigation("Packages"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.cs new file mode 100644 index 0000000..f4e3357 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.cs @@ -0,0 +1,277 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SoftwareInstallationDataBaseImplement.Migrations +{ + /// + public partial class InitDb : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Packages", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Packages", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Stores", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + StoreName = table.Column(type: "nvarchar(max)", nullable: false), + StoreAdress = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + PackageMaxCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Stores", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false), + HasRead = table.Column(type: "bit", nullable: false), + Reply = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), + ClientId = table.Column(type: "int", nullable: false), + PackageName = table.Column(type: "nvarchar(max)", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Orders_Packages_PackageId", + column: x => x.PackageId, + principalTable: "Packages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PackageComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PackageComponents", x => x.Id); + table.ForeignKey( + name: "FK_PackageComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PackageComponents_Packages_PackageId", + column: x => x.PackageId, + principalTable: "Packages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "StorePackages", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PackageId = table.Column(type: "int", nullable: false), + StoreId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StorePackages", x => x.Id); + table.ForeignKey( + name: "FK_StorePackages_Packages_PackageId", + column: x => x.PackageId, + principalTable: "Packages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_StorePackages_Stores_StoreId", + column: x => x.StoreId, + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_PackageId", + table: "Orders", + column: "PackageId"); + + migrationBuilder.CreateIndex( + name: "IX_PackageComponents_ComponentId", + table: "PackageComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_PackageComponents_PackageId", + table: "PackageComponents", + column: "PackageId"); + + migrationBuilder.CreateIndex( + name: "IX_StorePackages_PackageId", + table: "StorePackages", + column: "PackageId"); + + migrationBuilder.CreateIndex( + name: "IX_StorePackages_StoreId", + table: "StorePackages", + column: "StoreId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Messages"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "PackageComponents"); + + migrationBuilder.DropTable( + name: "StorePackages"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Packages"); + + migrationBuilder.DropTable( + name: "Stores"); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs new file mode 100644 index 0000000..d57f607 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs @@ -0,0 +1,387 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SoftwareInstallationDataBaseImplement; + +#nullable disable + +namespace SoftwareInstallationDataBaseImplement.Migrations +{ + [DbContext(typeof(SoftwareInstallationDataBase))] + partial class SoftwareInstallationDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("HasRead") + .HasColumnType("bit"); + + b.Property("Reply") + .HasColumnType("nvarchar(max)"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.PackageComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PackageId"); + + b.ToTable("PackageComponents"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Store", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("PackageMaxCount") + .HasColumnType("int"); + + b.Property("StoreAdress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StoreName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.StorePackage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("StoreId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("StoreId"); + + b.ToTable("StorePackages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Message", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Order", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.PackageComponent", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Component", "Component") + .WithMany("PackageComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") + .WithMany("Components") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.StorePackage", b => + { + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Package", "Package") + .WithMany("StorePackages") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDataBaseImplement.Models.Store", "Store") + .WithMany("Packages") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Store"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Component", b => + { + b.Navigation("PackageComponents"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Package", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("StorePackages"); + }); + + modelBuilder.Entity("SoftwareInstallationDataBaseImplement.Models.Store", b => + { + b.Navigation("Packages"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs index b389c26..831383e 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs @@ -20,7 +20,7 @@ namespace SoftwareInstallationDataBaseImplement.Models public string Body { get; private set; } = string.Empty; [Required] public bool HasRead { get; private set; } - [Required] + public string? Reply { get; private set; } public virtual Client Client { get; set; } diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs index b2a3209..8185ccb 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs @@ -87,22 +87,5 @@ namespace SoftwareInstallationRestApi.Controllers throw; } } - - [HttpGet] - public List? GetMessages(int clientId) - { - try - { - return _mailLogic.ReadList(new MessageInfoSearchModel - { - ClientId = clientId - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения писем клиента"); - throw; - } - } } } -- 2.25.1 From e069b185ddcf72cee17da3969642b5611adf91c1 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Thu, 4 May 2023 21:32:51 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=D0=BE?= =?UTF-8?q?=D1=81=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...509_InitDb.Designer.cs => 20230504171714_InitDb.Designer.cs} | 2 +- .../{20230503172509_InitDb.cs => 20230504171714_InitDb.cs} | 0 .../SoftwareInstallationDataBase.cs | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230503172509_InitDb.Designer.cs => 20230504171714_InitDb.Designer.cs} (99%) rename SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/{20230503172509_InitDb.cs => 20230504171714_InitDb.cs} (100%) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230504171714_InitDb.Designer.cs similarity index 99% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230504171714_InitDb.Designer.cs index 7c37da7..11df286 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230504171714_InitDb.Designer.cs @@ -12,7 +12,7 @@ using SoftwareInstallationDataBaseImplement; namespace SoftwareInstallationDataBaseImplement.Migrations { [DbContext(typeof(SoftwareInstallationDataBase))] - [Migration("20230503172509_InitDb")] + [Migration("20230504171714_InitDb")] partial class InitDb { /// diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230504171714_InitDb.cs similarity index 100% rename from SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230503172509_InitDb.cs rename to SoftwareInstallation/SoftwareInstallationDataBaseImplement/Migrations/20230504171714_InitDb.cs diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs index d98419e..68b25d2 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs @@ -9,7 +9,7 @@ namespace SoftwareInstallationDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VG5USAH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseHardFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=COMP-AVZH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseHardFulllab7;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } -- 2.25.1 From f5784833a3f798db003fb7016824b3f800711046 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Fri, 5 May 2023 11:38:19 +0400 Subject: [PATCH 7/8] lab 7 hard complete --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ca1c7a3..52737dc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# dll файлы +*.dll + # Mono auto generated files mono_crash.* -- 2.25.1 From 016e8d3099de667ac0f836f47dd1927aae9027a8 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Fri, 5 May 2023 11:39:12 +0400 Subject: [PATCH 8/8] lab 7 hard complete --- .../SoftwareInstallationDataBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs index 68b25d2..f60996f 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBase.cs @@ -9,7 +9,7 @@ namespace SoftwareInstallationDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=COMP-AVZH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseHardFulllab7;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=COMP-AVZH\SQLEXPRESS;Initial Catalog=SoftwareInstallationDataBaseHardFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } -- 2.25.1