88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
|
using StudentPerformanceContracts.BindingModels;
|
|||
|
using StudentPerformanceContracts.BusinessLogicContracts;
|
|||
|
using StudentPerformanceContracts.SearchModels;
|
|||
|
using StudentPerformanceContracts.StorageContracts;
|
|||
|
using StudentPerformanceContracts.ViewModels;
|
|||
|
|
|||
|
namespace StudentPerformanceBusinessLogic.BusinessLogics
|
|||
|
{
|
|||
|
public class FormatLogic : IFormatLogic
|
|||
|
{
|
|||
|
private readonly IFormatStorage _formatStorage;
|
|||
|
|
|||
|
public FormatLogic(IFormatStorage formatStorage)
|
|||
|
{
|
|||
|
_formatStorage = formatStorage;
|
|||
|
}
|
|||
|
|
|||
|
public List<FormatViewModel>? ReadList(FormatSearchModel? model)
|
|||
|
{
|
|||
|
var list = model == null ? _formatStorage.GetFullList() : _formatStorage.GetFilteredList(model);
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public FormatViewModel? ReadElement(FormatSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
var element = _formatStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(FormatBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_formatStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(FormatBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_formatStorage.Update(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
public bool Delete(FormatBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
if (_formatStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(FormatBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Name))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Нет наименования формата обучения", nameof(model.Name));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|