mirror of https://github.com/abpframework/eventhub
10 changed files with 168 additions and 27 deletions
@ -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} |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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> |
||||
|
|||||
@ -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; } |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue