89 lines
2.5 KiB
C#
89 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 StudentLogic : IStudentLogic
|
|
{
|
|
private readonly IStudentStorage _studentStorage;
|
|
|
|
public StudentLogic(IStudentStorage studentStorage)
|
|
{
|
|
_studentStorage = studentStorage;
|
|
}
|
|
|
|
public List<StudentViewModel>? ReadList(StudentSearchModel? model)
|
|
{
|
|
var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public StudentViewModel? ReadElement(StudentSearchModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
var element = _studentStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public bool Create(StudentBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_studentStorage.Insert(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Update(StudentBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_studentStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(StudentBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_studentStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(StudentBindingModel model, bool withParams = true)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
if (!withParams)
|
|
{
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(model.Fullname))
|
|
{
|
|
throw new ArgumentNullException("Нет ФИО студента", nameof(model.Fullname));
|
|
}
|
|
}
|
|
}
|
|
}
|