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; private readonly ISentMessageLogic _message; private readonly IReportLogic _reportLogic; private readonly AbstractMailWorker _mailWorker; public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor, AbstractMailWorker mailWorker, IReportLogic reportLogic, ISentMessageLogic message) { _organizer = organizer; _event = events; _visitor = visitor; _mailWorker = mailWorker; _reportLogic = reportLogic; _message = message; } /// Мероприятия [HttpGet] public List? GetEventList(int organizerId) { try { if (organizerId == null) { return _event.ReadList(null); } return _event.ReadList(new EventBindingModel { OrganizerId = organizerId }); } catch (Exception ex) { throw; } } [HttpGet] public List? GetVisitorList(int eventId) { try { if (eventId == null) { return _visitor.ReadList(null); } return _visitor.ReadList(new VisitorBindingModel { EventId = eventId }); } catch (Exception ex) { throw; } } [HttpPost] public void CreateEvent(EventBindingModel model) { try { _event.Create(model); } catch (Exception ex) { throw; } } [HttpPost] public void CreateMessage(SentMessageBindingModel model) { try { _message.Create(model); } catch (Exception ex) { throw; } } [HttpGet] public List? GetSentMessageList(int eventId) { try { if (eventId == null) { return _message.ReadList(null); } return _message.ReadList(new SentMessageBindingModel { EventId = eventId }); } catch (Exception ex) { throw; } } [HttpPost] public void RegistrationOnEvent(VisitorBindingModel model) { try { _visitor.Create(model); } catch (Exception ex) { throw; } } [HttpGet] public EventViewModel? GetEvent(int eventId) { try { return _event.ReadElement(new EventBindingModel { Id = eventId }); } catch (Exception ex) { throw; } } [HttpPost] public void UpdateEvent(EventBindingModel model) { try { _event.Update(model); } catch (Exception ex) { throw; } } [HttpGet] public VisitorViewModel? GetVisitor(int visitorId) { try { return _visitor.ReadElement(new VisitorBindingModel { Id = visitorId }); } catch (Exception ex) { throw; } } [HttpPost] public void UpdateVisitor(VisitorBindingModel model) { try { _visitor.Update(model); } catch (Exception ex) { throw; } } [HttpPost] public void DeleteVisitor(VisitorBindingModel model) { try { _visitor.Delete(model); } catch (Exception ex) { throw; } } [HttpPost] public void DeleteEvent(EventBindingModel model) { try { _event.Delete(model); } catch (Exception ex) { throw; } } [HttpPost] public void SendToMail(MailSendInfoBindingModel model) { try { _mailWorker.MailSendAsync(model); } catch (Exception ex) { throw; } } [HttpPost] public void CreateReportToWordFile(ReportVisitorsBindingModel model) { try { _reportLogic.SaveVisitorsToWordFile(model); } catch (Exception ex) { throw; } } [HttpPost] public void CreateReportToExcelFile(ReportVisitorsBindingModel model) { try { _reportLogic.SaveVisitorsToExcelFile(model); } catch (Exception ex) { throw; } } } }