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 ResultLogic : IResultLogic { private readonly IResultStorage _ResultStorage; public ResultLogic(IResultStorage ResultStorage) { _ResultStorage = ResultStorage; } public ResultViewModel? ReadElement(ResultSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _ResultStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(ResultSearchModel? model) { var list = model == null ? _ResultStorage.GetFullList() : _ResultStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Create(ResultBindingModel model) { CheckModel(model); if (_ResultStorage.Insert(model) == null) { return false; } return true; } public bool Delete(ResultBindingModel model) { CheckModel(model, false); if (_ResultStorage.Delete(model) == null) { return false; } return true; } public bool Update(ResultBindingModel model) { CheckModel(model); if (_ResultStorage.Update(model) == null) { return false; } return true; } private void CheckModel(ResultBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } } } }