using AircraftPlantContracts.BindingModels; using AircraftPlantContracts.BusinessLogicsContracts; using AircraftPlantContracts.SearchModels; using AircraftPlantContracts.StoragesContracts; using AircraftPlantContracts.ViewModels; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AircraftPlantBusinessLogic.BusinessLogics { /// /// Реализация интерфейса бизнес-логики для писем /// public class MessageInfoLogic : IMessageInfoLogic { /// /// Логгер /// private readonly ILogger _logger; /// /// Взаимодействие с хранилищем писем /// private readonly IMessageInfoStorage _messageStorage; /// /// Конструктор /// /// /// public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageStorage) { _logger = logger; _messageStorage = messageStorage; } /// /// Получение списка /// /// /// public List? ReadList(MessageInfoSearchModel? model) { _logger.LogInformation("ReadList. MessageId: {MessageId}. ClientId: {ClientId}", model?.MessageId, model?.ClientId); var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } _logger.LogInformation("ReadList. Count: {Count}", list.Count); 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; } /// /// Создание записи /// /// /// public bool Create(MessageInfoBindingModel model) { if (model == null) { return false; } if (_messageStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; } return true; } /// /// Изменение записи /// /// /// public bool Update(MessageInfoBindingModel model) { if (model == null) { return false; } if (_messageStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; } return true; } } }