Browse Source

Implemented UI register/unregister.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
d7b01adbfc
  1. 6
      eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs
  2. 17
      eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs
  3. 11
      eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json
  4. 10
      eventhub/src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs
  5. 42
      eventhub/src/EventHub.Web/Controllers/EventRegistrationController.cs
  6. 10
      eventhub/src/EventHub.Web/Controllers/WidgetsController.cs
  7. 0
      eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs
  8. 30
      eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/Default.cshtml
  9. 33
      eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/RegistrationAreaViewComponent.cs
  10. 36
      eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js

6
eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs

@ -6,8 +6,10 @@ namespace EventHub.Events.Registrations
{ {
public interface IEventRegistrationAppService : IApplicationService public interface IEventRegistrationAppService : IApplicationService
{ {
Task RegisterAsync(Guid id); Task RegisterAsync(Guid eventId);
Task UnregisterAsync(Guid id); Task UnregisterAsync(Guid eventId);
Task<bool> IsRegisteredAsync(Guid eventId);
} }
} }

17
eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs

@ -24,19 +24,28 @@ namespace EventHub.Events.Registrations
} }
[Authorize] [Authorize]
public async Task RegisterAsync(Guid id) public async Task RegisterAsync(Guid eventId)
{ {
await _eventRegistrationManager.RegisterAsync( await _eventRegistrationManager.RegisterAsync(
await _eventRepository.GetAsync(id), await _eventRepository.GetAsync(eventId),
await _userRepository.GetAsync(CurrentUser.GetId()) await _userRepository.GetAsync(CurrentUser.GetId())
); );
} }
[Authorize] [Authorize]
public async Task UnregisterAsync(Guid id) public async Task UnregisterAsync(Guid eventId)
{ {
await _eventRegistrationManager.UnregisterAsync( await _eventRegistrationManager.UnregisterAsync(
await _eventRepository.GetAsync(id), await _eventRepository.GetAsync(eventId),
await _userRepository.GetAsync(CurrentUser.GetId())
);
}
[Authorize]
public async Task<bool> IsRegisteredAsync(Guid eventId)
{
return await _eventRegistrationManager.IsRegisteredAsync(
await _eventRepository.GetAsync(eventId),
await _userRepository.GetAsync(CurrentUser.GetId()) await _userRepository.GetAsync(CurrentUser.GetId())
); );
} }

11
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.", "EventHub:CantRegisterOrUnregisterForAPastEvent": "Can not register to or unregister from an event in the past.",
"Events": "Events", "Events": "Events",
"Members": "Members", "Members": "Members",
"SeeOrganization": "See Organization", "SeeOrganization": "See organization",
"Organization": "Organization", "Organization": "Organization",
"Submit": "Submit", "Submit": "Submit",
"SeeEvent": "See Event", "SeeEvent": "See event",
"RegisterNow": "Register Now" "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."
} }
} }

10
eventhub/src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs

@ -27,7 +27,7 @@ namespace EventHub.Events.Registrations
{ {
CheckEventEndTime(@event); CheckEventEndTime(@event);
if (await _eventRegistrationRepository.AnyAsync(x => x.EventId == @event.Id && x.UserId == user.Id)) if (await IsRegisteredAsync(@event, user))
{ {
return; return;
} }
@ -52,6 +52,14 @@ namespace EventHub.Events.Registrations
); );
} }
public async Task<bool> IsRegisteredAsync(
Event @event,
AppUser user)
{
return await _eventRegistrationRepository
.AnyAsync(x => x.EventId == @event.Id && x.UserId == user.Id);
}
private void CheckEventEndTime(Event @event) private void CheckEventEndTime(Event @event)
{ {
if (_clock.Now > @event.EndTime) if (_clock.Now > @event.EndTime)

42
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<NoContentResult> Register(Guid eventId)
{
await _eventRegistrationAppService.RegisterAsync(eventId);
return NoContent();
}
[HttpPost]
public async Task<NoContentResult> Unregister(Guid eventId)
{
await _eventRegistrationAppService.UnregisterAsync(eventId);
return NoContent();
}
[HttpGet]
public IActionResult Widget(Guid eventId)
{
return ViewComponent(
typeof(RegistrationAreaViewComponent),
new {eventId}
);
}
}
}

10
eventhub/src/EventHub.Web/Controllers/WidgetsController.cs

@ -1,6 +1,5 @@
using System; using System;
using EventHub.Web.Pages.Events.Components.AttendeesArea; using EventHub.Web.Pages.Events.Components.AttendeesArea;
using EventHub.Web.Pages.Events.Components.RegistrationArea;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
@ -8,15 +7,6 @@ namespace EventHub.Web.Controllers
{ {
public class WidgetsController : AbpController public class WidgetsController : AbpController
{ {
[HttpGet]
public IActionResult EventRegistrationArea(Guid eventId)
{
return ViewComponent(
typeof(RegistrationAreaViewComponent),
new {eventId}
);
}
[HttpGet] [HttpGet]
public IActionResult EventAttendeesArea(Guid eventId) public IActionResult EventAttendeesArea(Guid eventId)
{ {

0
eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/RegistrationAreaViewComponent.cs → eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs

30
eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/Default.cshtml

@ -1,8 +1,34 @@
@using EventHub.Localization @using EventHub.Localization
@using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.AspNetCore.Mvc.Localization
@inject IHtmlLocalizer<EventHubResource> L @inject IHtmlLocalizer<EventHubResource> L
<abp-card class="mb-3"> @model EventHub.Web.Pages.Events.Components.RegistrationArea.RegistrationAreaViewComponent.RegistrationAreaViewComponentModel
<abp-card class="mb-3" data-event-id="@Model.EventId">
<abp-card-body> <abp-card-body>
<a id="EventRegisterButton" abp-button="Primary" href="#"> @L["RegisterNow"]</a> @if (Model.IsLoggedIn)
{
if (Model.IsRegistered)
{
<abp-button id="EventCancelRegistrationButton"
button-type="Secondary"
size="Block"
icon="fas fa-times"
text="@L["CancelRegistration"].Value"
data-url="@Url.Action("Unregister","EventRegistration", new { eventId = Model.EventId })" />
}
else
{
<abp-button id="EventRegisterButton"
button-type="Primary"
size="Block"
icon="fas fa-plus"
text="@L["RegisterNow"].Value"
data-url="@Url.Action("Register","EventRegistration", new { eventId = Model.EventId })"/>
}
}
else
{
<a abp-button="Primary"
href="@Url.Action("Login", "Account")"> @L["LoginToRegister"]</a>
}
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>

33
eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/RegistrationAreaViewComponent.cs

@ -1,25 +1,52 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using EventHub.Events.Registrations;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.Abp.Users;
namespace EventHub.Web.Pages.Events.Components.RegistrationArea namespace EventHub.Web.Pages.Events.Components.RegistrationArea
{ {
[Widget( [Widget(
AutoInitialize = true, AutoInitialize = true,
RefreshUrl = "/Widgets/EventRegistrationArea", RefreshUrl = "/EventRegistration/Widget",
ScriptFiles = new[] {"/Pages/Events/Components/RegistrationArea/registration-area.js"} ScriptFiles = new[] {"/Pages/Events/Components/RegistrationArea/registration-area.js"}
)] )]
public class RegistrationAreaViewComponent : AbpViewComponent 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<IViewComponentResult> InvokeAsync(Guid eventId) public async Task<IViewComponentResult> 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; }
} }
} }
} }

36
eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js

@ -1,16 +1,48 @@
(function () { (function () {
var l = abp.localization.getResource('EventHub');
abp.widgets.RegistrationArea = function ($wrapper) { abp.widgets.RegistrationArea = function ($wrapper) {
var widgetManager = $wrapper.data('abp-widget-manager'); 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() { 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(); 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 { return {
getFilters: getFilters,
init: init init: init
}; };
}; };

Loading…
Cancel
Save