From 8395929466906896c86c631213d01a5c3ea4a084 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Sun, 23 Apr 2023 03:34:02 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B8=D0=BB=D0=B8=20=D0=BD=D0=B5=D1=82,=20=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataFileSingleton.cs | 14 +- .../MessageInfo.cs | 82 ++++ .../MessageInfoStorage.cs | 54 +++ .../BusinessLogic/ClientLogic.cs | 12 +- .../BusinessLogic/MessageInfoLogic.cs | 48 ++ .../BusinessLogic/OrderLogic.cs | 33 +- .../MailWorker/AbstractMailWorker.cs | 100 +++++ .../MailWorker/MailKitWorker.cs | 82 ++++ .../Controllers/HomeController.cs | 13 +- .../Views/Home/Mails.cshtml | 54 +++ .../BindingModels/MailConfigBindingModel.cs | 18 + .../BindingModels/MailSendInfoBindingModel.cs | 15 + .../BindingModels/MessageInfoBindingModel.cs | 24 + .../IMessageInfoLogic.cs | 18 + .../SearchModels/MessageInfoSearchModel.cs | 15 + .../StoragesContracts/IMessageInfoStorage.cs | 22 + .../ViewModels/MessageInfoViewModel.cs | 29 ++ .../IMessageInfoModel.cs | 23 + .../Client.cs | 3 + .../MessageInfo.cs | 55 +++ .../MessageInfoStorage.cs | 52 +++ .../SoftwareInstallationDatabase.cs | 3 +- .../DataListSingleton.cs | 9 +- .../MessageInfo.cs | 56 +++ .../MessageInfoStorage.cs | 61 +++ .../Controllers/ClientController.cs | 24 +- .../SoftwareInstallationRestApi/Program.cs | 19 + .../appsettings.json | 9 +- .../SoftwareInstallationView/App.config | 11 + .../FormMain.Designer.cs | 415 +++++++++--------- .../SoftwareInstallationView/FormMain.cs | 387 ++++++++-------- .../FormViewMail.Designer.cs | 62 +++ .../SoftwareInstallationView/FormViewMail.cs | 50 +++ .../FormViewMail.resx | 60 +++ .../SoftwareInstallationView/Program.cs | 38 +- 35 files changed, 1556 insertions(+), 414 deletions(-) create mode 100644 SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfo.cs create mode 100644 SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/IMessageInfoModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/MessageInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/App.config create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormViewMail.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormViewMail.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormViewMail.resx diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs index c8fafc4..3f09bcb 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs @@ -10,14 +10,16 @@ namespace SoftwareInstallationFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PackageFileName = "Package.xml"; private readonly string ClientFileName = "Client.xml"; - private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageInfoFileName = "MessageInfo.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Packages { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List Messages { get; private set; } - public static DataFileSingleton GetInstance() + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -30,16 +32,18 @@ namespace SoftwareInstallationFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement); - private DataFileSingleton() + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; - } - private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) { diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfo.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfo.cs new file mode 100644 index 0000000..39a6107 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfo.cs @@ -0,0 +1,82 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + // Update в этой сущности не нужен, поскольку в логике мы не изменяем никакие поля после создания письма + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.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() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Body", Body), + new XAttribute("Subject", Subject), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } + +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfoStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfoStorage.cs new file mode 100644 index 0000000..0bfa534 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/MessageInfoStorage.cs @@ -0,0 +1,54 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; +using System.Reflection; + +namespace SoftwareInstallationFileImplement +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton _source; + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId != null) + { + return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + return _source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return _source.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + _source.SaveMessages(); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs index 7095546..63be25e 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs @@ -1,10 +1,10 @@ -using SoftwareInstallationBusinessLogic.BusinessLogics; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; namespace SoftwareInstallationBusinessLogic { @@ -102,6 +102,14 @@ namespace SoftwareInstallationBusinessLogic { throw new ArgumentNullException("Нет логина клиента", nameof(model.Email)); } + 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)); + } _logger.LogInformation("Client. Id: {Id}, FIO: {fio}, email: {email}", model.Id, model.ClientFIO, model.Email); var element = _clientStorage.GetElement(new ClientSearchModel { diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs new file mode 100644 index 0000000..50f6c33 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs @@ -0,0 +1,48 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _messageInfoStorage; + public MessageInfoLogic(ILogger logger, IMessageInfoStorage MessageInfoStorage) + { + _logger = logger; + _messageInfoStorage = MessageInfoStorage; + } + + public bool Create(MessageInfoBindingModel model) + { + if (_messageInfoStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId); + var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs index c4cc05a..3872706 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,10 +1,12 @@ using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationBusinessLogic.MailWorker; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; using Microsoft.Extensions.Logging; +using SoftwareInstallationBusinessLogic.MailWorker; namespace SoftwareInstallationBusinessLogic.BusinessLogics { @@ -12,11 +14,15 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly AbstractMailWorker _mailWorker; + private readonly IClientLogic _clientLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) { _logger = logger; _orderStorage = orderStorage; + _mailWorker = mailWorker; + _clientLogic = clientLogic; } public bool CreateOrder(OrderBindingModel model) { @@ -29,11 +35,13 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics } model.Status = OrderStatus.Принят; model.DateCreate = DateTime.Now; - if (_orderStorage.Insert(model) == null) + var result = _orderStorage.Insert(model); + if (result == null) { _logger.LogWarning("Insert operation failed"); return false; } + SendOrderStatusMail(result.ClientId, $"Новый заказ создан. Номер заказа #{result.Id}", $"Заказ #{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); return true; } @@ -106,11 +114,13 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics model.Sum = viewModel.Sum; model.Count = viewModel.Count; model.PackageId = viewModel.PackageId; - if (_orderStorage.Update(model) == null) + var result = _orderStorage.Update(model); + if (result == null) { _logger.LogWarning("Ошибка операции обновления"); return false; } + SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}"); return true; } public OrderViewModel? ReadElement(OrderSearchModel model) @@ -129,5 +139,20 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - } + private bool SendOrderStatusMail(int clientId, string subject, string text) + { + var client = _clientLogic.ReadElement(new() { Id = clientId }); + if (client == null) + { + return false; + } + _mailWorker.MailSendAsync(new() + { + MailAddress = client.Email, + Subject = subject, + Text = text + }); + return true; + } + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..722721c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,100 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + + protected string _mailPassword = string.Empty; + + protected string _smtpClientHost = string.Empty; + + protected int _smtpClientPort; + + protected string _popHost = string.Empty; + + protected int _popPort; + + private readonly IMessageInfoLogic _messageInfoLogic; + private readonly IClientLogic _clientLogic; + + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + { + _logger = logger; + _messageInfoLogic = messageInfoLogic; + _clientLogic = clientLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + await SendMailAsync(info); + } + + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + + if (_messageInfoLogic == null) + { + return; + } + + var list = await ReceiveMailAsync(); + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + foreach (var mail in list) + { + mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id; + _messageInfoLogic.Create(mail); + } + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + + protected abstract Task> ReceiveMailAsync(); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..002e8b5 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,82 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + + protected override async Task> ReceiveMailAsync() + { + var list = new List(); + using var client = new Pop3Client(); + await Task.Run(() => + { + try + { + client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + client.Authenticate(_mailLogin, _mailPassword); + for (int i = 0; i < client.Count; i++) + { + var message = client.GetMessage(i); + foreach (var mail in message.From.Mailboxes) + { + list.Add(new MessageInfoBindingModel + { + DateDelivery = message.Date.DateTime, + MessageId = message.MessageId, + SenderName = mail.Address, + Subject = message.Subject, + Body = message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + return list; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs index e0730de..d59d80c 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using SoftwareInstallationContracts.ViewModels; namespace SoftwareInstallationClientApp.Controllers { @@ -144,5 +145,15 @@ namespace SoftwareInstallationClientApp.Controllers var prod = APIClient.GetRequest($"api/main/getpackage?packageId={package}"); return count * (prod?.Price ?? 1); } - } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..0446c5d --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using SoftwareInstallationContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Письма

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

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

+ return; + } + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..2a19212 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + public string MailPassword { get; set; } = string.Empty; + public string SmtpClientHost { get; set; } = string.Empty; + public int SmtpClientPort { get; set; } + public string PopHost { get; set; } = string.Empty; + public int PopPort { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..1fdb3f3 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..8d47bc3 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,24 @@ +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..5b247ca --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,18 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + + bool Create(MessageInfoBindingModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..76d8c47 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public int? ClientId { get; set; } + + public string? MessageId { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..bbc6f74 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,22 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + + List GetFilteredList(MessageInfoSearchModel model); + + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..12aa517 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,29 @@ +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [DisplayName("Отправитель")] + public string SenderName { get; set; } = string.Empty; + + [DisplayName("Дата письма")] + public DateTime DateDelivery { get; set; } + + [DisplayName("Заголовок")] + public string Subject { get; set; } = string.Empty; + + [DisplayName("Текст")] + public string Body { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IMessageInfoModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IMessageInfoModel.cs new file mode 100644 index 0000000..46a8d89 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IMessageInfoModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDataModels +{ + public interface IMessageInfoModel + { + string MessageId { get; } + + int? ClientId { get; } + + string SenderName { get; } + + DateTime DateDelivery { get; } + + string Subject { get; } + + string Body { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Client.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Client.cs index cc86a17..670e66b 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Client.cs @@ -23,6 +23,9 @@ namespace SoftwareInstallationDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); + public static Client? Create(ClientBindingModel model) { if (model == null) diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfo.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfo.cs new file mode 100644 index 0000000..ce71a3f --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfo.cs @@ -0,0 +1,55 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System.ComponentModel.DataAnnotations; + +namespace SoftwareInstallationDatabaseImplement.Models +{ + // Update в этой сущности не нужен, поскольку в логике мы не изменяем никакие поля после создания письма + public class MessageInfo : IMessageInfoModel + { + [Key] + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public Client? Client { get; private set; } + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + } + +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfoStorage.cs new file mode 100644 index 0000000..d1e828c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/MessageInfoStorage.cs @@ -0,0 +1,52 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDatabaseImplement.Models; + +namespace SoftwareInstallationDatabaseImplement +{ + public class MessageInfoStorage : IMessageInfoStorage + { + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + using var context = new SoftwareInstallationDatabase(); + if (model.MessageId != null) + { + return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + using var context = new SoftwareInstallationDatabase(); + return context.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SoftwareInstallationDatabase(); + return context.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + var newMessage = MessageInfo.Create(model); + if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) + { + return null; + } + context.Messages.Add(newMessage); + context.SaveChanges(); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs index 16c2e57..a49202f 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs @@ -25,5 +25,6 @@ namespace SoftwareInstallationDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } - } + public virtual DbSet Messages { set; get; } + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs index 17e887c..8ed33cd 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs @@ -10,15 +10,18 @@ namespace SoftwareInstallationListImplement public List Packages { get; set; } public List Clients { get; set; } public List Implementers { get; set; } - private DataListSingleton() + public List Messages { get; set; } + + private DataListSingleton() { Components = new List(); Orders = new List(); Packages = new List(); Clients = new List(); Implementers = new List(); - } - public static DataListSingleton GetInstance() + Messages = new List(); + } + public static DataListSingleton GetInstance() { if (_instance == null) { diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/MessageInfo.cs b/SoftwareInstallation/SoftwareInstallationListImplement/MessageInfo.cs new file mode 100644 index 0000000..d3e5994 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/MessageInfo.cs @@ -0,0 +1,56 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement.Models +{ + // Update в этой сущности не нужен, поскольку в логике мы не изменяем никакие поля после создания письма + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + } + +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/MessageInfoStorage.cs new file mode 100644 index 0000000..5d4af95 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/MessageInfoStorage.cs @@ -0,0 +1,61 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; + +namespace SoftwareInstallationListImplement +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + foreach (var message in _source.Messages) + { + if (model.MessageId != null && model.MessageId.Equals(message.MessageId)) + return message.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + List result = new(); + foreach (var item in _source.Messages) + { + if (item.ClientId.HasValue && item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + List result = new(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs index 0ed9735..2c41dc3 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ClientController.cs @@ -3,6 +3,9 @@ using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; using Microsoft.AspNetCore.Mvc; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; namespace SoftwareInstallationRestApi.Controllers { @@ -14,10 +17,13 @@ namespace SoftwareInstallationRestApi.Controllers private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } [HttpGet] @@ -66,5 +72,21 @@ namespace SoftwareInstallationRestApi.Controllers throw; } } + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } } } diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs index 6696f9a..a1bc8cc 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs @@ -3,6 +3,9 @@ using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationDatabaseImplement.Implements; +using SoftwareInstallationBusinessLogic.MailWorker; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationDatabaseImplement; using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); @@ -14,6 +17,10 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddSingleton(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -32,6 +39,18 @@ builder.Services.AddSwaggerGen(c => }); }); var app = builder.Build(); + +var mailSender = app.Services.GetService(); + +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json b/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json index 10f68b8..697acfb 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json +++ b/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.mail.ru", + "SmtpClientPort": "587", + "PopHost": "pop.mail.ru", + "PopPort": "995", + "MailLogin": "ordersender228@mail.ru", + "MailPassword": "v8czsQ8zztJc5wEHxKPN" } diff --git a/SoftwareInstallation/SoftwareInstallationView/App.config b/SoftwareInstallation/SoftwareInstallationView/App.config new file mode 100644 index 0000000..400d322 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs index ddbcd6e..0ddc7b4 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -1,211 +1,220 @@ namespace SoftwareInstallationView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #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() - { - menuStrip1 = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - packageToolStripMenuItem = new ToolStripMenuItem(); - componentToolStripMenuItem = new ToolStripMenuItem(); - ImplementersToolStripMenuItem = new ToolStripMenuItem(); - ClientsToolStripMenuItem = new ToolStripMenuItem(); - отчётыToolStripMenuItem = new ToolStripMenuItem(); - списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); - компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); - списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); - DoWorkToolStripMenuItem = new ToolStripMenuItem(); - ButtonRef = new Button(); - ButtonIssuedOrder = new Button(); - buttonCreateOrder = new Button(); - dataGridView = new DataGridView(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, DoWorkToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1125, 24); - menuStrip1.TabIndex = 1; - menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { packageToolStripMenuItem, componentToolStripMenuItem, ImplementersToolStripMenuItem, ClientsToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(94, 20); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // packageToolStripMenuItem - // - packageToolStripMenuItem.Name = "packageToolStripMenuItem"; - packageToolStripMenuItem.Size = new Size(180, 22); - packageToolStripMenuItem.Text = "Изделия"; - packageToolStripMenuItem.Click += PackagesToolStripMenuItem_Click; - // - // componentToolStripMenuItem - // - componentToolStripMenuItem.Name = "componentToolStripMenuItem"; - componentToolStripMenuItem.Size = new Size(180, 22); - componentToolStripMenuItem.Text = "Компоненты"; - componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; - // - // ImplementersToolStripMenuItem - // - ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; - ImplementersToolStripMenuItem.Size = new Size(180, 22); - ImplementersToolStripMenuItem.Text = "Исполнители"; - ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; - // - // ClientsToolStripMenuItem - // - ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(180, 22); - ClientsToolStripMenuItem.Text = "Клиенты"; - ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // - // отчётыToolStripMenuItem - // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); - отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - отчётыToolStripMenuItem.Size = new Size(60, 20); - отчётыToolStripMenuItem.Text = "Отчёты"; - // - // списокКомпонентовToolStripMenuItem - // - списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - списокКомпонентовToolStripMenuItem.Size = new Size(218, 22); - списокКомпонентовToolStripMenuItem.Text = "Список изделий"; - списокКомпонентовToolStripMenuItem.Click += ComponentsReportToolStripMenuItem_Click; - // - // компонентыПоИзделиямToolStripMenuItem - // - компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - компонентыПоИзделиямToolStripMenuItem.Size = new Size(218, 22); - компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; - компонентыПоИзделиямToolStripMenuItem.Click += ComponentPackagesToolStripMenuItem_Click; - // - // списокЗаказовToolStripMenuItem - // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(218, 22); - списокЗаказовToolStripMenuItem.Text = "Список Заказов"; - списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; - // - // DoWorkToolStripMenuItem - // - DoWorkToolStripMenuItem.Name = "DoWorkToolStripMenuItem"; - DoWorkToolStripMenuItem.Size = new Size(92, 20); - DoWorkToolStripMenuItem.Text = "Запуск работ"; - DoWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; - // - // ButtonRef - // - ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonRef.Location = new Point(966, 149); - ButtonRef.Name = "ButtonRef"; - ButtonRef.Size = new Size(147, 55); - ButtonRef.TabIndex = 12; - ButtonRef.Text = "Обновить список"; - ButtonRef.UseVisualStyleBackColor = true; - ButtonRef.Click += ButtonRef_Click; - // - // ButtonIssuedOrder - // - ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonIssuedOrder.Location = new Point(966, 88); - ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - ButtonIssuedOrder.Size = new Size(147, 55); - ButtonIssuedOrder.TabIndex = 11; - ButtonIssuedOrder.Text = "Заказ выдан"; - ButtonIssuedOrder.UseVisualStyleBackColor = true; - ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonCreateOrder - // - buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.Location = new Point(966, 27); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(147, 55); - buttonCreateOrder.TabIndex = 8; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.BackgroundColor = SystemColors.ButtonHighlight; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 27); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(948, 402); - dataGridView.TabIndex = 7; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1125, 441); - Controls.Add(ButtonRef); - Controls.Add(ButtonIssuedOrder); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - Name = "FormMain"; - Text = "Установка ПО"; - Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + packageToolStripMenuItem = new ToolStripMenuItem(); + componentToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); + компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); + списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + DoWorkToolStripMenuItem = new ToolStripMenuItem(); + ButtonRef = new Button(); + ButtonIssuedOrder = new Button(); + buttonCreateOrder = new Button(); + dataGridView = new DataGridView(); + mailToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, DoWorkToolStripMenuItem, mailToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1125, 24); + menuStrip1.TabIndex = 1; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { packageToolStripMenuItem, componentToolStripMenuItem, ImplementersToolStripMenuItem, ClientsToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // packageToolStripMenuItem + // + packageToolStripMenuItem.Name = "packageToolStripMenuItem"; + packageToolStripMenuItem.Size = new Size(149, 22); + packageToolStripMenuItem.Text = "Изделия"; + packageToolStripMenuItem.Click += PackagesToolStripMenuItem_Click; + // + // componentToolStripMenuItem + // + componentToolStripMenuItem.Name = "componentToolStripMenuItem"; + componentToolStripMenuItem.Size = new Size(149, 22); + componentToolStripMenuItem.Text = "Компоненты"; + componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(149, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(149, 22); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // отчётыToolStripMenuItem + // + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(60, 20); + отчётыToolStripMenuItem.Text = "Отчёты"; + // + // списокКомпонентовToolStripMenuItem + // + списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; + списокКомпонентовToolStripMenuItem.Size = new Size(218, 22); + списокКомпонентовToolStripMenuItem.Text = "Список изделий"; + списокКомпонентовToolStripMenuItem.Click += ComponentsReportToolStripMenuItem_Click; + // + // компонентыПоИзделиямToolStripMenuItem + // + компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; + компонентыПоИзделиямToolStripMenuItem.Size = new Size(218, 22); + компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; + компонентыПоИзделиямToolStripMenuItem.Click += ComponentPackagesToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(218, 22); + списокЗаказовToolStripMenuItem.Text = "Список Заказов"; + списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // DoWorkToolStripMenuItem + // + DoWorkToolStripMenuItem.Name = "DoWorkToolStripMenuItem"; + DoWorkToolStripMenuItem.Size = new Size(92, 20); + DoWorkToolStripMenuItem.Text = "Запуск работ"; + DoWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; + // + // ButtonRef + // + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(966, 149); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(147, 55); + ButtonRef.TabIndex = 12; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonIssuedOrder + // + ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonIssuedOrder.Location = new Point(966, 88); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(147, 55); + ButtonIssuedOrder.TabIndex = 11; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(966, 27); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(147, 55); + buttonCreateOrder.TabIndex = 8; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(948, 402); + dataGridView.TabIndex = 7; + // + // mailToolStripMenuItem + // + mailToolStripMenuItem.Name = "mailToolStripMenuItem"; + mailToolStripMenuItem.Size = new Size(62, 20); + mailToolStripMenuItem.Text = "Письма"; + mailToolStripMenuItem.Click += mailToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1125, 441); + Controls.Add(ButtonRef); + Controls.Add(ButtonIssuedOrder); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + Name = "FormMain"; + Text = "Установка ПО"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem packageToolStripMenuItem; - private ToolStripMenuItem componentToolStripMenuItem; - private Button ButtonRef; - private Button ButtonIssuedOrder; - private Button buttonCreateOrder; - private DataGridView dataGridView; - private ToolStripMenuItem отчётыToolStripMenuItem; - private ToolStripMenuItem списокКомпонентовToolStripMenuItem; - private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; - private ToolStripMenuItem списокЗаказовToolStripMenuItem; - private ToolStripMenuItem ClientsToolStripMenuItem; - private ToolStripMenuItem DoWorkToolStripMenuItem; - private ToolStripMenuItem ImplementersToolStripMenuItem; - } + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem packageToolStripMenuItem; + private ToolStripMenuItem componentToolStripMenuItem; + private Button ButtonRef; + private Button ButtonIssuedOrder; + private Button buttonCreateOrder; + private DataGridView dataGridView; + private ToolStripMenuItem отчётыToolStripMenuItem; + private ToolStripMenuItem списокКомпонентовToolStripMenuItem; + private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem DoWorkToolStripMenuItem; + private ToolStripMenuItem ImplementersToolStripMenuItem; + private ToolStripMenuItem mailToolStripMenuItem; + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs index 5ad3b4f..0d66992 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs @@ -5,196 +5,205 @@ using SoftwareInstallationBusinessLogic.BusinessLogics; namespace SoftwareInstallationView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].HeaderText = "Номер заказа"; - dataGridView.Columns["PackageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + _workProcess = workProcess; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].HeaderText = "Номер заказа"; + dataGridView.Columns["PackageId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void PackagesToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormPackages)); - if (service is FormPackages form) - { - form.ShowDialog(); - } - } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ComponentsReportToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveComponentsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - private void ComponentPackagesToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPackageComponents)); - if (service is FormReportPackageComponents form) - { - form.ShowDialog(); - } - } - private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void PackagesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPackages)); + if (service is FormPackages form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ComponentsReportToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void ComponentPackagesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportPackageComponents)); + if (service is FormReportPackageComponents form) + { + form.ShowDialog(); + } + } + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } - private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormViewClients)); - if (service is FormViewClients form) - { - form.ShowDialog(); - } - } - private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers)); - if (service is FormViewImplementers form) - { - form.ShowDialog(); - } - } - private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormViewClients)); + if (service is FormViewClients form) + { + form.ShowDialog(); + } + } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers)); + if (service is FormViewImplementers form) + { + form.ShowDialog(); + } + } + private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void mailToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormViewMail)); + if (service is FormViewMail form) + { + form.ShowDialog(); + } + } + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormViewMail.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormViewMail.Designer.cs new file mode 100644 index 0000000..29e9125 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormViewMail.Designer.cs @@ -0,0 +1,62 @@ +namespace SoftwareInstallationView +{ + partial class FormViewMail + { + /// + /// 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() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(803, 450); + dataGridView.TabIndex = 0; + // + // FormViewMail + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormViewMail"; + Text = "Письма"; + Load += FormViewMail_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormViewMail.cs b/SoftwareInstallation/SoftwareInstallationView/FormViewMail.cs new file mode 100644 index 0000000..e037b96 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormViewMail.cs @@ -0,0 +1,50 @@ +using SoftwareInstallationBusinessLogic.MailWorker; +using SoftwareInstallationContracts.BusinessLogicsContracts; +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; + +namespace SoftwareInstallationView +{ + public partial class FormViewMail : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormViewMail(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormViewMail_Load(object sender, EventArgs e) + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка списка писем"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки писем"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormViewMail.resx b/SoftwareInstallation/SoftwareInstallationView/FormViewMail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormViewMail.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/Program.cs b/SoftwareInstallation/SoftwareInstallationView/Program.cs index 3aa15c6..3801b7b 100644 --- a/SoftwareInstallation/SoftwareInstallationView/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationView/Program.cs @@ -1,4 +1,4 @@ -using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; @@ -8,6 +8,10 @@ using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationBusinessLogic.OfficePackage.Implements; using SoftwareInstallationBusinessLogic.OfficePackage; using SoftwareInstallationBusinessLogic; +using SoftwareInstallationBusinessLogic.MailWorker; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationDatabaseImplement; +using SoftwareInstallationView; namespace SoftwareInstallationView { @@ -27,6 +31,27 @@ namespace SoftwareInstallationView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + try + { + var mailSender = _serviceProvider.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); + + // ñîçäàåì òàéìåð + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); + } Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) @@ -41,7 +66,9 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -49,7 +76,8 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddSingleton(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,6 +93,8 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file -- 2.25.1 From 4a8797687707b512eb2fbb13150b2a4dfb174747 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Sun, 23 Apr 2023 03:36:06 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=B5=D0=B7=D1=8C=D1=8F=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SoftwareInstallationBusinessLogic.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj index 7725543..1c92542 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj @@ -8,6 +8,7 @@ + -- 2.25.1 From e7e0729e0e8bdfe7e49d8b5cd1f88e03a3d3a717 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Sun, 23 Apr 2023 17:21:56 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=BB=D1=8E=D0=B1=D0=B8=D0=BC=D1=8B=D0=B5?= =?UTF-8?q?=20=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Home/Mails.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 3 ++ ...ner.cs => 20230423115628_init.Designer.cs} | 43 ++++++++++++++++++- ...3203641_init.cs => 20230423115628_init.cs} | 29 +++++++++++++ ...ftwareInstallationDatabaseModelSnapshot.cs | 41 ++++++++++++++++++ .../OrderStorage.cs | 3 +- .../appsettings.json | 4 +- .../SoftwareInstallationView/App.config | 4 +- 8 files changed, 122 insertions(+), 7 deletions(-) rename SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/{20230403203641_init.Designer.cs => 20230423115628_init.Designer.cs} (85%) rename SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/{20230403203641_init.cs => 20230423115628_init.cs} (85%) diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml index 0446c5d..2c4fc72 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Home/Mails.cshtml @@ -15,7 +15,7 @@ @{ if (Model == null) { -

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

+

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

return; } diff --git a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml index 12fbb2d..a2ec9df 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Views/Shared/_Layout.cshtml @@ -28,6 +28,9 @@ + diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230403203641_init.Designer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230423115628_init.Designer.cs similarity index 85% rename from SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230403203641_init.Designer.cs rename to SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230423115628_init.Designer.cs index 17e0647..ae608ff 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230403203641_init.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230423115628_init.Designer.cs @@ -12,7 +12,7 @@ using SoftwareInstallationDatabaseImplement; namespace SoftwareInstallationDatabaseImplement.Migrations { [DbContext(typeof(SoftwareInstallationDatabase))] - [Migration("20230403203641_init")] + [Migration("20230423115628_init")] partial class init { /// @@ -97,6 +97,36 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -186,6 +216,15 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("PackageComponents"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b => { b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client") @@ -232,6 +271,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230403203641_init.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230423115628_init.cs similarity index 85% rename from SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230403203641_init.cs rename to SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230423115628_init.cs index 2fce27d..7e72138 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230403203641_init.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20230423115628_init.cs @@ -70,6 +70,27 @@ namespace SoftwareInstallationDatabaseImplement.Migrations table.PrimaryKey("PK_Packages", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -134,6 +155,11 @@ namespace SoftwareInstallationDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", @@ -163,6 +189,9 @@ namespace SoftwareInstallationDatabaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Messages"); + migrationBuilder.DropTable( name: "Orders"); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs index d719758..664788a 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs @@ -94,6 +94,36 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -183,6 +213,15 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("PackageComponents"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b => { b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client") @@ -229,6 +268,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs index ef0c0e6..5a52f00 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs @@ -72,7 +72,8 @@ namespace SoftwareInstallationDatabaseImplement.Implements return queryWhere .Include(x => x.Client) .Include(x => x.Implementer) - .Select(x => x.GetViewModel) + .Include(x => x.Package) + .Select(x => x.GetViewModel) .ToList(); } diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json b/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json index 697acfb..96f4ca2 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json +++ b/SoftwareInstallation/SoftwareInstallationRestApi/appsettings.json @@ -11,6 +11,6 @@ "SmtpClientPort": "587", "PopHost": "pop.mail.ru", "PopPort": "995", - "MailLogin": "ordersender228@mail.ru", - "MailPassword": "v8czsQ8zztJc5wEHxKPN" + "MailLogin": "ilox_2018@mail.ru", + "MailPassword": "5Q1HSfrrha0Mg1UAGUZ8" } diff --git a/SoftwareInstallation/SoftwareInstallationView/App.config b/SoftwareInstallation/SoftwareInstallationView/App.config index 400d322..34fa27c 100644 --- a/SoftwareInstallation/SoftwareInstallationView/App.config +++ b/SoftwareInstallation/SoftwareInstallationView/App.config @@ -5,7 +5,7 @@ - - + + \ No newline at end of file -- 2.25.1