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-06 03:05:29 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
2024-11-03 19:42:19 +04:00
|
|
|
|
|
2024-11-06 03:05:29 +04:00
|
|
|
|
public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor, AbstractMailWorker mailWorker, IReportLogic reportLogic)
|
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-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-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-06 11:54:20 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateVisitor(VisitorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_visitor.Update(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
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|