PIbd-21_Bakalskaya_E.D._Sus.../SushiBarBusinessLogic/MessageInfoLogic.cs

43 lines
1.4 KiB
C#

using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModel;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModel;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic
{
public class MessageInfoLogic : IMessageInfoLogic
{
private readonly ILogger logger;
private readonly IMessageInfoStorage messageStorage;
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage)
{
this.logger = logger;
this.messageStorage = messageStorage;
}
public bool Create(MessageInfoBindingModel model)
{
if(messageStorage.Insert(model) == null)
{
logger.LogWarning("Insert message operation failed");
}
return true;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{
var list = model == null ? messageStorage.GetFullList() : messageStorage.GetFilteredList(model);
if(list == null)
{
logger.LogWarning("ReadList had returned a null list");
return null;
}
logger.LogInformation($"ReadList. Count of elements: {list.Count}");
return list;
}
}
}