From b8963972a22f5df07d6d910f97648c46c6b94406 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sat, 3 Jun 2023 00:16:54 +0400 Subject: [PATCH] needs debug --- .../Controllers/HomeController.cs | 11 + .../Views/Home/Mails.cshtml | 54 ++++ .../Views/Shared/_Layout.cshtml | 15 +- ...ctSoftwareInstallationBusinessLogic.csproj | 1 + .../BusinessLogic/ClientLogic.cs | 13 + .../BusinessLogic/MessageInfoLogic.cs | 48 +++ .../BusinessLogic/OrderLogic.cs | 34 +- .../MailWorker/AbstractMailWorker.cs | 82 +++++ .../MailWorker/MailKitWorker.cs | 79 +++++ .../BindingModels/MailConfigBindingModel.cs | 18 ++ .../BindingModels/MailSendInfoBindingModel.cs | 15 + .../BindingModels/MessageInfoBindingModel.cs | 24 ++ .../IMessageInfoLogic.cs | 17 + .../SearchModels/MessageInfoSearchModel.cs | 14 + .../StoragesContracts/IMessageInfoStorage.cs | 19 ++ .../ViewModels/MessageInfoViewModel.cs | 25 ++ .../Models/IMessageInfoModel.cs | 18 ++ .../AbstractSoftwareInstallationDatabase.cs | 1 + .../Implements/MessageInfoStorage.cs | 56 ++++ .../20230602161333_mail.Designer.cs | 296 ++++++++++++++++++ .../Migrations/20230602161333_mail.cs | 89 ++++++ ...ftwareInstallationDatabaseModelSnapshot.cs | 45 ++- .../Models/Client.cs | 3 +- .../Models/MessageInfo.cs | 57 ++++ .../DataFileSingleton.cs | 6 +- .../Implements/MessageInfoStorage.cs | 58 ++++ .../Models/MessageInfo.cs | 79 +++++ .../DataListSingleton.cs | 3 + .../Implements/MessageInfoStorage.cs | 65 ++++ .../Models/MessageInfo.cs | 53 ++++ .../Controllers/ClientController.cs | 22 +- .../Program.cs | 13 + .../appsettings.json | 12 +- .../SoftwareInstallation/App.config | 11 + .../FormMails.Designer.cs | 62 ++++ .../SoftwareInstallation/FormMails.cs | 49 +++ .../SoftwareInstallation/FormMails.resx | 120 +++++++ .../SoftwareInstallation/FormMain.Designer.cs | 20 +- .../SoftwareInstallation/FormMain.cs | 8 + .../SoftwareInstallation/Program.cs | 3 + .../SoftwareInstallationView.csproj | 33 ++ .../SoftwareInstallation/log4net.config | 16 + 42 files changed, 1641 insertions(+), 26 deletions(-) create mode 100644 SoftwareInstallation/AbstractShowClientApp/Views/Home/Mails.cshtml create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IMessageInfoModel.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.Designer.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/MessageInfo.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/MessageInfo.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationListImplement/Implements/MessageInfoStorage.cs create mode 100644 SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/MessageInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/App.config create mode 100644 SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormMails.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormMails.resx create mode 100644 SoftwareInstallation/SoftwareInstallation/log4net.config diff --git a/SoftwareInstallation/AbstractShowClientApp/Controllers/HomeController.cs b/SoftwareInstallation/AbstractShowClientApp/Controllers/HomeController.cs index f698af2..b9c5c76 100644 --- a/SoftwareInstallation/AbstractShowClientApp/Controllers/HomeController.cs +++ b/SoftwareInstallation/AbstractShowClientApp/Controllers/HomeController.cs @@ -144,5 +144,16 @@ namespace AbstractShowClientApp.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/AbstractShowClientApp/Views/Home/Mails.cshtml b/SoftwareInstallation/AbstractShowClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..5b1fc17 --- /dev/null +++ b/SoftwareInstallation/AbstractShowClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using AbstractSoftwareInstallationContracts.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) +
+ } +
\ No newline at end of file diff --git a/SoftwareInstallation/AbstractShowClientApp/Views/Shared/_Layout.cshtml b/SoftwareInstallation/AbstractShowClientApp/Views/Shared/_Layout.cshtml index 21896a8..d05a852 100644 --- a/SoftwareInstallation/AbstractShowClientApp/Views/Shared/_Layout.cshtml +++ b/SoftwareInstallation/AbstractShowClientApp/Views/Shared/_Layout.cshtml @@ -20,16 +20,19 @@ diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/AbstractSoftwareInstallationBusinessLogic.csproj b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/AbstractSoftwareInstallationBusinessLogic.csproj index af7613e..3d3a6d0 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/AbstractSoftwareInstallationBusinessLogic.csproj +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/AbstractSoftwareInstallationBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs index 55d329d..9c15975 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ClientLogic.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic @@ -47,6 +48,10 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic _logger.LogWarning("ReadElement element not found"); return null; } + if (!string.IsNullOrEmpty(model.Password) && element.Password != model.Password) + { + return null; + } _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } @@ -118,6 +123,14 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic { throw new InvalidOperationException("Такой клиент уже есть"); } + if (!Regex.IsMatch(model.Email, @"^[\w\.]{1,30}@{1}[^\d\W]+\.{1}[^\d\W]{2,4}$")) + { + throw new ArgumentException("Неверно введен адрес электронной почты", nameof(model.Email)); + } + if (!Regex.IsMatch(model.Password, @"^[^\s:""]{8,20}$")) + { + throw new ArgumentException("Неверно введен пароль", nameof(model.Password)); + } } } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs new file mode 100644 index 0000000..fcbd1a7 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/MessageInfoLogic.cs @@ -0,0 +1,48 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic +{ + 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/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs index d57d200..e91b1a7 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,6 +5,7 @@ using AbstractSoftwareInstallationContracts.ViewModels; using AbstractSoftwareInstallationContracts.StoragesContracts; using Microsoft.Extensions.Logging; using AbstractSoftwareInstallationDataModels; +using AbstractSoftwareInstallationBusinessLogic.MailWorker; namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic { @@ -12,10 +13,31 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage OrderStorage) + private readonly IClientLogic _clientLogic; + private readonly AbstractMailWorker _mailWorker; + public OrderLogic(ILogger logger, IOrderStorage OrderStorage, IClientLogic clientLogic, AbstractMailWorker mailWorker) { _logger = logger; _orderStorage = OrderStorage; + _clientLogic = clientLogic; + _mailWorker = mailWorker; + } + public void SendOrderStatusMail(int clientId, string subject, string text) + { + var client = _clientLogic.ReadElement(new ClientSearchModel + { + Id = clientId + }); + if (client == null) + { + throw new ArgumentNullException($"Клиент с Id:{clientId} не найден."); + } + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = client.Email, + Subject = subject, + Text = text + }); } private void CheckModel(OrderBindingModel model, bool withParams = true) { @@ -63,17 +85,19 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic { CheckModel(model); if (model.Status != OrderStatus.Неизвестен) - { - _logger.LogWarning("Order status is incorrect"); + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); return false; } model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + var result = _orderStorage.Insert(model); + if (result == null) { model.Status = OrderStatus.Неизвестен; - _logger.LogWarning("Failed to insert order into a storage"); + _logger.LogWarning("Insert operation failed"); return false; } + SendOrderStatusMail(result.ClientId, $"Новый заказ создан. Номер заказа #{result.Id}", $"Заказ #{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); return true; } public bool StatusUpdate(OrderBindingModel rawModel, OrderStatus _newStatus) diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..32d953d --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,82 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationBusinessLogic.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/AbstractSoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..0ea5148 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,79 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Mail; +using System.Text; +using System.Threading.Tasks; +using MailKit.Net.Pop3; +using MailKit.Security; + +namespace AbstractSoftwareInstallationBusinessLogic.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 (MailKit.Security.AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + return list; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..d26bb83 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..4dbdd96 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..e8fe101 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,24 @@ +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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 DateTime DateDelivery { get; set; } + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..716dc18 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,17 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + bool Create(MessageInfoBindingModel model); + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..cab8dcf --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public int? ClientId { get; set; } + public string? MessageId { get; set; } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..fc8bcca --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,19 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + List GetFilteredList(MessageInfoSearchModel model); + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..8a3fa1c --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,25 @@ +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..6bed1da --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + int? ClientId { get; } + string SenderName { get; } + DateTime DateDelivery { get; } + string Subject { get; } + string Body { get; } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs index 7eec09b..9ed02cb 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs @@ -26,5 +26,6 @@ optionsBuilder) public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } + public virtual DbSet Messages { set; get; } } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..13e63b1 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,56 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + 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 AbstractSoftwareInstallationDatabase(); + return context.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + 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/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.Designer.cs new file mode 100644 index 0000000..6fab46a --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.Designer.cs @@ -0,0 +1,296 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230602161333_mail")] + partial class mail + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.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("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.cs new file mode 100644 index 0000000..ab2b76e --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230602161333_mail.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class mail : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + 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.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Messages"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs index 51e1636..30daaa9 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs @@ -42,7 +42,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); - b.Property("ImplementerId") + b.Property("ImplementerId") .HasColumnType("int"); b.Property("PackageId") @@ -117,6 +117,36 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.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("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => { b.Property("Id") @@ -193,9 +223,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") .WithMany("Orders") - .HasForeignKey("ImplementerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("ImplementerId"); b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") .WithMany("Orders") @@ -210,6 +238,15 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.Navigation("Package"); }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => { b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs index f53311f..4c16ba1 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Client.cs @@ -23,7 +23,8 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Models public string Password { get; private set; } = string.Empty; [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/AbstractSoftwareInstallationDatabaseImplement/Models/MessageInfo.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..5954ebb --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/MessageInfo.cs @@ -0,0 +1,57 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + 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 virtual 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/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs index 47b0ed3..b9e295e 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs @@ -12,11 +12,13 @@ namespace AbstractSoftwareInstallationFileImplement private readonly string PackageFileName = "Package.xml"; private readonly string ClientFileName = "Package.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageFileName = "Message.xml"; public List Softwares { get; private set; } public List Orders { get; private set; } public List Packages { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List Messages { get; private set; } public static DataFileSingleton GetInstance() { @@ -31,7 +33,7 @@ namespace AbstractSoftwareInstallationFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); - + public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { @@ -40,7 +42,7 @@ namespace AbstractSoftwareInstallationFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; - + Messages = LoadData(MessageFileName, "Message", x => MessageInfo.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..c858676 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,58 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationFileImplement.Implements +{ + 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/AbstractSoftwareInstallationFileImplement/Models/MessageInfo.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..5106710 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/MessageInfo.cs @@ -0,0 +1,79 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractSoftwareInstallationFileImplement.Models +{ + public class MessageInfo + { + 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/AbstractSoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs index 672d974..a1948c7 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs @@ -16,6 +16,8 @@ namespace AbstractSoftwareInstallationListImplement public List Packages { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } + private DataListSingleton() { Softwares = new List(); @@ -23,6 +25,7 @@ namespace AbstractSoftwareInstallationListImplement Packages = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() { diff --git a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..4380b51 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,65 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationListImplement.Implements +{ + 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/AbstractSoftwareInstallationListImplement/Models/MessageInfo.cs b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..a201683 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/MessageInfo.cs @@ -0,0 +1,53 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationListImplement.Models +{ + public class MessageInfo + { + 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/AbstractSoftwareInstallationRestApi/Controllers/ClientController.cs b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Controllers/ClientController.cs index 4f24074..a9e26fc 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Controllers/ClientController.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Controllers/ClientController.cs @@ -14,10 +14,13 @@ namespace AbstractSoftwareInstallationRestApi.Controllers private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + + public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger logger) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } [HttpGet] @@ -65,5 +68,22 @@ namespace AbstractSoftwareInstallationRestApi.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/AbstractSoftwareInstallationRestApi/Program.cs b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Program.cs index 406048d..bb260a3 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Program.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Program.cs @@ -1,4 +1,6 @@ using AbstractSoftwareInstallationBusinessLogic.BusinessLogic; +using AbstractSoftwareInstallationBusinessLogic.MailWorker; +using AbstractSoftwareInstallationContracts.BindingModels; using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; using AbstractSoftwareInstallationContracts.StoragesContracts; using AbstractSoftwareInstallationDatabaseImplement.Implements; @@ -30,6 +32,17 @@ 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/AbstractSoftwareInstallationRestApi/appsettings.json b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/appsettings.json index 10f68b8..6169650 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationRestApi/appsettings.json +++ b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/appsettings.json @@ -5,5 +5,13 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "doodlydoolka@gmail.com", + "MailPassword": "doodlydoo07" + +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/App.config b/SoftwareInstallation/SoftwareInstallation/App.config new file mode 100644 index 0000000..c8f56ed --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs new file mode 100644 index 0000000..38cc80a --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.Designer.cs @@ -0,0 +1,62 @@ +namespace SoftwareInstallationView +{ + partial class FormMails + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(776, 426); + dataGridView.TabIndex = 0; + // + // FormMails + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "Письма"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.cs new file mode 100644 index 0000000..978fe36 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.cs @@ -0,0 +1,49 @@ +using AbstractSoftwareInstallationContracts.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 FormMails : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormMails(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormMails_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/SoftwareInstallation/FormMails.resx b/SoftwareInstallation/SoftwareInstallation/FormMails.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index b96ddbc..2e69222 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -45,6 +45,7 @@ namespace SoftwareInstallationView this.packageSoftwaresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.startWorksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -107,7 +108,8 @@ namespace SoftwareInstallationView this.packageToolStripMenuItem2, this.storageToolStripMenuItem3, this.clientToolStripMenuItem, - this.implementerToolStripMenuItem}); + this.implementerToolStripMenuItem, + this.письмаToolStripMenuItem}); this.guideToolStripMenuItem.Name = "guideToolStripMenuItem"; this.guideToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.guideToolStripMenuItem.Text = "Справочники"; @@ -115,28 +117,28 @@ namespace SoftwareInstallationView // packageToolStripMenuItem2 // this.packageToolStripMenuItem2.Name = "packageToolStripMenuItem2"; - this.packageToolStripMenuItem2.Size = new System.Drawing.Size(148, 22); + this.packageToolStripMenuItem2.Size = new System.Drawing.Size(180, 22); this.packageToolStripMenuItem2.Text = "Пакеты"; this.packageToolStripMenuItem2.Click += new System.EventHandler(this.packageToolStripMenuItem_Click); // // storageToolStripMenuItem3 // this.storageToolStripMenuItem3.Name = "storageToolStripMenuItem3"; - this.storageToolStripMenuItem3.Size = new System.Drawing.Size(148, 22); + this.storageToolStripMenuItem3.Size = new System.Drawing.Size(180, 22); this.storageToolStripMenuItem3.Text = "ПО"; this.storageToolStripMenuItem3.Click += new System.EventHandler(this.softwareToolStripMenuItem_Click); // // clientToolStripMenuItem // this.clientToolStripMenuItem.Name = "clientToolStripMenuItem"; - this.clientToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.clientToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.clientToolStripMenuItem.Text = "Клиенты"; this.clientToolStripMenuItem.Click += new System.EventHandler(this.clientToolStripMenuItem_Click); // // implementerToolStripMenuItem // this.implementerToolStripMenuItem.Name = "implementerToolStripMenuItem"; - this.implementerToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.implementerToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.implementerToolStripMenuItem.Text = "Исполнитель"; this.implementerToolStripMenuItem.Click += new System.EventHandler(this.implementerToolStripMenuItem_Click); // @@ -178,6 +180,13 @@ namespace SoftwareInstallationView this.startWorksToolStripMenuItem.Text = "Запуск работ"; this.startWorksToolStripMenuItem.Click += new System.EventHandler(this.startWorksToolStripMenuItem_Click); // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.mailsToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -217,5 +226,6 @@ namespace SoftwareInstallationView private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem implementerToolStripMenuItem; private ToolStripMenuItem startWorksToolStripMenuItem; + private ToolStripMenuItem письмаToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index d055cfb..a99e154 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -152,6 +152,14 @@ namespace SoftwareInstallationView form.ShowDialog(); } } + private void mailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if (service is FormMails form) + { + form.ShowDialog(); + } + } private void implementerToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); diff --git a/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index 24c771b..1a2b1aa 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -35,12 +35,14 @@ namespace SoftwareInstallation option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -53,6 +55,7 @@ namespace SoftwareInstallation services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj b/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj index cf45fac..5785940 100644 --- a/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj +++ b/SoftwareInstallation/SoftwareInstallation/SoftwareInstallationView.csproj @@ -9,6 +9,20 @@ + + + + + + PreserveNewest + true + PreserveNewest + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -26,4 +40,23 @@ + + + TextTemplatingFileGenerator + App.cs + + + + + + + + + + True + True + App.tt + + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/log4net.config b/SoftwareInstallation/SoftwareInstallation/log4net.config new file mode 100644 index 0000000..25986a1 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file