@inherits FeedbackComponent @inject ScriptService ScriptService @inject IMessageService MessageService @inject ILogger Logger @code { Guid Id = Guid.NewGuid(); Script Script; protected override async Task OnInitializedAsync() { if (Options.ScriptId != Guid.Empty) Script = await ScriptService.GetAsync(Options.ScriptId); else if (Options.GameId != Guid.Empty) Script = new Script() { GameId = Options.GameId }; else if (Options.RedistributableId != Guid.Empty) Script = new Script() { RedistributableId = Options.RedistributableId }; else if (Options.ServerId != Guid.Empty) Script = new Script() { ServerId = Options.ServerId }; } public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args) { var success = await Save(); if (success) await base.OkCancelRefWithResult!.OnOk(Script); else args.Reject(); } async Task Save() { try { if (Script.Id == Guid.Empty) Script = await ScriptService.AddAsync(Script); else Script = await ScriptService.UpdateAsync(Script); MessageService.Success("Script saved!"); return true; } catch (Exception ex) { MessageService.Error("Script could not be saved!"); Logger.LogError(ex, "Script could not be saved!"); return false; } } }