ShowErrorWindow now actually shows the ErrorWindow

This commit is contained in:
alphafetus committed 2023-11-15 11:34:02 -05:00
1 parent 99a666afd8
commit 4fcae0b3c7
10 files changed
+104 -30

No files matched your search

+22 -11
View File
@@ -41,12 +41,11 @@ public class MainWindowViewModel : ViewModelBase {
public Interaction<DeleteWindowViewModel, Boolean> ShowDeleteWindow { get; }
public ReactiveCommand<Unit, Unit> ExportCommand { get; }
public Interaction<Unit, Uri> ShowExportWindow { get; }
public Interaction<Unit, Unit> ShowErrorWindow { get; }
public Interaction<ErrorWindowViewModel, Unit> ShowErrorWindow { get; }
private ViewModelBase _sideContent;
private Coin? _selectedCoin;
private double _totalValue;
private PcgsClient _pcgsClient;
public MainWindowViewModel(CoinDatabase coins) {
ConnectedCoinDatabase = coins;
@@ -57,7 +56,7 @@ public class MainWindowViewModel : ViewModelBase {
TotalValue = DisplayedList.Sum(x => x.TotalPrice);
// Set up the ability to show the error window.
ShowErrorWindow = new Interaction<Unit, Unit>();
ShowErrorWindow = new Interaction<ErrorWindowViewModel, Unit>();
// Set up the ability to open the delete window.
ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
@@ -84,8 +83,10 @@ public class MainWindowViewModel : ViewModelBase {
catch (IOException e) {
// Something is wrong with the file after it's been created.
Console.WriteLine(e.Message);
ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
} catch (Exception e) {
Console.WriteLine(e.Message);
ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
}
});
@@ -93,19 +94,29 @@ public class MainWindowViewModel : ViewModelBase {
// This is the same as the above, but with a different syntax.
newViewModel.OkCommand
.Subscribe(async requestStructure => {
try {
ConnectedCoinDatabase.CreateCoin(requestStructure.Item1, requestStructure.Item2,
requestStructure.Item3);
}
catch (Exception e) {
// TODO Error handling - create a popup window.
Console.WriteLine(e.Message);
var result = await ConnectedCoinDatabase.CreateCoin(requestStructure.Item1, requestStructure.Item2,
requestStructure.Item3);
switch (result) {
case PcgsClient.ErrorType.ApiKeyInvalid:
Console.WriteLine("API key is invalid - showing window.");
await ShowErrorWindow.Handle(new ErrorWindowViewModel("API key is invalid - authorization failed."));
break;
case PcgsClient.ErrorType.InvalidRequestFormat:
Console.WriteLine("Request format is invalid - showing window.");
await ShowErrorWindow.Handle(new ErrorWindowViewModel("Request format is invalid."));
break;
case PcgsClient.ErrorType.NoCoinFound:
Console.WriteLine("No coin was found with the given parameters.");
await ShowErrorWindow.Handle(new ErrorWindowViewModel("No coin was found with the given parameters."));
break;
}
// TODO Clear the text boxes.
});
// Change TotalValue anytime SelectedCoin.TotalPrice changes.
// Possible null deref - ignored due to null values summing to 0.
// Possible null deref - how do you remove this?
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
.Subscribe(_ => TotalValue = ConnectedCoinDatabase.Collection.Sum(x => x.TotalPrice));
}