76 lines
2.5 KiB
C#
76 lines
2.5 KiB
C#
using AbstractShopContracts.StoragesContracts;
|
|
using AutomobilePlantContracts.BindingModels;
|
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
|
using AutomobilePlantContracts.SearchModel;
|
|
using AutomobilePlantContracts.StoragesContracts;
|
|
using AutomobilePlantContracts.ViewModel;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
|
{
|
|
public class MessageLogic : IMessageInfoLogic
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IMessageInfoStorage _messageStorage;
|
|
public MessageLogic(ILogger<CarLogic> logger, IMessageInfoStorage messageStorage)
|
|
{
|
|
_logger = logger;
|
|
_messageStorage = messageStorage;
|
|
}
|
|
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
|
{
|
|
_logger.LogInformation("ReadList");
|
|
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)
|
|
{
|
|
CheckModel(model);
|
|
if (_messageStorage.Insert(model) == null)
|
|
{
|
|
_logger.LogWarning("Insert operation failed");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
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));
|
|
}
|
|
if (string.IsNullOrEmpty(model.Body))
|
|
{
|
|
throw new ArgumentNullException("Нет тела письма", nameof(model.Body));
|
|
}
|
|
if (string.IsNullOrEmpty(model.SenderName))
|
|
{
|
|
throw new ArgumentNullException("Нет отправителя письма", nameof(model.SenderName));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|