@using Oqtane.Modules.Controls @using SZUAbsolventenverein.Module.PremiumArea.Services @using SZUAbsolventenverein.Module.PremiumArea.Models @namespace SZUAbsolventenverein.Module.PremiumArea @inherits ModuleBase @inject IPremiumAreaService PremiumAreaService @inject NavigationManager NavigationManager @inject IStringLocalizer Localizer
@Localizer["Cancel"]

@if (PageState.Action == "Edit") { }
@code { public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit; public override string Actions => "Add,Edit"; public override string Title => "Manage PremiumArea"; public override List Resources => new List() { new Stylesheet("_content/SZUAbsolventenverein.Module.PremiumArea/Module.css") }; private ElementReference form; private bool validated = false; private int _id; private string _name; 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"]); PremiumArea PremiumArea = await PremiumAreaService.GetPremiumAreaAsync(_id, ModuleState.ModuleId); if (PremiumArea != null) { _name = PremiumArea.Name; _createdby = PremiumArea.CreatedBy; _createdon = PremiumArea.CreatedOn; _modifiedby = PremiumArea.ModifiedBy; _modifiedon = PremiumArea.ModifiedOn; } } } catch (Exception ex) { await logger.LogError(ex, "Error Loading PremiumArea {PremiumAreaId} {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") { PremiumArea PremiumArea = new PremiumArea(); PremiumArea.ModuleId = ModuleState.ModuleId; PremiumArea.Name = _name; PremiumArea = await PremiumAreaService.AddPremiumAreaAsync(PremiumArea); await logger.LogInformation("PremiumArea Added {PremiumArea}", PremiumArea); } else { PremiumArea PremiumArea = await PremiumAreaService.GetPremiumAreaAsync(_id, ModuleState.ModuleId); PremiumArea.Name = _name; await PremiumAreaService.UpdatePremiumAreaAsync(PremiumArea); await logger.LogInformation("PremiumArea Updated {PremiumArea}", PremiumArea); } NavigationManager.NavigateTo(NavigateUrl()); } else { AddModuleMessage(Localizer["Message.SaveValidation"], MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving PremiumArea {Error}", ex.Message); AddModuleMessage(Localizer["Message.SaveError"], MessageType.Error); } } }