diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/App.config b/BlacksmithWorkshop/BlacksmithWorkshop/App.config
index 44a79a8..07336cc 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/App.config
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/App.config
@@ -5,7 +5,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs
new file mode 100644
index 0000000..f45cd0a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs
@@ -0,0 +1,90 @@
+namespace BlacksmithWorkshopView
+{
+ 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();
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.refToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.menuStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(0, 27);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(802, 426);
+ this.dataGridView.TabIndex = 0;
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.refToolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(800, 24);
+ this.menuStrip1.TabIndex = 1;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // refToolStripMenuItem
+ //
+ this.refToolStripMenuItem.Name = "refToolStripMenuItem";
+ this.refToolStripMenuItem.Size = new System.Drawing.Size(73, 20);
+ this.refToolStripMenuItem.Text = "Обновить";
+ this.refToolStripMenuItem.Click += new System.EventHandler(this.RefToolStripMenuItem_Click);
+ //
+ // 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.Controls.Add(this.menuStrip1);
+ this.MainMenuStrip = this.menuStrip1;
+ this.Name = "FormMails";
+ this.Text = "Письма";
+ this.Load += new System.EventHandler(this.FormMails_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem refToolStripMenuItem;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
new file mode 100644
index 0000000..13936eb
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
@@ -0,0 +1,41 @@
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopView
+{
+ public partial class FormMails : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IMessageInfoLogic _messageLogic;
+ public FormMails(ILogger logger, IMessageInfoLogic messageLogic)
+ {
+ _logger = logger;
+ _messageLogic = messageLogic;
+ InitializeComponent();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ _logger.LogInformation("Загрузка списка писем");
+ dataGridView.DataSource = _messageLogic.ReadList(null);
+ dataGridView.Columns["MessageId"].Visible = false;
+ dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning("Ошибка загрузки писем");
+ MessageBox.Show($"Не удалось загрузить письма: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void FormMails_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void RefToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.resx
new file mode 100644
index 0000000..938108a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
index 892e72d..cd4bbac 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
@@ -43,6 +43,7 @@
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
+ this.mailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@@ -52,7 +53,8 @@
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.refbooksToolStripMenuItem,
this.reportsToolStripMenuItem,
- this.doWorkToolStripMenuItem});
+ this.doWorkToolStripMenuItem,
+ this.mailsToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1795, 24);
@@ -179,6 +181,13 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
+ // mailsToolStripMenuItem
+ //
+ this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem";
+ this.mailsToolStripMenuItem.Size = new System.Drawing.Size(62, 20);
+ this.mailsToolStripMenuItem.Text = "Письма";
+ this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -218,5 +227,6 @@
private ToolStripMenuItem clientsToolStripMenuItem;
private ToolStripMenuItem implementersToolStripMenuItem;
private ToolStripMenuItem doWorkToolStripMenuItem;
+ private ToolStripMenuItem mailsToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
index 6d248c0..0e83f74 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
@@ -13,7 +13,7 @@ namespace BlacksmithWorkshopView
private readonly IReportLogic _reportLogic;
private readonly IImplementerLogic _implementerLogic;
private readonly IWorkProcess _workProcess;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic)
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic, IMessageInfoLogic messageInfoLogic)
{
InitializeComponent();
_logger = logger;
@@ -204,5 +204,15 @@ namespace BlacksmithWorkshopView
{
_workProcess.DoWork(_implementerLogic, _orderLogic);
}
+
+ private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormMails));
+ if (service is FormMails form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
index b4551c3..1273bd2 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
@@ -35,7 +35,7 @@ namespace BlacksmithWorkshopView
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["SmtpClient Port"]),
+ SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
});
@@ -86,6 +86,7 @@ namespace BlacksmithWorkshopView
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck();
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs
index f40ffba..d81283b 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs
@@ -6,6 +6,7 @@ using BlacksmithWorkshopContracts.ViewModels;
using DocumentFormat.OpenXml.InkML;
using Microsoft.Extensions.Logging;
using System.Net;
+using System.Text.RegularExpressions;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
@@ -104,6 +105,14 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
throw new InvalidOperationException("Клиент с таким адресом электронной почты уже есть");
}
+ if (!Regex.IsMatch(model.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
+ {
+ throw new ArgumentException("Некорретно введенный email", nameof(model.Email));
+ }
+ if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$"))
+ {
+ throw new ArgumentException("Некорректно введенный пароль. Пароль должен содержать хотя бы одну букву, цифру и не буквенный символ", nameof(model.Password));
+ }
}
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
index ed30882..25722bf 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -68,6 +68,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
}
if (_orderStorage.Update(model) != null)
{
+ SendMail(vm?.ClientId ?? 0, $"Информация о заказе №{model.Id}", $"Заказ №{model.Id} {model.Status}");
return true;
}
}
@@ -82,7 +83,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) != null)
{
- SendMail(model.ClientId, $"Новый заказ создан. Номер заказа #{model.Id}", $"Заказ #{model.Id} от {model.DateCreate} на сумму {model.Sum} принят");
+ SendMail(model.ClientId, $"Новый заказ создан. Номер заказа: {model.Id}", $"Заказ №{model.Id} от {model.DateCreate} на сумму {model.Sum} принят");
return true;
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/MessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/MessageInfoStorage.cs
index 6cb3d65..8c98b89 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/MessageInfoStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/MessageInfoStorage.cs
@@ -44,6 +44,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
return null;
}
context.MessageInfos.Add(newMessage);
+ if (newMessage == null || context.MessageInfos.Any(x => x.MessageId.Equals(model.MessageId)))
+ {
+ return null;
+ }
context.SaveChanges();
return newMessage.GetViewModel;
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs
index c1b71ad..ab4d92c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs
@@ -41,17 +41,23 @@ builder.Services.AddSwaggerGen(c =>
var app = builder.Build();
-var MailLogin = builder.Configuration.GetSection("MailLogin").Value;
-
var mailSender = app.Services.GetService();
+
+var MailLogin = builder.Configuration.GetSection("MailLogin").Value ?? string.Empty;
+var MailPassword = builder.Configuration.GetSection("MailPassword").Value ?? string.Empty;
+var SmtpClientHost = builder.Configuration.GetSection("SmtpClientHost").Value ?? string.Empty;
+var SmtpClientPort = Convert.ToInt32(builder.Configuration.GetSection("SmtpClientPort").Value);
+var PopHost = builder.Configuration.GetSection("PopHost").Value ?? string.Empty;
+var PopPort = Convert.ToInt32(builder.Configuration.GetSection("PopPort").Value);
+
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["SmtpClient Port"]),
- PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
- PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
+ MailLogin = builder.Configuration.GetSection("MailLogin").Value ?? string.Empty,
+ MailPassword = builder.Configuration.GetSection("MailPassword").Value ?? string.Empty,
+ SmtpClientHost = builder.Configuration.GetSection("SmtpClientHost").Value ?? string.Empty,
+ SmtpClientPort = Convert.ToInt32(builder.Configuration.GetSection("SmtpClientPort").Value),
+ PopHost = builder.Configuration.GetSection("PopHost").Value ?? string.Empty,
+ PopPort = Convert.ToInt32(builder.Configuration.GetSection("PopPort").Value)
});
// Configure the HTTP request pipeline.
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json
index 0bc242f..786a1d6 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json
+++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json
@@ -10,6 +10,6 @@
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
- "MailLogin": "ulsturpplab7@gmail.com",
- "MailPassword": "ihnm riqo ysxz bxqb"
+ "MailLogin": "igors20111@gmail.com",
+ "MailPassword": "xzjt gzal aoek rjmp"
}