diff --git a/EstusShots.Gtk/Dialogs/EnemyEditor.cs b/EstusShots.Gtk/Dialogs/EnemyEditor.cs index 565534e..42cdaf8 100644 --- a/EstusShots.Gtk/Dialogs/EnemyEditor.cs +++ b/EstusShots.Gtk/Dialogs/EnemyEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using EstusShots.Gtk.Controls; using EstusShots.Shared.Dto; using Gtk; @@ -33,10 +34,20 @@ namespace EstusShots.Gtk.Dialogs protected override void LoadToModel() { + EditObject.Name = _nameEntry.Text; + EditObject.Boss = _isBossCheckButton.Active; + EditObject.Seasons = _seasonSelectionControl.SelectedItems.Select(s => new Season() + { + SeasonId = s.SeasonId + }).ToList(); } protected override void LoadFromModel() { + _nameEntry.Text = EditObject.Name; + _isBossCheckButton.Active = EditObject.Boss; + if (EditObject.Seasons != null) + _seasonSelectionControl.SelectedItems.AddRange(EditObject.Seasons); } } } \ No newline at end of file diff --git a/EstusShots.Gtk/MainWindow.cs b/EstusShots.Gtk/MainWindow.cs index 8716d9a..4579efd 100644 --- a/EstusShots.Gtk/MainWindow.cs +++ b/EstusShots.Gtk/MainWindow.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using EstusShots.Client; using EstusShots.Gtk.Dialogs; using Gdk; @@ -56,7 +57,7 @@ namespace EstusShots.Gtk private void NavigationOnSwitchPage(object o, SwitchPageArgs args) { if (!(args.Page is Box appPage)) return; - + if (appPage == _enemiesPage) EnemiesPageNavigatedTo(); } private void ExceptionManagerOnUnhandledException(UnhandledExceptionArgs args) diff --git a/EstusShots.Gtk/Pages/BaseDataPage.cs b/EstusShots.Gtk/Pages/BaseDataPage.cs index cb28eb0..8bf10dd 100644 --- a/EstusShots.Gtk/Pages/BaseDataPage.cs +++ b/EstusShots.Gtk/Pages/BaseDataPage.cs @@ -56,8 +56,6 @@ namespace EstusShots.Gtk _ = ReloadDrinks(); } - - // Events private void PlayersControlActivated(Player player) diff --git a/EstusShots.Gtk/Pages/EnemiesPage.cs b/EstusShots.Gtk/Pages/EnemiesPage.cs index 500cc03..ec689e3 100644 --- a/EstusShots.Gtk/Pages/EnemiesPage.cs +++ b/EstusShots.Gtk/Pages/EnemiesPage.cs @@ -31,13 +31,33 @@ namespace EstusShots.Gtk _newEnemyButton.Clicked += NewEnemyButtonOnClicked; } + private void EnemiesPageNavigatedTo() + { + var _ = ReloadEnemies(); + } + private void NewEnemyButtonOnClicked(object sender, EventArgs e) { var enemyEditor = new EnemyEditor(this, new Enemy(), SeasonsControl.Items); + enemyEditor.DialogClosed += EnemyEditorOnDialogClosed; enemyEditor.Show(); } - private async void ReloadEnemies() + private async void EnemyEditorOnDialogClosed(object o, DialogClosedEventArgs args) + { + if (!args.Ok) return; + var res = await Client.Enemies.SaveEnemy(new SaveEnemyParameter(args.Model)); + if (!res.OperationResult.Success) + { + Info($"Unable to save: {res.OperationResult.ShortMessage}"); + ErrorDialog.Show(res.OperationResult); + return; + } + + await ReloadEnemies(); + } + + private async Task ReloadEnemies() { var res = await Task.Factory.StartNew(() => Client.Enemies.GetEnemies(new GetEnemiesParameter()).Result);