Skip to content

Instantly share code, notes, and snippets.

@ZadokJoshua
Created April 2, 2023 17:08
Show Gist options
  • Save ZadokJoshua/ac8caa801d0bbcf956e5b06b533a3acd to your computer and use it in GitHub Desktop.
Save ZadokJoshua/ac8caa801d0bbcf956e5b06b533a3acd to your computer and use it in GitHub Desktop.
using BooksTracker.Models;
using BooksTracker.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace BooksTracker.ViewModels;
[QueryProperty(nameof(Book), "BookObject")]
public partial class UpdateBookViewModel : ObservableObject
{
private readonly IDataService _dataService;
[ObservableProperty]
private Book _book;
public UpdateBookViewModel(IDataService dataService)
{
_dataService = dataService;
}
[RelayCommand]
private async Task UpdateBook()
{
if (!string.IsNullOrEmpty(Book.Title))
{
await _dataService.UpdateBook(Book);
await Shell.Current.GoToAsync("..");
}
else
{
await Shell.Current.DisplayAlert("Error", "No title!", "OK");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment