Saving of enemies

This commit is contained in:
2020-03-09 17:47:26 +01:00
parent e85f4a1adb
commit 13a87b7094
4 changed files with 34 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using EstusShots.Gtk.Controls; using EstusShots.Gtk.Controls;
using EstusShots.Shared.Dto; using EstusShots.Shared.Dto;
using Gtk; using Gtk;
@@ -33,10 +34,20 @@ namespace EstusShots.Gtk.Dialogs
protected override void LoadToModel() 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() protected override void LoadFromModel()
{ {
_nameEntry.Text = EditObject.Name;
_isBossCheckButton.Active = EditObject.Boss;
if (EditObject.Seasons != null)
_seasonSelectionControl.SelectedItems.AddRange(EditObject.Seasons);
} }
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using EstusShots.Client; using EstusShots.Client;
using EstusShots.Gtk.Dialogs; using EstusShots.Gtk.Dialogs;
using Gdk; using Gdk;
@@ -56,7 +57,7 @@ namespace EstusShots.Gtk
private void NavigationOnSwitchPage(object o, SwitchPageArgs args) private void NavigationOnSwitchPage(object o, SwitchPageArgs args)
{ {
if (!(args.Page is Box appPage)) return; if (!(args.Page is Box appPage)) return;
if (appPage == _enemiesPage) EnemiesPageNavigatedTo();
} }
private void ExceptionManagerOnUnhandledException(UnhandledExceptionArgs args) private void ExceptionManagerOnUnhandledException(UnhandledExceptionArgs args)

View File

@@ -56,8 +56,6 @@ namespace EstusShots.Gtk
_ = ReloadDrinks(); _ = ReloadDrinks();
} }
// Events // Events
private void PlayersControlActivated(Player player) private void PlayersControlActivated(Player player)

View File

@@ -31,13 +31,33 @@ namespace EstusShots.Gtk
_newEnemyButton.Clicked += NewEnemyButtonOnClicked; _newEnemyButton.Clicked += NewEnemyButtonOnClicked;
} }
private void EnemiesPageNavigatedTo()
{
var _ = ReloadEnemies();
}
private void NewEnemyButtonOnClicked(object sender, EventArgs e) private void NewEnemyButtonOnClicked(object sender, EventArgs e)
{ {
var enemyEditor = new EnemyEditor(this, new Enemy(), SeasonsControl.Items); var enemyEditor = new EnemyEditor(this, new Enemy(), SeasonsControl.Items);
enemyEditor.DialogClosed += EnemyEditorOnDialogClosed;
enemyEditor.Show(); enemyEditor.Show();
} }
private async void ReloadEnemies() private async void EnemyEditorOnDialogClosed(object o, DialogClosedEventArgs<Enemy> 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(() var res = await Task.Factory.StartNew(()
=> Client.Enemies.GetEnemies(new GetEnemiesParameter()).Result); => Client.Enemies.GetEnemies(new GetEnemiesParameter()).Result);