2024-11-03 11:19:43 +04:00
|
|
|
|
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.Phone))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет телефона", nameof(model.Phone));
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
if (string.IsNullOrEmpty(model.Email))
|
2024-11-03 11:19:43 +04:00
|
|
|
|
{
|
2024-11-03 19:42:19 +04:00
|
|
|
|
throw new ArgumentNullException("Нет почты", nameof(model.Email));
|
2024-11-03 11:19:43 +04:00
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
if (string.IsNullOrEmpty(model.Password))
|
2024-11-03 11:19:43 +04:00
|
|
|
|
{
|
2024-11-03 19:42:19 +04:00
|
|
|
|
throw new ArgumentNullException("Нет пароля", nameof(model.Password));
|
2024-11-03 11:19:43 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|