Сделано
This commit is contained in:
parent
688da5bdc0
commit
f11e568b69
182
CarRepairShop/CarRepairShop/FormLetter.Designer.cs
generated
Normal file
182
CarRepairShop/CarRepairShop/FormLetter.Designer.cs
generated
Normal file
@ -0,0 +1,182 @@
|
||||
namespace CarRepairShop
|
||||
{
|
||||
partial class FormLetter
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.textBoxEmail = new System.Windows.Forms.TextBox();
|
||||
this.labelAdress = new System.Windows.Forms.Label();
|
||||
this.labelSubject = new System.Windows.Forms.Label();
|
||||
this.textBoxSubject = new System.Windows.Forms.TextBox();
|
||||
this.labelBody = new System.Windows.Forms.Label();
|
||||
this.textBoxBody = new System.Windows.Forms.TextBox();
|
||||
this.buttonClose = new System.Windows.Forms.Button();
|
||||
this.buttonReply = new System.Windows.Forms.Button();
|
||||
this.labelDate = new System.Windows.Forms.Label();
|
||||
this.textBoxDate = new System.Windows.Forms.TextBox();
|
||||
this.buttonSend = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBoxEmail
|
||||
//
|
||||
this.textBoxEmail.Location = new System.Drawing.Point(72, 6);
|
||||
this.textBoxEmail.Name = "textBoxEmail";
|
||||
this.textBoxEmail.ReadOnly = true;
|
||||
this.textBoxEmail.Size = new System.Drawing.Size(186, 27);
|
||||
this.textBoxEmail.TabIndex = 0;
|
||||
//
|
||||
// labelAdress
|
||||
//
|
||||
this.labelAdress.AutoSize = true;
|
||||
this.labelAdress.Location = new System.Drawing.Point(12, 9);
|
||||
this.labelAdress.Name = "labelAdress";
|
||||
this.labelAdress.Size = new System.Drawing.Size(54, 20);
|
||||
this.labelAdress.TabIndex = 1;
|
||||
this.labelAdress.Text = "Адрес:";
|
||||
//
|
||||
// labelSubject
|
||||
//
|
||||
this.labelSubject.AutoSize = true;
|
||||
this.labelSubject.Location = new System.Drawing.Point(12, 55);
|
||||
this.labelSubject.Name = "labelSubject";
|
||||
this.labelSubject.Size = new System.Drawing.Size(47, 20);
|
||||
this.labelSubject.TabIndex = 2;
|
||||
this.labelSubject.Text = "Тема:";
|
||||
//
|
||||
// textBoxSubject
|
||||
//
|
||||
this.textBoxSubject.Location = new System.Drawing.Point(72, 52);
|
||||
this.textBoxSubject.Name = "textBoxSubject";
|
||||
this.textBoxSubject.ReadOnly = true;
|
||||
this.textBoxSubject.Size = new System.Drawing.Size(552, 27);
|
||||
this.textBoxSubject.TabIndex = 3;
|
||||
//
|
||||
// labelBody
|
||||
//
|
||||
this.labelBody.AutoSize = true;
|
||||
this.labelBody.Location = new System.Drawing.Point(12, 96);
|
||||
this.labelBody.Name = "labelBody";
|
||||
this.labelBody.Size = new System.Drawing.Size(104, 20);
|
||||
this.labelBody.TabIndex = 4;
|
||||
this.labelBody.Text = "Текст письма:";
|
||||
//
|
||||
// textBoxBody
|
||||
//
|
||||
this.textBoxBody.Location = new System.Drawing.Point(12, 119);
|
||||
this.textBoxBody.Multiline = true;
|
||||
this.textBoxBody.Name = "textBoxBody";
|
||||
this.textBoxBody.ReadOnly = true;
|
||||
this.textBoxBody.Size = new System.Drawing.Size(612, 186);
|
||||
this.textBoxBody.TabIndex = 5;
|
||||
//
|
||||
// buttonClose
|
||||
//
|
||||
this.buttonClose.Location = new System.Drawing.Point(491, 326);
|
||||
this.buttonClose.Name = "buttonClose";
|
||||
this.buttonClose.Size = new System.Drawing.Size(111, 39);
|
||||
this.buttonClose.TabIndex = 6;
|
||||
this.buttonClose.Text = "Закрыть";
|
||||
this.buttonClose.UseVisualStyleBackColor = true;
|
||||
this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click);
|
||||
//
|
||||
// buttonReply
|
||||
//
|
||||
this.buttonReply.Location = new System.Drawing.Point(290, 326);
|
||||
this.buttonReply.Name = "buttonReply";
|
||||
this.buttonReply.Size = new System.Drawing.Size(177, 39);
|
||||
this.buttonReply.TabIndex = 7;
|
||||
this.buttonReply.Text = "Ответить";
|
||||
this.buttonReply.UseVisualStyleBackColor = true;
|
||||
this.buttonReply.Click += new System.EventHandler(this.buttonReply_Click);
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
this.labelDate.AutoSize = true;
|
||||
this.labelDate.Location = new System.Drawing.Point(278, 9);
|
||||
this.labelDate.Name = "labelDate";
|
||||
this.labelDate.Size = new System.Drawing.Size(127, 20);
|
||||
this.labelDate.TabIndex = 8;
|
||||
this.labelDate.Text = "Дата получения: ";
|
||||
//
|
||||
// textBoxDate
|
||||
//
|
||||
this.textBoxDate.Location = new System.Drawing.Point(411, 6);
|
||||
this.textBoxDate.Name = "textBoxDate";
|
||||
this.textBoxDate.ReadOnly = true;
|
||||
this.textBoxDate.Size = new System.Drawing.Size(213, 27);
|
||||
this.textBoxDate.TabIndex = 9;
|
||||
//
|
||||
// buttonSend
|
||||
//
|
||||
this.buttonSend.Location = new System.Drawing.Point(149, 326);
|
||||
this.buttonSend.Name = "buttonSend";
|
||||
this.buttonSend.Size = new System.Drawing.Size(109, 39);
|
||||
this.buttonSend.TabIndex = 10;
|
||||
this.buttonSend.Text = "Отправить";
|
||||
this.buttonSend.UseVisualStyleBackColor = true;
|
||||
this.buttonSend.Visible = false;
|
||||
this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);
|
||||
//
|
||||
// FormLetter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(636, 377);
|
||||
this.Controls.Add(this.buttonSend);
|
||||
this.Controls.Add(this.textBoxDate);
|
||||
this.Controls.Add(this.labelDate);
|
||||
this.Controls.Add(this.buttonReply);
|
||||
this.Controls.Add(this.buttonClose);
|
||||
this.Controls.Add(this.textBoxBody);
|
||||
this.Controls.Add(this.labelBody);
|
||||
this.Controls.Add(this.textBoxSubject);
|
||||
this.Controls.Add(this.labelSubject);
|
||||
this.Controls.Add(this.labelAdress);
|
||||
this.Controls.Add(this.textBoxEmail);
|
||||
this.Name = "FormLetter";
|
||||
this.Text = "Письмо";
|
||||
this.Load += new System.EventHandler(this.FormLetter_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxEmail;
|
||||
private Label labelAdress;
|
||||
private Label labelSubject;
|
||||
private TextBox textBoxSubject;
|
||||
private Label labelBody;
|
||||
private TextBox textBoxBody;
|
||||
private Button buttonClose;
|
||||
private Button buttonReply;
|
||||
private Label labelDate;
|
||||
private TextBox textBoxDate;
|
||||
private Button buttonSend;
|
||||
}
|
||||
}
|
151
CarRepairShop/CarRepairShop/FormLetter.cs
Normal file
151
CarRepairShop/CarRepairShop/FormLetter.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using CarRepairShopBusinessLogic.MailWorker;
|
||||
using CarRepairShopContracts.BindingModels;
|
||||
using CarRepairShopContracts.BusinessLogicsContracts;
|
||||
using CarRepairShopContracts.SearchModels;
|
||||
using CarRepairShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace CarRepairShop
|
||||
{
|
||||
public partial class FormLetter : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoLogic _logic;
|
||||
private readonly AbstractMailWorker _worker;
|
||||
|
||||
public MessageInfoViewModel? model;
|
||||
public string? messageId;
|
||||
|
||||
public FormLetter(ILogger<FormLetter> logger, IMessageInfoLogic logic, AbstractMailWorker worker)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_worker = worker;
|
||||
}
|
||||
|
||||
private void FormLetter_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(messageId))
|
||||
{
|
||||
ReloadLetter();
|
||||
return;
|
||||
}
|
||||
else if (model != null)
|
||||
{
|
||||
ConfigurateToCreateAnsver();
|
||||
return;
|
||||
}
|
||||
_logger.LogError("Для формы не переданно сведений о письме, на которое отвечаем!");
|
||||
DialogResult = DialogResult.Abort;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
private void ReloadLetter()
|
||||
{
|
||||
_logger.LogInformation("Загрузка существующего письма с id:{}", messageId);
|
||||
model = _logic.ReadElement(new MessageInfoSearchModel
|
||||
{
|
||||
MessageId = messageId
|
||||
});
|
||||
if (model != null)
|
||||
{
|
||||
_logger.LogInformation("Письмо найдено");
|
||||
textBoxEmail.Text = model.SenderName;
|
||||
textBoxDate.Text = model.DateDelivery.ToString();
|
||||
textBoxSubject.Text = model.Subject;
|
||||
textBoxBody.Text = model.Body;
|
||||
|
||||
|
||||
if (model.IsReply)
|
||||
{
|
||||
_logger.LogInformation("Письмо само и есть ответ");
|
||||
buttonReply.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.ReplyMessageId))
|
||||
{
|
||||
_logger.LogInformation("У письма есть ответ.");
|
||||
buttonReply.Text = "Прочитать ответ";
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
_logger.LogWarning("Письмо с таким id не удалось найти");
|
||||
DialogResult = DialogResult.Abort;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
private void ConfigurateToCreateAnsver()
|
||||
{
|
||||
textBoxEmail.Text = model.SenderName;
|
||||
labelDate.Visible = false;
|
||||
textBoxDate.Visible = false;
|
||||
textBoxSubject.Text = $"re: {model.Subject}";
|
||||
textBoxBody.ReadOnly = false;
|
||||
buttonReply.Visible = false;
|
||||
buttonSend.Visible = true;
|
||||
_logger.LogInformation("Запущена форма создания нового письма - ответа");
|
||||
}
|
||||
|
||||
private void buttonClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void buttonReply_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormLetter));
|
||||
if (service is FormLetter form)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.ReplyMessageId))
|
||||
{
|
||||
form.messageId = model.ReplyMessageId;
|
||||
}
|
||||
else
|
||||
{
|
||||
form.model = model;
|
||||
}
|
||||
|
||||
if (form.ShowDialog() != DialogResult.Cancel)
|
||||
{
|
||||
buttonReply.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSend_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string subject = textBoxSubject.Text;
|
||||
string text = textBoxBody.Text;
|
||||
|
||||
Task.Run(() => _worker.MailSendReplyAsync(new MailReplySendInfoBindingModel
|
||||
{
|
||||
MailAddress = model.SenderName,
|
||||
Subject = subject,
|
||||
Text = text,
|
||||
ParentMessageId = model.MessageId,
|
||||
}));
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
CarRepairShop/CarRepairShop/FormLetter.resx
Normal file
120
CarRepairShop/CarRepairShop/FormLetter.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
129
CarRepairShop/CarRepairShop/FormMails.Designer.cs
generated
129
CarRepairShop/CarRepairShop/FormMails.Designer.cs
generated
@ -27,36 +27,107 @@
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(12, 12);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(776, 426);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// FormMails
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormMails";
|
||||
Text = "Письма";
|
||||
Load += ViewMailForm_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
{
|
||||
this.panel = new Panel();
|
||||
this.dataGridView = new DataGridView();
|
||||
this.buttonOpen = new Button();
|
||||
this.numericUpDownPage = new NumericUpDown();
|
||||
this.buttonPrevious = new Button();
|
||||
this.buttonNext = new Button();
|
||||
this.panel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPage)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel.Controls.Add(this.dataGridView);
|
||||
this.panel.Location = new Point(3, 1);
|
||||
this.panel.Margin = new Padding(3, 4, 3, 4);
|
||||
this.panel.Name = "panel1";
|
||||
this.panel.Size = new Size(795, 431);
|
||||
this.panel.TabIndex = 0;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.AllowUserToAddRows = false;
|
||||
this.dataGridView.AllowUserToDeleteRows = false;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = DockStyle.Fill;
|
||||
this.dataGridView.Location = new Point(0, 0);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.ReadOnly = true;
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new Size(795, 431);
|
||||
this.dataGridView.TabIndex = 2;
|
||||
//
|
||||
// buttonOpen
|
||||
//
|
||||
this.buttonOpen.Location = new Point(806, 80);
|
||||
this.buttonOpen.Margin = new Padding(3, 4, 3, 4);
|
||||
this.buttonOpen.Name = "buttonOpen";
|
||||
this.buttonOpen.Size = new Size(107, 31);
|
||||
this.buttonOpen.TabIndex = 1;
|
||||
this.buttonOpen.Text = "Прочитать";
|
||||
this.buttonOpen.UseVisualStyleBackColor = true;
|
||||
this.buttonOpen.Click += new EventHandler(this.buttonOpen_Click);
|
||||
//
|
||||
// numericUpDownPage
|
||||
//
|
||||
this.numericUpDownPage.Location = new Point(825, 287);
|
||||
this.numericUpDownPage.Name = "numericUpDownPage";
|
||||
this.numericUpDownPage.Size = new Size(85, 27);
|
||||
this.numericUpDownPage.TabIndex = 4;
|
||||
this.numericUpDownPage.ValueChanged += new System.EventHandler(this.numericUpDownPage_ValueChanged);
|
||||
//
|
||||
// buttonPreveous
|
||||
//
|
||||
this.buttonPrevious.Location = new Point(825, 323);
|
||||
this.buttonPrevious.Name = "buttonPreveous";
|
||||
this.buttonPrevious.Size = new Size(39, 29);
|
||||
this.buttonPrevious.TabIndex = 5;
|
||||
this.buttonPrevious.Text = "<-";
|
||||
this.buttonPrevious.UseVisualStyleBackColor = true;
|
||||
this.buttonPrevious.Click += new System.EventHandler(this.buttonPreveous_Click);
|
||||
//
|
||||
// buttonNext
|
||||
//
|
||||
this.buttonNext.Location = new Point(872, 323);
|
||||
this.buttonNext.Name = "buttonNext";
|
||||
this.buttonNext.Size = new Size(39, 29);
|
||||
this.buttonNext.TabIndex = 6;
|
||||
this.buttonNext.Text = "->";
|
||||
this.buttonNext.UseVisualStyleBackColor = true;
|
||||
this.buttonNext.Click += new EventHandler(this.buttonNext_Click);
|
||||
//
|
||||
// FormMail
|
||||
//
|
||||
this.AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
this.AutoScaleMode = AutoScaleMode.Font;
|
||||
this.ClientSize = new Size(925, 428);
|
||||
this.Controls.Add(this.buttonNext);
|
||||
this.Controls.Add(this.buttonPrevious);
|
||||
this.Controls.Add(this.numericUpDownPage);
|
||||
this.Controls.Add(this.buttonOpen);
|
||||
this.Controls.Add(this.panel);
|
||||
this.Name = "FormMail";
|
||||
this.Text = "Письма";
|
||||
this.Load += new System.EventHandler(this.FormMail_Load);
|
||||
this.panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPage)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private DataGridView dataGridView;
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonOpen;
|
||||
private NumericUpDown numericUpDownPage;
|
||||
private Button buttonPrevious;
|
||||
private Button buttonNext;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using CarRepairShopContracts.BusinessLogicsContracts;
|
||||
using CarRepairShopContracts.BindingModels;
|
||||
using CarRepairShopContracts.BusinessLogicsContracts;
|
||||
using CarRepairShopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarRepairShop
|
||||
@ -7,6 +9,8 @@ namespace CarRepairShop
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoLogic _logic;
|
||||
private int currentPage = 1;
|
||||
private int pageLength = 2;
|
||||
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -14,17 +18,26 @@ namespace CarRepairShop
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ViewMailForm_Load(object sender, EventArgs e)
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
var list = _logic.ReadList(new MessageInfoSearchModel()
|
||||
{
|
||||
PageLength = pageLength,
|
||||
PageIndex = currentPage
|
||||
|
||||
});
|
||||
numericUpDownPage.Value = pageLength;
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["MessageId"].Visible = false;
|
||||
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ReplyMessageId"].Visible = false;
|
||||
dataGridView.Columns["Reply"].Visible = false;
|
||||
dataGridView.Columns["IsReply"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Загрузка списка писем");
|
||||
}
|
||||
@ -35,5 +48,53 @@ namespace CarRepairShop
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void FormMail_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
private void buttonOpen_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count <= 0)
|
||||
return;
|
||||
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormLetter));
|
||||
if (service is FormLetter form)
|
||||
{
|
||||
string? messageId = dataGridView.SelectedRows[0].Cells["MessageId"].Value.ToString();
|
||||
if (messageId == null) return;
|
||||
form.messageId = messageId;
|
||||
|
||||
if (!Convert.ToBoolean(dataGridView.SelectedRows[0].Cells["IsReaded"].Value))
|
||||
{
|
||||
_logic.Update(new MessageInfoBindingModel
|
||||
{
|
||||
MessageId = messageId,
|
||||
IsReaded = true,
|
||||
ReplyMessageId = dataGridView.SelectedRows[0].Cells["ReplyMessageId"].Value?.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonPreveous_Click(object sender, EventArgs e)
|
||||
{
|
||||
currentPage = Math.Max(1, currentPage - 1);
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonNext_Click(object sender, EventArgs e)
|
||||
{
|
||||
currentPage++;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void numericUpDownPage_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
pageLength = Math.Max(1, (int)numericUpDownPage.Value);
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
CarRepairShop/CarRepairShop/FormMain.Designer.cs
generated
9
CarRepairShop/CarRepairShop/FormMain.Designer.cs
generated
@ -59,7 +59,7 @@
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem1, почтаToolStripMenuItem });
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1542, 28);
|
||||
@ -296,13 +296,6 @@
|
||||
private Button buttonOrderReady;
|
||||
private Button buttonIssuedOrder;
|
||||
private Button buttonRefresh;
|
||||
private ToolStripMenuItem отчётыToolStripMenuItem;
|
||||
private ToolStripMenuItem списокКомпонентовToolStripMenuItem;
|
||||
private ToolStripMenuItem компонентыПоРемонтуToolStripMenuItem;
|
||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
||||
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||
private ToolStripMenuItem запускРаботToolStripMenuItem1;
|
||||
private ToolStripMenuItem почтаToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ namespace CarRepairShop
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["RepairId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ClientEmail"].Visible = false;
|
||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||
dataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ namespace CarRepairShop
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
@ -85,7 +84,8 @@ namespace CarRepairShop
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormRepair>();
|
||||
services.AddTransient<FormLetter>();
|
||||
services.AddTransient<FormRepair>();
|
||||
services.AddTransient<FormRepairComponent>();
|
||||
services.AddTransient<FormRepairs>();
|
||||
services.AddTransient<FormClients>();
|
||||
|
@ -94,14 +94,14 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
throw new ArgumentNullException("Нет ФИО клиента",
|
||||
nameof(model.ClientFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^[a-z0-9._%+-]+\@([a-z0-9-]+\.)+[a-z]{2,4}$"))
|
||||
{
|
||||
throw new ArgumentNullException("Нет Email клиента",
|
||||
throw new ArgumentNullException("Не указана валидная почта",
|
||||
nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
if (string.IsNullOrEmpty(model.Password) || !Regex.IsMatch(model.Password, @"^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z0-9\n]).{10,50}$"))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента",
|
||||
throw new ArgumentNullException("Не указан правильный пароль",
|
||||
nameof(model.Password));
|
||||
}
|
||||
if (!Regex.IsMatch(model.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
|
||||
@ -113,7 +113,7 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
throw new ArgumentException("Некорректно введен пароль клиента", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Client. ClientFIO:{ClientFIO}." +
|
||||
"Email:{ Email}. Password:{ Password}. Id: { Id} ", model.ClientFIO, model.Email, model.Password, model.Id);
|
||||
"Email:{ Email}. Id: { Id} ", model.ClientFIO, model.Email, model.Id);
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||
{
|
||||
Email = model.Email,
|
||||
|
@ -11,24 +11,21 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoStorage _messageInfoStorage;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage MessageInfoStorage)
|
||||
private readonly IClientStorage _clientStorage;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoStorage = MessageInfoStorage;
|
||||
}
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (_messageInfoStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
_messageInfoStorage = messageInfoStorage;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId);
|
||||
var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId}.PageLength:{PageLength}.PageCount:{PageIndex}", model?.MessageId, model?.ClientId, model?.PageLength, model?.PageIndex);
|
||||
var list = _messageInfoStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
@ -37,5 +34,84 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
var message = _messageInfoStorage.Insert(model);
|
||||
if (message == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MessageInfoBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.MessageId))
|
||||
{
|
||||
throw new ArgumentNullException("Не указан id сообщения", nameof(model.MessageId));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.SenderName))
|
||||
{
|
||||
throw new ArgumentNullException("Не указао имя отправителя(электронная почта)", nameof(model.SenderName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Subject))
|
||||
{
|
||||
throw new ArgumentNullException("Не указана темма", nameof(model.Subject));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Body))
|
||||
{
|
||||
throw new ArgumentNullException("Не указан текст сообщения", nameof(model.Subject));
|
||||
}
|
||||
_logger.LogInformation("MessageInfo. MessageId:{MessageId}.SenderName:{SenderName}.Subject:{Subject}.Body:{Body}", model.MessageId, model.SenderName, model.Subject, model.Body);
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||
{
|
||||
Email = model.SenderName
|
||||
});
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("Не удалоссь найти клиента, отправившего письмо с адреса Email:{Email}", model.SenderName);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.ClientId = element.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. MessageId:{MessageId}", model?.MessageId);
|
||||
var element = _messageInfoStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.MessageId);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Update(MessageInfoBindingModel model)
|
||||
{
|
||||
CheckModel(model, withParams: false);
|
||||
if (_messageInfoStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
private readonly IClientLogic _clientLogic;
|
||||
static readonly object locker = new object();
|
||||
|
||||
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IRepairStorage repairStorage, ILogger<OrderLogic> logger)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage,
|
||||
AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IRepairStorage repairStorage, ILogger<OrderLogic> logger, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
@ -31,7 +29,6 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
_logger = logger;
|
||||
_shopLogic = shopLogic;
|
||||
_repairStorage = repairStorage;
|
||||
}
|
||||
_mailWorker = mailWorker;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
@ -220,7 +217,6 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private bool SendOrderStatusMail(int clientId, string subject, string text)
|
||||
{
|
||||
var client = _clientLogic.ReadElement(new() { Id = clientId });
|
||||
|
@ -72,7 +72,50 @@ namespace CarRepairShopBusinessLogic.MailWorker
|
||||
_messageInfoLogic.Create(mail);
|
||||
}
|
||||
}
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
public async void MailSendReplyAsync(MailReplySendInfoBindingModel 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) || string.IsNullOrEmpty(info.ParentMessageId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Send Mail as reply: {To}, {Subject}, {parentId}", info.MailAddress, info.Subject, info.ParentMessageId);
|
||||
|
||||
string? messageId = await SendMailAsync(info);
|
||||
if (string.IsNullOrEmpty(messageId))
|
||||
{
|
||||
throw new InvalidOperationException("Непредвиденная ошибка при отправке сообщения в ответ");
|
||||
}
|
||||
if (_messageInfoLogic.Create(new MessageInfoBindingModel
|
||||
{
|
||||
MessageId = messageId,
|
||||
DateDelivery = DateTime.Now,
|
||||
SenderName = _mailLogin,
|
||||
IsReply = true,
|
||||
Subject = info.Subject,
|
||||
Body = info.Text,
|
||||
}))
|
||||
{
|
||||
_messageInfoLogic.Update(new MessageInfoBindingModel()
|
||||
{
|
||||
MessageId = info.ParentMessageId,
|
||||
ReplyMessageId = messageId,
|
||||
IsReaded = true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task<string?> SendMailAsync(MailSendInfoBindingModel info);
|
||||
protected abstract Task<List<MessageInfoBindingModel>>
|
||||
ReceiveMailAsync();
|
||||
}
|
||||
|
@ -13,29 +13,32 @@ namespace CarRepairShopBusinessLogic.MailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger,
|
||||
IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { }
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
protected override async Task<string?> SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
string? resount = null;
|
||||
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));
|
||||
ConfigurateSmtpClient(objSmtpClient);
|
||||
CreateMessage(objMailMessage, info);
|
||||
if (info is MailReplySendInfoBindingModel replyInfo)
|
||||
{
|
||||
objMailMessage.Headers.Add("In-Reply-To", replyInfo.ParentMessageId);
|
||||
objMailMessage.Headers.Add("References", replyInfo.ParentMessageId);
|
||||
|
||||
string messageGuid = Guid.NewGuid().ToString();
|
||||
objMailMessage.Headers.Add("Message-Id", messageGuid);
|
||||
resount = messageGuid;
|
||||
}
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return resount;
|
||||
}
|
||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||
{
|
||||
var list = new List<MessageInfoBindingModel>();
|
||||
@ -71,5 +74,22 @@ namespace CarRepairShopBusinessLogic.MailWorker
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
private void CreateMessage(MailMessage objMailMessage, MailSendInfoBindingModel info)
|
||||
{
|
||||
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;
|
||||
}
|
||||
private void ConfigurateSmtpClient(SmtpClient objSmtpClient)
|
||||
{
|
||||
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarRepairShopContracts.BindingModels
|
||||
{
|
||||
public class MailReplySendInfoBindingModel : MailSendInfoBindingModel
|
||||
{
|
||||
public string ParentMessageId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -15,5 +15,8 @@ namespace CarRepairShopContracts.BindingModels
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
public bool IsReaded { get; set; }
|
||||
public string? ReplyMessageId { get; set; }
|
||||
public bool IsReply { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ namespace CarRepairShopContracts.BusinessLogicsContracts
|
||||
public interface IMessageInfoLogic
|
||||
{
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
MessageInfoViewModel? ReadElement(MessageInfoSearchModel model);
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
bool Update(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,7 @@
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
public string? MessageId { get; set; }
|
||||
public int? PageLength { get; set; }
|
||||
public int? PageIndex { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace CarRepairShopContracts.StoragesContracts
|
||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||
MessageInfoViewModel? Update(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -15,5 +15,13 @@ namespace CarRepairShopContracts.ViewModels
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
[DisplayName("Текст")]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
[DisplayName("Прочитанно")]
|
||||
public bool IsReaded { get; set; }
|
||||
|
||||
public string? ReplyMessageId { get; set; }
|
||||
|
||||
public IMessageInfoModel? Reply { get; set; }
|
||||
|
||||
public bool IsReply { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace CarRepairShopContracts.ViewModels
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public string ClientEmail { get; set; } = string.Empty;
|
||||
public int? ImplementerId { get; set; } = null;
|
||||
[DisplayName("Исполнитель")]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
@ -8,5 +8,8 @@
|
||||
DateTime DateDelivery { get; }
|
||||
string Subject { get; }
|
||||
string Body { get; }
|
||||
bool IsReaded { get; }
|
||||
string? ReplyMessageId { get; }
|
||||
bool IsReply { get; }
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,21 @@ namespace CarRepairShopDatabaseImplement.Implements
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue && !model.PageLength.HasValue && !model.PageIndex.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new RepairsShopDatabase();
|
||||
return context.Messages
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
IEnumerable<MessageInfo> request = context.Messages.Where(x => !x.IsReply);
|
||||
if (model.ClientId.HasValue)
|
||||
request = request.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId);
|
||||
if (model.PageLength.HasValue)
|
||||
{
|
||||
int skipRows = model.PageIndex.HasValue ? (model.PageIndex.Value - 1) * model.PageLength.Value : 0;
|
||||
request = request.Skip(skipRows).Take(model.PageLength.Value);
|
||||
}
|
||||
|
||||
return request.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
@ -47,5 +57,17 @@ namespace CarRepairShopDatabaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||
{
|
||||
using var context = new RepairsShopDatabase();
|
||||
var message = context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId);
|
||||
if (message == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
message.Update(context, model);
|
||||
context.SaveChanges();
|
||||
return message.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
394
CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240520225652_InitialCreate.Designer.cs
generated
Normal file
394
CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240520225652_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,394 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarRepairShopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRepairShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(RepairsShopDatabase))]
|
||||
[Migration("20240520225652_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsReaded")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsReply")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("ReplyMessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("MessageId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ReplyMessageId");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("MaxCapacity")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("MessageInfos")
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.MessageInfo", "Reply")
|
||||
.WithMany()
|
||||
.HasForeignKey("ReplyMessageId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Reply");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("ShopRepairs")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Repairs")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("MessageInfos");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Repairs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -71,26 +71,6 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
<<<<<<<< HEAD:CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240507162722_InitialCreate.cs
|
||||
name: "Messages",
|
||||
columns: table => new
|
||||
{
|
||||
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: true),
|
||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Body = table.Column<string>(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");
|
||||
========
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
@ -104,7 +84,35 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
>>>>>>>> Lab6_Hard:CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240507192029_InitialCreate.cs
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Messages",
|
||||
columns: table => new
|
||||
{
|
||||
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: true),
|
||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
IsReaded = table.Column<bool>(type: "bit", nullable: false),
|
||||
ReplyMessageId = table.Column<string>(type: "nvarchar(450)", nullable: true),
|
||||
IsReply = table.Column<bool>(type: "bit", 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");
|
||||
table.ForeignKey(
|
||||
name: "FK_Messages_Messages_ReplyMessageId",
|
||||
column: x => x.ReplyMessageId,
|
||||
principalTable: "Messages",
|
||||
principalColumn: "MessageId");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@ -203,6 +211,11 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
table: "Messages",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Messages_ReplyMessageId",
|
||||
table: "Messages",
|
||||
column: "ReplyMessageId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
@ -109,6 +109,15 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsReaded")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsReply")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("ReplyMessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@ -121,6 +130,8 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ReplyMessageId");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
@ -272,7 +283,13 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
.WithMany("MessageInfos")
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.HasOne("CarRepairShopDatabaseImplement.Models.MessageInfo", "Reply")
|
||||
.WithMany()
|
||||
.HasForeignKey("ReplyMessageId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Reply");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b =>
|
||||
@ -340,9 +357,9 @@ namespace CarRepairShopDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("MessageInfos");
|
||||
b.Navigation("MessageInfos");
|
||||
|
||||
b.Navigation("Orders");
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Component", b =>
|
||||
|
@ -2,6 +2,7 @@
|
||||
using CarRepairShopContracts.ViewModels;
|
||||
using CarRepairShopDataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace CarRepairShopDatabaseImplement.Models
|
||||
{
|
||||
@ -15,6 +16,16 @@ namespace CarRepairShopDatabaseImplement.Models
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
public Client? Client { get; private set; }
|
||||
[Required]
|
||||
public bool IsReaded { get; set; }
|
||||
|
||||
public string? ReplyMessageId { get; set; }
|
||||
|
||||
[ForeignKey("ReplyMessageId")]
|
||||
public virtual MessageInfo? Reply { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool IsReply { get; set; }
|
||||
public static MessageInfo? Create(RepairsShopDatabase context, MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -30,6 +41,9 @@ namespace CarRepairShopDatabaseImplement.Models
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
IsReaded = model.IsReaded,
|
||||
ReplyMessageId = model.ReplyMessageId,
|
||||
IsReply = model.IsReply
|
||||
};
|
||||
}
|
||||
|
||||
@ -41,6 +55,23 @@ namespace CarRepairShopDatabaseImplement.Models
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
IsReaded = IsReaded,
|
||||
ReplyMessageId = ReplyMessageId,
|
||||
Reply = Reply,
|
||||
IsReply = IsReply
|
||||
};
|
||||
public void Update(RepairsShopDatabase context, MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IsReaded = model.IsReaded;
|
||||
ReplyMessageId = model.ReplyMessageId;
|
||||
if (!string.IsNullOrEmpty(ReplyMessageId))
|
||||
{
|
||||
Reply = context.Messages.First(x => x.MessageId == ReplyMessageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,8 @@ namespace CarRepairShopDatabaseImplement.Models
|
||||
ImplementerId = ImplementerId,
|
||||
RepairName = Repair?.RepairName ?? string.Empty,
|
||||
ClientFIO = Client?.ClientFIO ?? string.Empty,
|
||||
Count = Count,
|
||||
ClientEmail = Client.Email,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
|
@ -25,10 +25,12 @@ namespace CarRepairShopFileImplement.Implements
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
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.PageIndex.HasValue && model.PageLength.HasValue))
|
||||
{
|
||||
return res.ToList();
|
||||
}
|
||||
return res.Skip((model.PageIndex.Value - 1) * model.PageLength.Value).Take(model.PageLength.Value).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
@ -49,5 +51,15 @@ namespace CarRepairShopFileImplement.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,11 @@ namespace CarRepairShopFileImplement.Models
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
public bool IsReaded { get; private set; }
|
||||
public bool IsReply { get; private set; }
|
||||
public string? ReplyMessageId { get; private set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -33,7 +36,10 @@ namespace CarRepairShopFileImplement.Models
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
};
|
||||
IsReply = model.IsReply,
|
||||
IsReaded = model.IsReaded,
|
||||
ReplyMessageId = model.ReplyMessageId,
|
||||
};
|
||||
}
|
||||
|
||||
public static MessageInfo? Create(XElement element)
|
||||
@ -45,15 +51,26 @@ namespace CarRepairShopFileImplement.Models
|
||||
return new()
|
||||
{
|
||||
Body = element.Attribute("Body")!.Value,
|
||||
Subject = element.Attribute("Subject")!.Value,
|
||||
IsReply = Convert.ToBoolean(element.Attribute("IsReply")!.Value),
|
||||
IsReaded = Convert.ToBoolean(element.Attribute("HasRead")!.Value),
|
||||
ReplyMessageId = element.Attribute("ReplyMessageId")!.Value,
|
||||
Subject = element.Attribute("Subject")!.Value,
|
||||
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||
MessageId = element.Attribute("MessageId")!.Value,
|
||||
SenderName = element.Attribute("SenderName")!.Value,
|
||||
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
public void Update(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IsReply = model.IsReply;
|
||||
IsReaded = model.IsReaded;
|
||||
}
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
@ -61,7 +78,10 @@ namespace CarRepairShopFileImplement.Models
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
};
|
||||
IsReply = IsReply,
|
||||
IsReaded = IsReaded,
|
||||
ReplyMessageId = ReplyMessageId,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("MessageInfo",
|
||||
new XAttribute("Body", Body),
|
||||
@ -69,7 +89,10 @@ namespace CarRepairShopFileImplement.Models
|
||||
new XAttribute("ClientId", ClientId),
|
||||
new XAttribute("MessageId", MessageId),
|
||||
new XAttribute("SenderName", SenderName),
|
||||
new XAttribute("DateDelivery", DateDelivery)
|
||||
);
|
||||
new XAttribute("DateDelivery", DateDelivery),
|
||||
new XAttribute("ReplyMessageId", ReplyMessageId),
|
||||
new XAttribute("IsReply", IsReply),
|
||||
new XAttribute("IsReaded", IsReaded)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,20 @@ namespace CarRepairShopListImplement.Implements
|
||||
result.Add(item.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
if (!(model.PageIndex.HasValue && model.PageLength.HasValue))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (model.PageIndex * model.PageLength >= result.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<MessageInfoViewModel> filteredResult = new();
|
||||
for (var i = (model.PageIndex.Value - 1) * model.PageLength.Value; i < model.PageIndex.Value * model.PageLength.Value; i++)
|
||||
{
|
||||
filteredResult.Add(result[i]);
|
||||
}
|
||||
return filteredResult;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
@ -57,5 +70,17 @@ namespace CarRepairShopListImplement.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ namespace CarRepairShopListImplement.Models
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
public bool IsReaded { get; private set; }
|
||||
public bool IsReply { get; private set; }
|
||||
public string? ReplyMessageId { get; private set; }
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
@ -32,9 +35,20 @@ namespace CarRepairShopListImplement.Models
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
IsReply = model.IsReply,
|
||||
IsReaded = model.IsReaded,
|
||||
ReplyMessageId = model.ReplyMessageId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IsReply = model.IsReply;
|
||||
IsReaded = model.IsReaded;
|
||||
}
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
@ -43,6 +57,9 @@ namespace CarRepairShopListImplement.Models
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
IsReply = IsReply,
|
||||
IsReaded = IsReaded,
|
||||
ReplyMessageId = ReplyMessageId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using CarRepairShopContracts.BusinessLogicsContracts;
|
||||
using CarRepairShopContracts.SearchModels;
|
||||
using CarRepairShopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
|
||||
namespace CarRepairShopRestApi.Controllers
|
||||
{
|
||||
@ -12,14 +13,14 @@ namespace CarRepairShopRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController>
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController>
|
||||
logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
[HttpGet]
|
||||
public ClientViewModel? Login(string login, string password)
|
||||
{
|
||||
@ -37,23 +38,23 @@ namespace CarRepairShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void Register(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -63,7 +64,7 @@ namespace CarRepairShopRestApi.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
@ -79,5 +80,23 @@ namespace CarRepairShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId, int page, int pagesize = 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId,
|
||||
PageLength = pagesize,
|
||||
PageIndex = page
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ namespace CarRepairShowClientApp
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
public static ClientViewModel? Client { get; set; } = null;
|
||||
public static void Connect(IConfiguration configuration)
|
||||
public static int MailPage { get; set; } = 1;
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
|
@ -145,14 +145,15 @@ namespace CarRepairShowClientApp.Controllers
|
||||
return count * (rep?.Price ?? 1);
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Mails()
|
||||
public IActionResult Mails(int page = 1)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
page = Math.Max(page, 1);
|
||||
return
|
||||
View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}&page={page}"));
|
||||
}
|
||||
}
|
||||
}
|
@ -50,5 +50,23 @@
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
@{
|
||||
int page = int.Parse(Context.Request.Query["page"]);
|
||||
<div class="m-1">
|
||||
<input type="number" class="form-control" min="1" step="1" asp-action="Mails" name="page" value="@(page)" readonly>
|
||||
</div>
|
||||
if (page > 1)
|
||||
{
|
||||
<a name="page" class="btn btn-primary" type="button" asp-action="Mails" asp-route-page="@(page-1)"><-</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="btn btn-primary my-auto"><-</p>
|
||||
}
|
||||
|
||||
<a name="" id="" class="btn btn-primary" type="button" asp-action="Mails" asp-route-page="@(page+1)">-></a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user