2024-05-05 13:34:40 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SecuritySystemContracts.BindingModels;
|
2024-05-05 13:28:33 +04:00
|
|
|
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
|
|
|
|
using SecuritySystemContracts.SearchModels;
|
2024-05-05 13:34:40 +04:00
|
|
|
|
using SecuritySystemContracts.StoragesContracts;
|
2024-05-05 13:28:33 +04:00
|
|
|
|
using SecuritySystemContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace SecuritySystemBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class MessageInfoLogic : IMessageInfoLogic
|
|
|
|
|
{
|
2024-05-05 13:34:40 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IMessageInfoStorage _messageInfoStorage;
|
|
|
|
|
public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_messageInfoStorage = messageInfoStorage;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 13:28:33 +04:00
|
|
|
|
public bool Create(MessageInfoBindingModel model)
|
|
|
|
|
{
|
2024-05-05 13:34:40 +04:00
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_messageInfoStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-05-05 13:28:33 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
|
|
|
|
{
|
2024-05-05 13:34:40 +04:00
|
|
|
|
_logger.LogInformation("ReadList. MessageId:{Id}", model?.MessageId);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckModel(MessageInfoBindingModel model, bool withParams = true)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
if (!withParams)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(model.MessageId))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет идентификатора письма", nameof(model.MessageId));
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("MessageInfo. MessageId: {MessageId}", model.MessageId);
|
|
|
|
|
var element = _messageInfoStorage.GetElement(new MessageInfoSearchModel
|
|
|
|
|
{
|
|
|
|
|
MessageId = model.MessageId
|
|
|
|
|
});
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Пиьсмо с таким идентификатором уже есть");
|
|
|
|
|
}
|
2024-05-05 13:28:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|