94 lines
1.9 KiB
C#
94 lines
1.9 KiB
C#
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 TeamLogic : ITeamLogic
|
|
{
|
|
private readonly ITeamStorage _TeamStorage;
|
|
|
|
public TeamLogic(ITeamStorage TeamStorage)
|
|
{
|
|
_TeamStorage = TeamStorage;
|
|
}
|
|
public TeamViewModel? ReadElement(TeamSearchModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
|
|
var element = _TeamStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public List<TeamViewModel>? ReadList(TeamSearchModel? model)
|
|
{
|
|
var list = model == null ? _TeamStorage.GetFullList() : _TeamStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool Create(TeamBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_TeamStorage.Insert(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(TeamBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_TeamStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Update(TeamBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_TeamStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(TeamBindingModel model, bool withParams = true)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
if (!withParams)
|
|
{
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(model.TeamName))
|
|
{
|
|
throw new ArgumentNullException("Нет названия", nameof(model.TeamName));
|
|
}
|
|
}
|
|
}
|
|
}
|