diff --git a/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs b/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs index 0aa6920..0f34d94 100644 --- a/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs +++ b/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs @@ -6,8 +6,10 @@ namespace EventHub.Events.Registrations { public interface IEventRegistrationAppService : IApplicationService { - Task RegisterAsync(Guid id); + Task RegisterAsync(Guid eventId); - Task UnregisterAsync(Guid id); + Task UnregisterAsync(Guid eventId); + + Task IsRegisteredAsync(Guid eventId); } } diff --git a/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs b/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs index f5f81b4..dc6d2e9 100644 --- a/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs +++ b/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs @@ -24,19 +24,28 @@ namespace EventHub.Events.Registrations } [Authorize] - public async Task RegisterAsync(Guid id) + public async Task RegisterAsync(Guid eventId) { await _eventRegistrationManager.RegisterAsync( - await _eventRepository.GetAsync(id), + await _eventRepository.GetAsync(eventId), await _userRepository.GetAsync(CurrentUser.GetId()) ); } [Authorize] - public async Task UnregisterAsync(Guid id) + public async Task UnregisterAsync(Guid eventId) { await _eventRegistrationManager.UnregisterAsync( - await _eventRepository.GetAsync(id), + await _eventRepository.GetAsync(eventId), + await _userRepository.GetAsync(CurrentUser.GetId()) + ); + } + + [Authorize] + public async Task IsRegisteredAsync(Guid eventId) + { + return await _eventRegistrationManager.IsRegisteredAsync( + await _eventRepository.GetAsync(eventId), await _userRepository.GetAsync(CurrentUser.GetId()) ); } diff --git a/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json b/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json index 6e8945f..3c93977 100644 --- a/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json +++ b/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json @@ -22,10 +22,15 @@ "EventHub:CantRegisterOrUnregisterForAPastEvent": "Can not register to or unregister from an event in the past.", "Events": "Events", "Members": "Members", - "SeeOrganization": "See Organization", + "SeeOrganization": "See organization", "Organization": "Organization", "Submit": "Submit", - "SeeEvent": "See Event", - "RegisterNow": "Register Now" + "SeeEvent": "See event", + "RegisterNow": "Register Now", + "LoginToRegister": "Login to register", + "CancelRegistration": "Cancel registration", + "EventRegisterSuccessMessageTitle": "Thanks for registering!", + "EventRegisterSuccessMessage": "We will send a reminder email before the event.", + "EventRegistrationCancelledMessage": "Your event registration has been cancelled." } } diff --git a/eventhub/src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs b/eventhub/src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs index 3008cf1..419e8b1 100644 --- a/eventhub/src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs +++ b/eventhub/src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs @@ -27,7 +27,7 @@ namespace EventHub.Events.Registrations { CheckEventEndTime(@event); - if (await _eventRegistrationRepository.AnyAsync(x => x.EventId == @event.Id && x.UserId == user.Id)) + if (await IsRegisteredAsync(@event, user)) { return; } @@ -52,6 +52,14 @@ namespace EventHub.Events.Registrations ); } + public async Task IsRegisteredAsync( + Event @event, + AppUser user) + { + return await _eventRegistrationRepository + .AnyAsync(x => x.EventId == @event.Id && x.UserId == user.Id); + } + private void CheckEventEndTime(Event @event) { if (_clock.Now > @event.EndTime) diff --git a/eventhub/src/EventHub.Web/Controllers/EventRegistrationController.cs b/eventhub/src/EventHub.Web/Controllers/EventRegistrationController.cs new file mode 100644 index 0000000..8548ffb --- /dev/null +++ b/eventhub/src/EventHub.Web/Controllers/EventRegistrationController.cs @@ -0,0 +1,42 @@ +using System; +using System.Threading.Tasks; +using EventHub.Events.Registrations; +using EventHub.Web.Pages.Events.Components.RegistrationArea; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace EventHub.Web.Controllers +{ + public class EventRegistrationController : AbpController + { + private readonly IEventRegistrationAppService _eventRegistrationAppService; + + public EventRegistrationController(IEventRegistrationAppService eventRegistrationAppService) + { + _eventRegistrationAppService = eventRegistrationAppService; + } + + [HttpPost] + public async Task Register(Guid eventId) + { + await _eventRegistrationAppService.RegisterAsync(eventId); + return NoContent(); + } + + [HttpPost] + public async Task Unregister(Guid eventId) + { + await _eventRegistrationAppService.UnregisterAsync(eventId); + return NoContent(); + } + + [HttpGet] + public IActionResult Widget(Guid eventId) + { + return ViewComponent( + typeof(RegistrationAreaViewComponent), + new {eventId} + ); + } + } +} diff --git a/eventhub/src/EventHub.Web/Controllers/WidgetsController.cs b/eventhub/src/EventHub.Web/Controllers/WidgetsController.cs index 7c3060c..8cbd060 100644 --- a/eventhub/src/EventHub.Web/Controllers/WidgetsController.cs +++ b/eventhub/src/EventHub.Web/Controllers/WidgetsController.cs @@ -1,6 +1,5 @@ using System; using EventHub.Web.Pages.Events.Components.AttendeesArea; -using EventHub.Web.Pages.Events.Components.RegistrationArea; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; @@ -8,15 +7,6 @@ namespace EventHub.Web.Controllers { public class WidgetsController : AbpController { - [HttpGet] - public IActionResult EventRegistrationArea(Guid eventId) - { - return ViewComponent( - typeof(RegistrationAreaViewComponent), - new {eventId} - ); - } - [HttpGet] public IActionResult EventAttendeesArea(Guid eventId) { diff --git a/eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/RegistrationAreaViewComponent.cs b/eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs similarity index 100% rename from eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/RegistrationAreaViewComponent.cs rename to eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs diff --git a/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/Default.cshtml b/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/Default.cshtml index 56d7394..423824e 100644 --- a/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/Default.cshtml +++ b/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/Default.cshtml @@ -1,8 +1,34 @@ @using EventHub.Localization @using Microsoft.AspNetCore.Mvc.Localization @inject IHtmlLocalizer L - +@model EventHub.Web.Pages.Events.Components.RegistrationArea.RegistrationAreaViewComponent.RegistrationAreaViewComponentModel + - @L["RegisterNow"] + @if (Model.IsLoggedIn) + { + if (Model.IsRegistered) + { + + } + else + { + + } + } + else + { + @L["LoginToRegister"] + } diff --git a/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/RegistrationAreaViewComponent.cs b/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/RegistrationAreaViewComponent.cs index c3cec29..2004fb4 100644 --- a/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/RegistrationAreaViewComponent.cs +++ b/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/RegistrationAreaViewComponent.cs @@ -1,25 +1,52 @@ using System; using System.Threading.Tasks; +using EventHub.Events.Registrations; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; +using Volo.Abp.Users; namespace EventHub.Web.Pages.Events.Components.RegistrationArea { [Widget( AutoInitialize = true, - RefreshUrl = "/Widgets/EventRegistrationArea", + RefreshUrl = "/EventRegistration/Widget", ScriptFiles = new[] {"/Pages/Events/Components/RegistrationArea/registration-area.js"} )] public class RegistrationAreaViewComponent : AbpViewComponent { - public RegistrationAreaViewComponent() + private readonly IEventRegistrationAppService _eventRegistrationAppService; + private readonly ICurrentUser _currentUser; + + public RegistrationAreaViewComponent( + IEventRegistrationAppService eventRegistrationAppService, + ICurrentUser currentUser) { + _eventRegistrationAppService = eventRegistrationAppService; + _currentUser = currentUser; } public async Task InvokeAsync(Guid eventId) { - return View("~/Pages/Events/Components/RegistrationArea/Default.cshtml"); + var model = new RegistrationAreaViewComponentModel + { + EventId = eventId, + IsLoggedIn = _currentUser.IsAuthenticated + }; + + if (model.IsLoggedIn) + { + model.IsRegistered = await _eventRegistrationAppService.IsRegisteredAsync(eventId); + } + + return View("~/Pages/Events/Components/RegistrationArea/Default.cshtml", model); + } + + public class RegistrationAreaViewComponentModel + { + public Guid EventId { get; set; } + public bool IsLoggedIn { get; set; } + public bool IsRegistered { get; set; } } } } diff --git a/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js b/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js index 6fe3c35..3f044c9 100644 --- a/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js +++ b/eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js @@ -1,16 +1,48 @@ (function () { + var l = abp.localization.getResource('EventHub'); abp.widgets.RegistrationArea = function ($wrapper) { var widgetManager = $wrapper.data('abp-widget-manager'); + var eventId = $wrapper.find('[data-event-id]').attr('data-event-id'); + + function getFilters() { + return { + eventId: eventId + }; + } function init() { - $wrapper.find('#EventRegisterButton').click(function(e){ + var $registerButton = $wrapper.find('#EventRegisterButton'); + $registerButton.click(function (e) { + e.preventDefault(); + $registerButton.buttonBusy(true); + abp.ajax({ + url: $registerButton.attr('data-url') + }).then(function (){ + widgetManager.refresh(); + abp.message.success(l('EventRegisterSuccessMessage'), l('EventRegisterSuccessMessageTitle')); + }).always(function (){ + $registerButton.buttonBusy(false); + }); + }); + + var $cancelRegistrationButton = $wrapper.find('#EventCancelRegistrationButton'); + $cancelRegistrationButton.click(function (e) { e.preventDefault(); - widgetManager.refresh(); + $cancelRegistrationButton.buttonBusy(true); + abp.ajax({ + url: $cancelRegistrationButton.attr('data-url') + }).then(function (){ + widgetManager.refresh(); + abp.notify.info(l('EventRegistrationCancelledMessage')); + }).always(function (){ + $cancelRegistrationButton.buttonBusy(false); + }); }); } return { + getFilters: getFilters, init: init }; };