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 IReportLogic _reportLogic; private readonly AbstractMailWorker _mailWorker; public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor, AbstractMailWorker mailWorker, IReportLogic reportLogic) { _organizer = organizer; _event = events; _visitor = visitor; _mailWorker = mailWorker; _reportLogic = reportLogic; } /// Мероприятия [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 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; } } [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; } } } }