145 lines
5.9 KiB
Plaintext
145 lines
5.9 KiB
Plaintext
@using Oqtane.Modules.Controls
|
|
@using SZUAbsolventenverein.Module.EventRegistration.Services
|
|
@using SZUAbsolventenverein.Module.EventRegistration.Models
|
|
|
|
@namespace SZUAbsolventenverein.Module.EventRegistration
|
|
@inherits ModuleBase
|
|
@inject IEventRegistrationService EventRegistrationService
|
|
@inject NavigationManager NavigationManager
|
|
@inject IStringLocalizer<Edit> Localizer
|
|
|
|
<form @ref="form" class="@(validated ? " was-validated" : "needs-validation" )" novalidate>
|
|
<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>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="description" HelpText="Enter a description" ResourceKey="Description">Description: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="description" class="form-control" @bind="@_description" required />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="eventdate" HelpText="Enter a Date" ResourceKey="EventDate">EventDate: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="eventdate" class="form-control" @bind="@_eventDate" required />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="location" HelpText="Enter a Location" ResourceKey="Location">Location: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="location" class="form-control" @bind="@_location" required />
|
|
</div>
|
|
</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 />
|
|
@if (PageState.Action == "Edit")
|
|
{
|
|
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon"></AuditInfo>
|
|
}
|
|
</form>
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
|
|
|
public override string Actions => "Add,Edit";
|
|
|
|
public override string Title => "Manage Event";
|
|
|
|
public override List<Resource> Resources => new List<Resource>()
|
|
{
|
|
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
|
|
};
|
|
|
|
private ElementReference form;
|
|
private bool validated = false;
|
|
|
|
private int _id;
|
|
private string _name;
|
|
private string _description;
|
|
private DateTime _eventDate;
|
|
private string _location;
|
|
|
|
private string _createdby;
|
|
private DateTime _createdon;
|
|
private string _modifiedby;
|
|
private DateTime _modifiedon;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
if (PageState.Action == "Edit")
|
|
{
|
|
_id = Int32.Parse(PageState.QueryString["id"]);
|
|
Event EventRegistration = await EventRegistrationService.GetEventAsync(_id, ModuleState.ModuleId);
|
|
if (EventRegistration != null)
|
|
{
|
|
_name = EventRegistration.Name;
|
|
_description = EventRegistration.Description;
|
|
_eventDate = EventRegistration.EventDate;
|
|
_location = EventRegistration.Location;
|
|
|
|
_createdby = EventRegistration.CreatedBy;
|
|
_createdon = EventRegistration.CreatedOn;
|
|
_modifiedby = EventRegistration.ModifiedBy;
|
|
_modifiedon = EventRegistration.ModifiedOn;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading EventRegistration {EventRegistrationId} {Error}", _id, ex.Message);
|
|
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task Save()
|
|
{
|
|
try
|
|
{
|
|
validated = true;
|
|
var interop = new Oqtane.UI.Interop(JSRuntime);
|
|
if (await interop.FormValid(form))
|
|
{
|
|
if (PageState.Action == "Add")
|
|
{
|
|
Event EventRegistration = new Event();
|
|
EventRegistration.ModuleId = ModuleState.ModuleId;
|
|
EventRegistration.Name = _name;
|
|
EventRegistration.Description = _description;
|
|
EventRegistration.EventDate = _eventDate;
|
|
EventRegistration.Location = _location;
|
|
EventRegistration = await EventRegistrationService.AddEventAsync(EventRegistration);
|
|
await logger.LogInformation("EventRegistration Added {EventRegistration}", EventRegistration);
|
|
}
|
|
else
|
|
{
|
|
Event EventRegistration = await EventRegistrationService.GetEventAsync(_id, ModuleState.ModuleId);
|
|
EventRegistration.Name = _name;
|
|
EventRegistration.Description = _description;
|
|
EventRegistration.EventDate = _eventDate;
|
|
EventRegistration.Location = _location;
|
|
await EventRegistrationService.UpdateEventAsync(EventRegistration);
|
|
await logger.LogInformation("EventRegistration Updated {EventRegistration}", EventRegistration);
|
|
}
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Message.SaveValidation"], MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Saving EventRegistration {Error}", ex.Message);
|
|
AddModuleMessage(Localizer["Message.SaveError"], MessageType.Error);
|
|
}
|
|
}
|
|
}
|