Skip to content

Commit

Permalink
Export and Import functions are no longer commands since they aren't …
Browse files Browse the repository at this point in the history
…used as such.
  • Loading branch information
HimmDawg committed Jul 2, 2023
1 parent 4c9dc66 commit 2a01655
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
36 changes: 16 additions & 20 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public partial class MainWindowViewModel : ViewModelBase

[ObservableProperty,
NotifyCanExecuteChangedFor(
nameof(ExportCommand),
nameof(ImportCommand),
nameof(StartAddItemCommand),
nameof(CancelAddItemCommand))]
private bool _isConnectionEstablished = true;
Expand Down Expand Up @@ -133,24 +131,6 @@ public async Task DeleteItem()
await _context.SaveChangesAsync();
}

[RelayCommand(CanExecute = nameof(CanExecuteCommands))]
public void Export(string filePath)
{
_exportService.ExportRoadshopItems(filePath, RoadshopItems.ToList());
}

[RelayCommand(CanExecute = nameof(CanExecuteCommands))]
public void Import(string filePath)
{
var items = _importService.ImportRoadshopItems(filePath);
RoadshopItems.Clear();
foreach (var item in items)
{
item.Name = AllItems[item.ItemId];
RoadshopItems.Add(item);
}
}

[RelayCommand(CanExecute = nameof(CanExecuteCommands))]
public void StartAddItem()
{
Expand Down Expand Up @@ -178,6 +158,22 @@ private bool CanExecuteDeleteItem()
return IsConnectionEstablished && SelectedRoadshopItem is not null;
}

public void Export(string filePath)
{
_exportService.ExportRoadshopItems(filePath, RoadshopItems.ToList());
}

public void Import(string filePath)
{
var items = _importService.ImportRoadshopItems(filePath);
RoadshopItems.Clear();
foreach (var item in items)
{
item.Name = AllItems[item.ItemId];
RoadshopItems.Add(item);
}
}

public async Task Initialize(RoadshopContext context)
{
if (!await context.Database.CanConnectAsync())
Expand Down
2 changes: 2 additions & 0 deletions Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@
<Button
Background="BlueViolet"
Content="Export"
IsEnabled="{Binding IsConnectionEstablished}"
Click="ExportItems_OnClick"/>
<Button
Background="BlueViolet"
Content="Import"
IsEnabled="{Binding IsConnectionEstablished}"
Click="ImportItems_OnClick"/>
</StackPanel>

Expand Down

0 comments on commit 2a01655

Please sign in to comment.