From d90a87c05f41637940f61ebefd9eecb05cb3d878 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 30 Apr 2023 19:20:30 +0400 Subject: [PATCH] MessageInfoLogic added --- .../BusinessLogics/MessageInfoLogic.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/MessageInfoLogic.cs diff --git a/JewelryStoreBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/MessageInfoLogic.cs new file mode 100644 index 0000000..0faa027 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -0,0 +1,56 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _messageStorage; + + public MessageInfoLogic(ILogger 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? 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; + } + } +} +}