2023-03-18 05:10:51 +04:00
|
|
|
|
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 ConfectioneryBusinessLogic.MailWorker;
|
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using MimeKit;
|
|
|
|
|
|
|
|
|
|
namespace ConfectioneryView
|
|
|
|
|
{
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
public FormReplyMail(ILogger<FormReplyMail> logger, AbstractMailWorker mailWorker, IMessageInfoLogic logic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_mailWorker = mailWorker;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-03-18 06:53:42 +04:00
|
|
|
|
var guid = Guid.NewGuid();
|
|
|
|
|
var newMsgId = $"<{guid.ToString().Replace("-", "")}@f129.i.mail.ru>";
|
2023-03-18 05:10:51 +04:00
|
|
|
|
_mailWorker.MailSendAsync(new()
|
|
|
|
|
{
|
2023-03-18 06:53:42 +04:00
|
|
|
|
MessageId = newMsgId,
|
|
|
|
|
ReplyMessageId = _message.MessageId,
|
2023-03-18 05:10:51 +04:00
|
|
|
|
MailAddress = _message.SenderName,
|
|
|
|
|
Subject = _message.Subject,
|
|
|
|
|
Text = textBoxReply.Text,
|
|
|
|
|
});
|
2023-03-18 06:53:42 +04:00
|
|
|
|
_logic.Create(new()
|
|
|
|
|
{
|
|
|
|
|
MessageId = newMsgId,
|
|
|
|
|
Body = textBoxReply.Text,
|
|
|
|
|
ClientId = _message.ClientId,
|
|
|
|
|
HasRead = false,
|
|
|
|
|
Subject = _message.Subject,
|
|
|
|
|
});
|
2023-03-18 05:10:51 +04:00
|
|
|
|
_logic.Update(new()
|
|
|
|
|
{
|
|
|
|
|
MessageId = MessageId,
|
|
|
|
|
HasRead = true,
|
2023-03-18 06:53:42 +04:00
|
|
|
|
ReplyMessageId = newMsgId,
|
2023-03-18 05:10:51 +04:00
|
|
|
|
});
|
|
|
|
|
MessageBox.Show("Успешно отправлено письмо", "Отправка письма", MessageBoxButtons.OK);
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
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}";
|
|
|
|
|
textBoxHead.Text = _message.Subject;
|
|
|
|
|
textBoxMail.Text = _message.Body;
|
|
|
|
|
_logic.Update(new() { MessageId = MessageId, HasRead = true });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения собщения");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|