2024-11-03 19:42:19 +04:00
|
|
|
|
using EventVisitorLogic.BindingModels;
|
|
|
|
|
using EventVisitorLogic.Logic;
|
|
|
|
|
using EventVisitorLogic.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace EventVisitorRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class MainController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly IOrganizerLogic _organizer;
|
|
|
|
|
private readonly IEventLogic _event;
|
|
|
|
|
private readonly IVisitorLogic _visitor;
|
2024-11-17 00:04:09 +04:00
|
|
|
|
private readonly ISentMessageLogic _message;
|
2024-11-06 03:05:29 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-17 00:04:09 +04:00
|
|
|
|
public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor, AbstractMailWorker mailWorker, IReportLogic reportLogic, ISentMessageLogic message)
|
2024-11-03 19:42:19 +04:00
|
|
|
|
{
|
|
|
|
|
_organizer = organizer;
|
|
|
|
|
_event = events;
|
|
|
|
|
_visitor = visitor;
|
2024-11-06 03:05:29 +04:00
|
|
|
|
_mailWorker = mailWorker;
|
|
|
|
|
_reportLogic = reportLogic;
|
2024-11-17 00:04:09 +04:00
|
|
|
|
_message = message;
|
2024-11-03 19:42:19 +04:00
|
|
|
|
}
|
|
|
|
|
/// Мероприятия
|
|
|
|
|
[HttpGet]
|
2024-11-04 19:46:16 +04:00
|
|
|
|
public List<EventViewModel>? GetEventList(int organizerId)
|
2024-11-03 19:42:19 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-04 19:46:16 +04:00
|
|
|
|
if (organizerId == null)
|
|
|
|
|
{
|
|
|
|
|
return _event.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
return _event.ReadList(new EventBindingModel
|
|
|
|
|
{
|
|
|
|
|
OrganizerId = organizerId
|
|
|
|
|
});
|
2024-11-03 19:42:19 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-04 19:46:16 +04:00
|
|
|
|
|
2024-11-05 23:50:08 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<VisitorViewModel>? GetVisitorList(int eventId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (eventId == null)
|
|
|
|
|
{
|
|
|
|
|
return _visitor.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
return _visitor.ReadList(new VisitorBindingModel
|
|
|
|
|
{
|
|
|
|
|
EventId = eventId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 19:46:16 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateEvent(EventBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_event.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-17 00:04:09 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateMessage(SentMessageBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_message.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<SentMessageViewModel>? GetSentMessageList(int eventId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (eventId == null)
|
|
|
|
|
{
|
|
|
|
|
return _message.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
return _message.ReadList(new SentMessageBindingModel
|
|
|
|
|
{
|
|
|
|
|
EventId = eventId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 14:09:00 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void RegistrationOnEvent(VisitorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_visitor.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 19:46:16 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public EventViewModel? GetEvent(int eventId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _event.ReadElement(new EventBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = eventId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-06 03:05:29 +04:00
|
|
|
|
|
2024-11-04 19:46:16 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateEvent(EventBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_event.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-19 10:28:03 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public VisitorViewModel? GetVisitor(int visitorId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _visitor.ReadElement(new VisitorBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = visitorId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-06 11:54:20 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateVisitor(VisitorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_visitor.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 10:28:03 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteVisitor(VisitorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_visitor.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 19:46:16 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteEvent(EventBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_event.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-06 03:05:29 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendToMail(MailSendInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_mailWorker.MailSendAsync(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-06 03:05:29 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToWordFile(ReportVisitorsBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveVisitorsToWordFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-06 03:05:29 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToExcelFile(ReportVisitorsBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveVisitorsToExcelFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|