125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using EventVisitorLogic.BindingModels;
|
|
using EventVisitorLogic.StoragesContracts;
|
|
using EventVisitorLogic.ViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EventVisitorLogic.Logic
|
|
{
|
|
public class OrganizerLogic : IOrganizerLogic
|
|
{
|
|
private readonly IOrganizerStorage _organizerStorage;
|
|
public OrganizerLogic(IOrganizerStorage organizerStorage)
|
|
{
|
|
_organizerStorage = organizerStorage;
|
|
}
|
|
public bool Create(OrganizerBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
var result = _organizerStorage.Insert(model);
|
|
|
|
if (result == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(OrganizerBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_organizerStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public OrganizerViewModel? ReadElement(OrganizerBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
var element = _organizerStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public List<OrganizerViewModel>? ReadList(OrganizerBindingModel? model)
|
|
{
|
|
//var list = model == null ? _organizerStorage.GetFullList() : _organizerStorage.GetFilteredList(model);
|
|
var list = _organizerStorage.GetFullList();
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool Update(OrganizerBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_organizerStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(OrganizerBindingModel 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));
|
|
}
|
|
if (string.IsNullOrEmpty(model.Surname))
|
|
{
|
|
throw new ArgumentNullException("Нет фамилии", nameof(model.Surname));
|
|
}
|
|
if (string.IsNullOrEmpty(model.OrganizationName))
|
|
{
|
|
throw new ArgumentNullException("Нет названия компании", nameof(model.OrganizationName));
|
|
}
|
|
if (string.IsNullOrEmpty(model.Role))
|
|
{
|
|
throw new ArgumentNullException("Нет адреса мероприятия", nameof(model.Role));
|
|
}
|
|
if (string.IsNullOrEmpty(model.Phone))
|
|
{
|
|
throw new ArgumentNullException("Нет телефона", nameof(model.Phone));
|
|
}
|
|
if (model.CountVisitors < 0)
|
|
{
|
|
throw new ArgumentNullException("Некорректный количество посетителей, nameof(model.CountVisitors)");
|
|
}
|
|
if (model.Date <= DateTime.Now.AddHours(2))
|
|
{
|
|
throw new ArgumentNullException("Нельзя выбрать дату меньше сегодняшней", nameof(model.Date));
|
|
}
|
|
if (model.TimeStart <= DateTime.Now.AddHours(2))
|
|
{
|
|
throw new ArgumentNullException("Нельзя выбрать время меньше, чем через 2 часа от текущего", nameof(model.Date));
|
|
}
|
|
if (model.TimeEnd <= DateTime.Now)
|
|
{
|
|
throw new ArgumentNullException("Нельзя выбрать время меньше, чем через 2 часа от текущего", nameof(model.Date));
|
|
}
|
|
}
|
|
}
|
|
}
|