@using LANCommander.SDK.Enums @using LANCommander.Server.Extensions; @using LANCommander.Server.Models; @using LANCommander.Server.UI.Components; @inherits FeedbackComponent @inject DatabaseServiceFactory DatabaseServiceFactory @inject ModalService ModalService @inject IMessageService MessageService @inject ILogger Logger @code { Guid Id = Guid.NewGuid(); Script Script; protected override async Task OnInitializedAsync() { using (var scriptService = DatabaseServiceFactory.Create()) { 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 { using (var scriptService = DatabaseServiceFactory.Create()) { 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; } } }