using SportCompetitionsContracts.BindingModels; using SportCompetitionsContracts.BusinessLogicsContracts; using SportCompetitionsContracts.SearchModels; using SportCompetitionsContracts.StoragesContracts; using SportCompetitionsContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SportCompetitionsBusinessLogic.BusinessLogics { public class RecordLogic : IRecordLogic { private readonly IRecordStorage _RecordStorage; public RecordLogic(IRecordStorage RecordStorage) { _RecordStorage = RecordStorage; } public RecordViewModel? ReadElement(RecordSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _RecordStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(RecordSearchModel? model) { var list = model == null ? _RecordStorage.GetFullList() : _RecordStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Create(RecordBindingModel model) { CheckModel(model); if (_RecordStorage.Insert(model) == null) { return false; } return true; } public bool Delete(RecordBindingModel model) { CheckModel(model, false); if (_RecordStorage.Delete(model) == null) { return false; } return true; } public bool Update(RecordBindingModel model) { CheckModel(model); if (_RecordStorage.Update(model) == null) { return false; } return true; } private void CheckModel(RecordBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty(model.RecordName)) { throw new ArgumentNullException("Нет названия", nameof(model.RecordName)); } } } }