diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 62272c0..d35e90e 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -58,6 +58,32 @@ namespace AircraftPlantBusinessLogic.BusinessLogics return list; } + /// + /// Получение отдельной записи + /// + /// + /// + /// + public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. MessageId:{Id}", model.MessageId); + + var element = _messageStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. MessageId:{Id}", element.MessageId); + return element; + } + /// /// Создание записи /// diff --git a/AircraftPlant/AircraftPlantBusinessLogic/MailWorker/AbstractMailWorker.cs b/AircraftPlant/AircraftPlantBusinessLogic/MailWorker/AbstractMailWorker.cs index 089b497..41e96ba 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -1,6 +1,7 @@ using AircraftPlantBusinessLogic.BusinessLogics; using AircraftPlantContracts.BindingModels; using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.SearchModels; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -46,22 +47,27 @@ namespace AircraftPlantBusinessLogic.MailWorker /// Порт протокола POP3 /// protected int _popPort; - private object _clientLogic; /// /// Бизнес-логика для писем /// private readonly IMessageInfoLogic _messageInfoLogic; + /// + /// Бизнес-логика для клиентов + /// + private readonly IClientLogic _clientLogic; + /// /// Конструктор /// /// /// - public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) { _logger = logger; _messageInfoLogic = messageInfoLogic; + _clientLogic = clientLogic; } /// @@ -130,6 +136,10 @@ namespace AircraftPlantBusinessLogic.MailWorker foreach (var mail in list) { + mail.ClientId = _clientLogic.ReadElement(new ClientSearchModel + { + Email = mail.SenderName + })?.Id; _messageInfoLogic.Create(mail); } } diff --git a/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IMessageInfoLogic.cs index ae4ed0b..1e96a19 100644 --- a/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IMessageInfoLogic.cs +++ b/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -21,6 +21,13 @@ namespace AircraftPlantContracts.BusinessLogicsContracts /// List? ReadList(MessageInfoSearchModel? model); + /// + /// Получение отдельной записи + /// + /// + /// + MessageInfoViewModel? ReadElement(MessageInfoSearchModel model); + /// /// Создание записи /// diff --git a/AircraftPlant/AircraftPlantFileImplement/Implements/MessageInfoStorage.cs b/AircraftPlant/AircraftPlantFileImplement/Implements/MessageInfoStorage.cs index a6a2470..000242f 100644 --- a/AircraftPlant/AircraftPlantFileImplement/Implements/MessageInfoStorage.cs +++ b/AircraftPlant/AircraftPlantFileImplement/Implements/MessageInfoStorage.cs @@ -1,5 +1,6 @@ using AircraftPlantContracts.BindingModels; using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.StoragesContracts; using AircraftPlantContracts.ViewModels; using AircraftPlantFileImplement.Models; using System; @@ -13,7 +14,7 @@ namespace AircraftPlantFileImplement.Implements /// /// Реализация интерфейса хранилища для писем /// - public class MessageInfoStorage + public class MessageInfoStorage : IMessageInfoStorage { /// /// Хранилище