102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UchetLabContracts.BindingModels;
|
|
using UchetLabContracts.BusinessLogicsContracts;
|
|
using UchetLabContracts.SearchModels;
|
|
using UchetLabContracts.StorageContracts;
|
|
using UchetLabContracts.ViewModels;
|
|
|
|
namespace UchetLabBusinessLogic.BusinessLogic
|
|
{
|
|
public class LabLogic : ILabLogic
|
|
{
|
|
ILabStorage _labStorage;
|
|
|
|
public LabLogic(ILabStorage labStorage)
|
|
{
|
|
_labStorage = labStorage;
|
|
}
|
|
|
|
public bool Create(LabBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_labStorage.Insert(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(LabBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_labStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public LabViewModel? ReadElement(LabSearchModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
var element = _labStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public List<LabViewModel>? ReadList(LabSearchModel? model)
|
|
{
|
|
var list = model == null ? _labStorage.GetFullList() : _labStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool Update(LabBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_labStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(LabBindingModel model, bool withParams = true)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
if (!withParams)
|
|
{
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(model.LabTask))
|
|
{
|
|
throw new ArgumentNullException("Нет задания лабораторной", nameof(model.LabTask));
|
|
}
|
|
if (string.IsNullOrEmpty(model.Checker))
|
|
{
|
|
throw new ArgumentNullException("Нет проверяющего лабораторной", nameof(model.Checker));
|
|
}
|
|
if (string.IsNullOrEmpty(model.TaskImage))
|
|
{
|
|
throw new ArgumentNullException("Нет картинки для лабораторной", nameof(model.TaskImage));
|
|
}
|
|
}
|
|
}
|
|
}
|