Saving of enemies
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -56,8 +56,6 @@ namespace EstusShots.Gtk
|
||||
_ = ReloadDrinks();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Events
|
||||
|
||||
private void PlayersControlActivated(Player player)
|
||||
|
||||
@@ -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<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(()
|
||||
=> Client.Enemies.GetEnemies(new GetEnemiesParameter()).Result);
|
||||
|
||||
Reference in New Issue
Block a user