2023-04-21 23:21:49 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SofrwareInstallationContracts.BindingModels;
|
|
|
|
|
using SofrwareInstallationContracts.BusinessLogicsContracts;
|
|
|
|
|
using SofrwareInstallationContracts.SearchModels;
|
|
|
|
|
using SofrwareInstallationContracts.StoragesContracts;
|
|
|
|
|
using SofrwareInstallationContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace SoftwareInstallationBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class MessageInfoLogic : IMessageInfoLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IMessageInfoStorage _messageStorage;
|
|
|
|
|
|
|
|
|
|
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_messageStorage = messageStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Create(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (_messageStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel>? 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;
|
|
|
|
|
}
|
2023-05-03 20:50:36 +04:00
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
var res = _messageStorage.GetElement(model);
|
|
|
|
|
|
|
|
|
|
if (res == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Read element operation failed");
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (_messageStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-04-21 23:21:49 +04:00
|
|
|
|
}
|
|
|
|
|
}
|