54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
using ConfectioneryContracts.BindingModels;
|
|
using ConfectioneryContracts.SearchModels;
|
|
using ConfectioneryContracts.StoragesContracts;
|
|
using ConfectioneryContracts.ViewModels;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConfectioneryBusinessLogic.BusinessLogics
|
|
{
|
|
public class MessageInfoLogic : IMessageInfoLogic
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IMessageInfoStorage _messageStorage;
|
|
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage)
|
|
{
|
|
_logger = logger;
|
|
_messageStorage = messageStorage;
|
|
}
|
|
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;
|
|
}
|
|
public bool Create(MessageInfoBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (_messageStorage.Insert(model) == null)
|
|
{
|
|
_logger.LogWarning("Insert operation failed");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|