CourseWork_EventVisitor/EventVisitor/EventVisitorLogic/Logic/OrganizerLogic.cs

113 lines
3.4 KiB
C#
Raw Normal View History

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));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля", nameof(model.Password));
}
}
}
}