using BlogContracts.BindingModels; using BlogContracts.BusinessLogicContracts; using BlogContracts.SearchModels; using BlogContracts.StoragesContracts; using BlogContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BlogBusinessLogic { public class MessageLogic : IMessageLogic { private readonly IMessageStorage _messageStorage; public MessageLogic(IMessageStorage messageStorage) { _messageStorage = messageStorage; } public bool Create(MessageBindingModel model) { CheckModel(model); if (_messageStorage.Insert(model) == null) { return false; } return true; } public bool Delete(MessageBindingModel model) { CheckModel(model, false); if (_messageStorage.Delete(model) == null) { return false; } return true; } public MessageViewModel? ReadElement(MessageSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _messageStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(MessageSearchModel? model) { var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public string TestInsertList(int num, List users, List topics) { return _messageStorage.TestInsertList(num, users, topics); } public string TestReadList(int num) { return _messageStorage.TestReadList(num); } public string TestJoinReadList(int num) { return _messageStorage.TestJoinReadList(num); } public bool Update(MessageBindingModel model) { CheckModel(model); if (_messageStorage.Update(model) == null) { return false; } return true; } private void CheckModel(MessageBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } } } }