-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete method for route repositories
- Loading branch information
1 parent
8236ed4
commit 2f3c1b9
Showing
20 changed files
with
533 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/RoadCaptain.App.RouteBuilder/ViewModels/DesignTimeManageRoutesViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Collections.Immutable; | ||
using RoadCaptain.UseCases; | ||
|
||
namespace RoadCaptain.App.RouteBuilder.ViewModels | ||
{ | ||
public class DesignTimeManageRoutesViewModel : ManageRoutesViewModel | ||
{ | ||
public DesignTimeManageRoutesViewModel() | ||
: base(new RetrieveRepositoryNamesUseCase(new[] { new StubRouteRepository() }), null!, new DeleteRouteUseCase(new []{new StubRouteRepository()})) | ||
{ | ||
Repositories = new[] | ||
{ | ||
"All", | ||
"Local" | ||
}.ToImmutableList(); | ||
|
||
Routes = new[] | ||
{ | ||
new RoadCaptain.App.Shared.ViewModels.RouteViewModel(new RouteModel | ||
{ | ||
Ascent = 123, | ||
Descent = 75, | ||
Distance = 105, | ||
CreatorName = "Joe Bloegs", | ||
World = "watopia", | ||
Id = 1, | ||
IsLoop = false, | ||
Name = "Design time route 1", | ||
RepositoryName = "Local", | ||
ZwiftRouteName = "ZRName1" | ||
}), | ||
|
||
new RoadCaptain.App.Shared.ViewModels.RouteViewModel(new RouteModel | ||
{ | ||
Ascent = 13, | ||
Descent = 45, | ||
Distance = 45, | ||
CreatorName = "Joe Blogs", | ||
World = "yorkshire", | ||
Id = 2, | ||
IsLoop = true, | ||
Name = "Design time route 2", | ||
RepositoryName = "Local", | ||
ZwiftRouteName = "ZRName2" | ||
}), | ||
|
||
new RoadCaptain.App.Shared.ViewModels.RouteViewModel(new RouteModel | ||
{ | ||
Ascent = 13, | ||
Descent = 45, | ||
Distance = 45, | ||
CreatorName = "Joe Blogs", | ||
World = "makuri_islands", | ||
Id = 3, | ||
IsLoop = true, | ||
Name = "Design time route 3", | ||
RepositoryName = "Local", | ||
ZwiftRouteName = "ZRName3" | ||
}) | ||
}.ToImmutableList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/RoadCaptain.App.RouteBuilder/ViewModels/ManageRoutesViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using ReactiveUI; | ||
using RoadCaptain.App.Shared.Commands; | ||
using RoadCaptain.App.Shared.Dialogs; | ||
using RoadCaptain.Commands; | ||
using RoadCaptain.UseCases; | ||
|
||
namespace RoadCaptain.App.RouteBuilder.ViewModels | ||
{ | ||
public class ManageRoutesViewModel : ViewModelBase | ||
{ | ||
private ImmutableList<string>? _repositories; | ||
private string? _selectedRepository; | ||
private readonly RetrieveRepositoryNamesUseCase _retrieveRepositoryNamesUseCase; | ||
private ImmutableList<Shared.ViewModels.RouteViewModel>? _routes; | ||
private readonly IWindowService _windowService; | ||
private readonly DeleteRouteUseCase _deleteRouteUseCase; | ||
|
||
public ManageRoutesViewModel(RetrieveRepositoryNamesUseCase retrieveRepositoryNamesUseCase, IWindowService windowService, DeleteRouteUseCase deleteRouteUseCase) | ||
{ | ||
_retrieveRepositoryNamesUseCase = retrieveRepositoryNamesUseCase; | ||
_windowService = windowService; | ||
_deleteRouteUseCase = deleteRouteUseCase; | ||
} | ||
|
||
public AsyncRelayCommand DeleteRouteCommand => new AsyncRelayCommand( | ||
parameter => DeleteRouteAsync((parameter as Shared.ViewModels.RouteViewModel)!), | ||
parameter => parameter is Shared.ViewModels.RouteViewModel); | ||
|
||
private async Task<CommandResult> DeleteRouteAsync(Shared.ViewModels.RouteViewModel parameter) | ||
{ | ||
var result = await _windowService.ShowQuestionDialog( | ||
"Delete route?", | ||
$"Are you sure you want to delete the route {parameter.Name}?"); | ||
|
||
if (result == MessageBoxResult.No) | ||
{ | ||
return CommandResult.Aborted(); | ||
} | ||
|
||
try | ||
{ | ||
await _deleteRouteUseCase.ExecuteAsync(new DeleteRouteCommand(parameter.Uri, parameter.RepositoryName)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return CommandResult.Failure($"Failed to delete route: {e.Message}"); | ||
} | ||
|
||
return CommandResult.Success(); | ||
} | ||
|
||
public Task InitializeAsync() | ||
{ | ||
Repositories = _retrieveRepositoryNamesUseCase.Execute(new RetrieveRepositoryNamesCommand(RetrieveRepositoriesIntent.Manage)).ToImmutableList(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public ImmutableList<string> Repositories | ||
{ | ||
get => _repositories ?? ImmutableList<string>.Empty; | ||
set | ||
{ | ||
if (value == _repositories) | ||
{ | ||
return; | ||
} | ||
|
||
_repositories = value; | ||
this.RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
public string? SelectedRepository | ||
{ | ||
get => _selectedRepository; | ||
set | ||
{ | ||
if (value == _selectedRepository) | ||
{ | ||
return; | ||
} | ||
|
||
_selectedRepository = value; | ||
this.RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
public ImmutableList<Shared.ViewModels.RouteViewModel> Routes | ||
{ | ||
get => _routes ?? ImmutableList<Shared.ViewModels.RouteViewModel>.Empty; | ||
set | ||
{ | ||
if (_routes != null && value == _routes) | ||
{ | ||
return; | ||
} | ||
|
||
_routes = value; | ||
|
||
this.RaisePropertyChanged(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.