ой забыла email и password надо добавить(

This commit is contained in:
EkaterinaR 2024-11-03 11:19:43 +04:00
parent c219f9da5d
commit 9148fdd11c
9 changed files with 353 additions and 0 deletions

View File

@ -16,6 +16,8 @@ namespace EventVisitorLogic.BindingModels
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public Dictionary<int, IEventModel> OrganizerEvent
{

View File

@ -0,0 +1,128 @@
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 EventLogic : IEventLogic
{
private readonly IEventStorage _eventStorage;
public EventLogic(IEventStorage eventStorage)
{
_eventStorage = eventStorage;
}
public bool Create(EventBindingModel model)
{
CheckModel(model);
var result = _eventStorage.Insert(model);
if (result == null)
{
return false;
}
return true;
}
public bool Delete(EventBindingModel model)
{
CheckModel(model, false);
if (_eventStorage.Delete(model) == null)
{
return false;
}
return true;
}
public EventViewModel? ReadElement(EventBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _eventStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<EventViewModel>? ReadList(EventBindingModel? model)
{
//var list = model == null ? _eventStorage.GetFullList() : _eventStorage.GetFilteredList(model);
var list = _eventStorage.GetFullList();
if (list == null)
{
return null;
}
return list;
}
public bool Update(EventBindingModel model)
{
CheckModel(model);
if (_eventStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(EventBindingModel 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.Type))
{
throw new ArgumentNullException("Нет типа мероприятия", nameof(model.Type));
}
if (string.IsNullOrEmpty(model.ContactPhone))
{
throw new ArgumentNullException("Нет контактного телефона", nameof(model.ContactPhone));
}
if (string.IsNullOrEmpty(model.Address))
{
throw new ArgumentNullException("Нет адреса мероприятия", nameof(model.Address));
}
if (string.IsNullOrEmpty(model.City))
{
throw new ArgumentNullException("Нет города", nameof(model.City));
}
if (string.IsNullOrEmpty(model.Status))
{
throw new ArgumentNullException("Нет статуса меропрития", nameof(model.Status));
}
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));
}
}
}
}

View File

@ -0,0 +1,19 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.Logic
{
public interface IEventLogic
{
List<EventViewModel>? ReadList(EventBindingModel? model);
EventViewModel? ReadElement(EventBindingModel model);
bool Create(EventBindingModel model);
bool Update(EventBindingModel model);
bool Delete(EventBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.Logic
{
public interface IOrganizerLogic
{
List<OrganizerViewModel>? ReadList(OrganizerBindingModel? model);
OrganizerViewModel? ReadElement(OrganizerBindingModel model);
bool Create(OrganizerBindingModel model);
bool Update(OrganizerBindingModel model);
bool Delete(OrganizerBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.Logic
{
public interface IVisitorLogic
{
List<VisitorViewModel>? ReadList(VisitorBindingModel? model);
VisitorViewModel? ReadElement(VisitorBindingModel model);
bool Create(VisitorBindingModel model);
bool Update(VisitorBindingModel model);
bool Delete(VisitorBindingModel model);
}
}

View File

@ -0,0 +1,124 @@
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));
}
}
}
}

View File

@ -0,0 +1,38 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.Logic
{
public class VisitorLogic : IVisitorLogic
{
public bool Create(VisitorBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(VisitorBindingModel model)
{
throw new NotImplementedException();
}
public VisitorViewModel? ReadElement(VisitorBindingModel model)
{
throw new NotImplementedException();
}
public List<VisitorViewModel>? ReadList(VisitorBindingModel? model)
{
throw new NotImplementedException();
}
public bool Update(VisitorBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -16,5 +16,7 @@ namespace EventVisitorLogic.ViewModels
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}

View File

@ -15,5 +15,7 @@ namespace EventVisitorModels
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}