Bulk-Commit: Darft: Anmeldetool.

Interface Definition: done
Server-Side-Implementation: partly done (CR missing, potential Refactor, ...)
Client-Side-Implementation: started: (UI: done, Service: started, but works with SSR)
Missing: Permissions / Roles to restrict access to an event.
Missing: Fields on Event.
Missing: Good Styling
Time-Took: about 12 Hours.
Learning: Commit in smaller packets, rest will be discussed at CR
This commit is contained in:
Konstantin Hintermayer
2025-05-14 20:40:10 +02:00
parent e45fce2e65
commit 38c5bef225
17 changed files with 508 additions and 92 deletions

View File

@ -8,22 +8,38 @@
@inject NavigationManager NavigationManager
@inject IStringLocalizer<Edit> Localizer
<div class="container">
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="name" HelpText="Enter a name" ResourceKey="Name">Name: </Label>
<div class="col-sm-9">
<input id="name" class="form-control" @bind="@_name" required />
</div>
<h3>Anmeldung zum Event</h3>
<p>Willst du am Event (@_name) teilnehmen?</p>
@if (PageState.User != null) {
@if (Status != null)
{
<p class="mt-3"><strong>Status:</strong>
@if (Status == true)
{
@Localizer["Zusage"]
<button class="btn btn-danger" @onclick="Absage">@Localizer["Absagen"]</button>
} else
{
@Localizer["Absage"]
<button class="btn btn-success" @onclick="Zusage">@Localizer["Zusagen"]</button>
}
</p>
} else {
<div class="buttons">
<button class="btn btn-success" @onclick="Zusage">@Localizer["Zusagen"]</button>
<button class="btn btn-danger" @onclick="Absage">@Localizer["Absagen"]</button>
</div>
</div>
<button type="button" class="btn btn-success" @onclick="Save">@Localizer["Save"]</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink>
<br /><br />
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon"></AuditInfo>
}
} else
{
<p class="mt-3">Um dich für dieses Event zu registrieren, muss man sich zuerst anmelden.</p> <Login />
}
@code {
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
public override string Actions => "Details";
@ -44,19 +60,59 @@
private string _modifiedby;
private DateTime _modifiedon;
private Response _response;
private bool? Status;
private async Task SendResponse(bool response)
{
if(_response == null)
{
_response = new Response();
_response.EventRegistrationId = _id;
_response.OwnerId = PageState.User.UserId;
_response.ModuleId = ModuleState.ModuleId;
_response.ResponseType = response;
_response = await EventRegistrationService.AddResponseAsync(_response);
} else
{
_response.ResponseType = response;
_response = await EventRegistrationService.UpdateResponseAsync(_response);
}
if(_response != null) Status = _response.ResponseType;
}
private async void Zusage()
{
await SendResponse(true);
}
private async void Absage()
{
await SendResponse(false);
}
protected override async Task OnInitializedAsync()
{
try
{
_id = Int32.Parse(PageState.QueryString["id"]);
Event EventRegistration = await EventRegistrationService.GetEventRegistrationAsync(_id, ModuleState.ModuleId);
if (EventRegistration != null)
Event currentEvent;
Response rsvp;
(currentEvent, rsvp) = await EventRegistrationService.GetEventDetails(_id, ModuleState.ModuleId);
if (currentEvent != null)
{
_name = EventRegistration.Name;
_createdby = EventRegistration.CreatedBy;
_createdon = EventRegistration.CreatedOn;
_modifiedby = EventRegistration.ModifiedBy;
_modifiedon = EventRegistration.ModifiedOn;
_name = currentEvent.Name;
_createdby = currentEvent.CreatedBy;
_createdon = currentEvent.CreatedOn;
_modifiedby = currentEvent.ModifiedBy;
_modifiedon = currentEvent.ModifiedOn;
}
if(rsvp != null)
{
_response = rsvp;
Status = rsvp.ResponseType;
}
}
catch (Exception ex)
@ -79,14 +135,14 @@
Event EventRegistration = new Event();
EventRegistration.ModuleId = ModuleState.ModuleId;
EventRegistration.Name = _name;
EventRegistration = await EventRegistrationService.AddEventRegistrationAsync(EventRegistration);
EventRegistration = await EventRegistrationService.AddEventAsync(EventRegistration);
await logger.LogInformation("EventRegistration Added {EventRegistration}", EventRegistration);
}
else
{
Event EventRegistration = await EventRegistrationService.GetEventRegistrationAsync(_id, ModuleState.ModuleId);
Event EventRegistration = await EventRegistrationService.GetEventAsync(_id, ModuleState.ModuleId);
EventRegistration.Name = _name;
await EventRegistrationService.UpdateEventRegistrationAsync(EventRegistration);
await EventRegistrationService.UpdateEventAsync(EventRegistration);
await logger.LogInformation("EventRegistration Updated {EventRegistration}", EventRegistration);
}
NavigationManager.NavigateTo(NavigateUrl());

View File

@ -55,7 +55,7 @@
if (PageState.Action == "Edit")
{
_id = Int32.Parse(PageState.QueryString["id"]);
Event EventRegistration = await EventRegistrationService.GetEventRegistrationAsync(_id, ModuleState.ModuleId);
Event EventRegistration = await EventRegistrationService.GetEventAsync(_id, ModuleState.ModuleId);
if (EventRegistration != null)
{
_name = EventRegistration.Name;
@ -86,14 +86,14 @@
Event EventRegistration = new Event();
EventRegistration.ModuleId = ModuleState.ModuleId;
EventRegistration.Name = _name;
EventRegistration = await EventRegistrationService.AddEventRegistrationAsync(EventRegistration);
EventRegistration = await EventRegistrationService.AddEventAsync(EventRegistration);
await logger.LogInformation("EventRegistration Added {EventRegistration}", EventRegistration);
}
else
{
Event EventRegistration = await EventRegistrationService.GetEventRegistrationAsync(_id, ModuleState.ModuleId);
Event EventRegistration = await EventRegistrationService.GetEventAsync(_id, ModuleState.ModuleId);
EventRegistration.Name = _name;
await EventRegistrationService.UpdateEventRegistrationAsync(EventRegistration);
await EventRegistrationService.UpdateEventAsync(EventRegistration);
await logger.LogInformation("EventRegistration Updated {EventRegistration}", EventRegistration);
}
NavigationManager.NavigateTo(NavigateUrl());

View File

@ -27,13 +27,11 @@ else
<th style="width: 1px;">&nbsp;</th>
</Header>
<Row>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.EventRegistrationId.ToString())" ResourceKey="Edit" /></td>
<td><ActionDialog Header="Delete EventRegistration" Message="Are You Sure You Wish To Delete This EventRegistration?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.EventRegistrationId.ToString()" /></td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.EventId.ToString())" ResourceKey="Edit" /></td>
<td><ActionDialog Header="Delete EventRegistration" Message="Are You Sure You Wish To Delete This EventRegistration?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.EventId.ToString()" /></td>
<td>@context.Name</td>
@* @if(UserSecurity.IsAuthorized(PageState.User, PermissionNames.Utilize)) { *@
<td><ActionLink Action="Details" Parameters="@($"id=" + context.EventRegistrationId.ToString())" ResourceKey="Details"/></td>
@* } *@
<td><ActionLink Action="Details" Parameters="@($"id=" + context.EventId.ToString())" ResourceKey="Details"/></td>
</Row>
</Pager>
}
@ -58,7 +56,7 @@ else
{
try
{
_EventRegistrations = await EventRegistrationService.GetEventRegistrationsAsync(ModuleState.ModuleId);
_EventRegistrations = await EventRegistrationService.GetEventsAsync(ModuleState.ModuleId);
}
catch (Exception ex)
{
@ -71,9 +69,9 @@ else
{
try
{
await EventRegistrationService.DeleteEventRegistrationAsync(EventRegistration.EventRegistrationId, ModuleState.ModuleId);
await EventRegistrationService.DeleteEventAsync(EventRegistration.EventId, ModuleState.ModuleId);
await logger.LogInformation("EventRegistration Deleted {EventRegistration}", EventRegistration);
_EventRegistrations = await EventRegistrationService.GetEventRegistrationsAsync(ModuleState.ModuleId);
_EventRegistrations = await EventRegistrationService.GetEventsAsync(ModuleState.ModuleId);
StateHasChanged();
}
catch (Exception ex)