From 8686272f4f01f78da85236b912aebb09aff579b8 Mon Sep 17 00:00:00 2001 From: Adrian Hall Date: Sun, 18 May 2025 08:56:28 -0700 Subject: [PATCH 1/3] (#341) Run dotnet outdated on samples. --- Directory.Packages.props | 8 ++++---- .../Sample.Datasync.Server.csproj | 16 ++++++++-------- .../TodoApp.Service/TodoApp.Service.csproj | 8 ++++---- .../todoapp-tutorial/ClientApp/ClientApp.csproj | 2 +- .../todoapp-tutorial/ServerApp/ServerApp.csproj | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 56e0d4c9..ac7e9527 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,9 +10,9 @@ - + - + @@ -20,9 +20,9 @@ - + - + diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj b/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj index 76b7ea2d..06b2470e 100644 --- a/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj +++ b/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj @@ -7,14 +7,14 @@ - - - - - - - - + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/todoapp-mvc/TodoApp.Service/TodoApp.Service.csproj b/samples/todoapp-mvc/TodoApp.Service/TodoApp.Service.csproj index 4fbb088f..154c87b1 100644 --- a/samples/todoapp-mvc/TodoApp.Service/TodoApp.Service.csproj +++ b/samples/todoapp-mvc/TodoApp.Service/TodoApp.Service.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/samples/todoapp-tutorial/ClientApp/ClientApp.csproj b/samples/todoapp-tutorial/ClientApp/ClientApp.csproj index bb904366..932370b6 100644 --- a/samples/todoapp-tutorial/ClientApp/ClientApp.csproj +++ b/samples/todoapp-tutorial/ClientApp/ClientApp.csproj @@ -9,7 +9,7 @@ - + diff --git a/samples/todoapp-tutorial/ServerApp/ServerApp.csproj b/samples/todoapp-tutorial/ServerApp/ServerApp.csproj index 3b630dd7..b3b1f2bf 100644 --- a/samples/todoapp-tutorial/ServerApp/ServerApp.csproj +++ b/samples/todoapp-tutorial/ServerApp/ServerApp.csproj @@ -7,8 +7,8 @@ - - + + From a2748bd2ae301d045f2057eaf2842185fafc8f15 Mon Sep 17 00:00:00 2001 From: Adrian Hall Date: Sun, 18 May 2025 12:46:53 -0700 Subject: [PATCH 2/3] (#341) Updated packages for todoapp --- .../TodoApp.Avalonia.Android.csproj | 6 +++--- .../TodoApp.Avalonia.Desktop.csproj | 6 +++--- .../TodoApp.Avalonia.iOS.csproj | 4 ++-- .../TodoApp.Avalonia/TodoApp.Avalonia.csproj | 16 ++++++++-------- samples/todoapp/TodoApp.MAUI/TodoApp.MAUI.csproj | 6 +++--- samples/todoapp/TodoApp.WPF/TodoApp.WPF.csproj | 2 +- .../todoapp/TodoApp.WinUI3/TodoApp.WinUI3.csproj | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Android/TodoApp.Avalonia.Android.csproj b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Android/TodoApp.Avalonia.Android.csproj index 5a7d5c52..70c8d49c 100644 --- a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Android/TodoApp.Avalonia.Android.csproj +++ b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Android/TodoApp.Avalonia.Android.csproj @@ -18,11 +18,11 @@ - - + + - + diff --git a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Desktop/TodoApp.Avalonia.Desktop.csproj b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Desktop/TodoApp.Avalonia.Desktop.csproj index 639fe2be..cd1eeae3 100644 --- a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Desktop/TodoApp.Avalonia.Desktop.csproj +++ b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Desktop/TodoApp.Avalonia.Desktop.csproj @@ -13,12 +13,12 @@ - + - + - + diff --git a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.iOS/TodoApp.Avalonia.iOS.csproj b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.iOS/TodoApp.Avalonia.iOS.csproj index 1f2c8ef4..fd463bcd 100644 --- a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.iOS/TodoApp.Avalonia.iOS.csproj +++ b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.iOS/TodoApp.Avalonia.iOS.csproj @@ -7,10 +7,10 @@ - + - + diff --git a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia/TodoApp.Avalonia.csproj b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia/TodoApp.Avalonia.csproj index 5183165e..cda4c5ce 100644 --- a/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia/TodoApp.Avalonia.csproj +++ b/samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia/TodoApp.Avalonia.csproj @@ -7,17 +7,17 @@ - + - - - + + + - - - - + + + + diff --git a/samples/todoapp/TodoApp.MAUI/TodoApp.MAUI.csproj b/samples/todoapp/TodoApp.MAUI/TodoApp.MAUI.csproj index ab34c60a..16cf5aa7 100644 --- a/samples/todoapp/TodoApp.MAUI/TodoApp.MAUI.csproj +++ b/samples/todoapp/TodoApp.MAUI/TodoApp.MAUI.csproj @@ -50,10 +50,10 @@ - + - - + + diff --git a/samples/todoapp/TodoApp.WPF/TodoApp.WPF.csproj b/samples/todoapp/TodoApp.WPF/TodoApp.WPF.csproj index aa575cda..9233af2b 100644 --- a/samples/todoapp/TodoApp.WPF/TodoApp.WPF.csproj +++ b/samples/todoapp/TodoApp.WPF/TodoApp.WPF.csproj @@ -20,6 +20,6 @@ - + diff --git a/samples/todoapp/TodoApp.WinUI3/TodoApp.WinUI3.csproj b/samples/todoapp/TodoApp.WinUI3/TodoApp.WinUI3.csproj index f995d303..131be158 100644 --- a/samples/todoapp/TodoApp.WinUI3/TodoApp.WinUI3.csproj +++ b/samples/todoapp/TodoApp.WinUI3/TodoApp.WinUI3.csproj @@ -29,13 +29,13 @@ - + - - - + + + From e841b2d8df2926f6d15cffc4d93d1ada7d458df9 Mon Sep 17 00:00:00 2001 From: Adrian Hall Date: Sun, 18 May 2025 12:58:40 -0700 Subject: [PATCH 3/3] (#341) Corrections to tutorial code --- docs/tutorial/client/part-1.md | 2 +- .../todoapp-tutorial/ClientApp/App.xaml.cs | 4 +- .../Converters/BooleanToImageConverter.cs | 4 + .../ClientApp/MainWindow.xaml | 2 +- .../ClientApp/ViewModels/TodoListViewModel.cs | 85 +++++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 samples/todoapp-tutorial/ClientApp/ViewModels/TodoListViewModel.cs diff --git a/docs/tutorial/client/part-1.md b/docs/tutorial/client/part-1.md index 69a74485..67fb057f 100644 --- a/docs/tutorial/client/part-1.md +++ b/docs/tutorial/client/part-1.md @@ -216,4 +216,4 @@ In the [next tutorial](./part-2.md), I'm going to talk about authenticating clie [todomvc]: https://github.com/CommunityToolkit/Datasync/tree/main/samples/todoapp-mvc [todoapp]: https://github.com/CommunityToolkit/Datasync/tree/main/samples/todoapp-tutorial [CommunityToolkit.MVVM]: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/ -[CommunityToolkit.Datasync.Client]: https://www.nuget.org/packages/CommunityToolkit.Datasync.Client#readme-body-tab \ No newline at end of file +[CommunityToolkit.Datasync.Client]: https://www.nuget.org/packages/CommunityToolkit.Datasync.Client#readme-body-tab diff --git a/samples/todoapp-tutorial/ClientApp/App.xaml.cs b/samples/todoapp-tutorial/ClientApp/App.xaml.cs index 99c87d2a..88610822 100644 --- a/samples/todoapp-tutorial/ClientApp/App.xaml.cs +++ b/samples/todoapp-tutorial/ClientApp/App.xaml.cs @@ -1,4 +1,4 @@ -using ClientApp.Interfaces; +using ClientApp.Interfaces; using ClientApp.Services; using ClientApp.ViewModels; using Microsoft.Extensions.DependencyInjection; @@ -29,7 +29,7 @@ private void InitializeApplication() { using IServiceScope scope = Services.CreateScope(); IAppInitializer initializer = scope.ServiceProvider.GetRequiredService(); - initializer.Initialize(); + _ = initializer.Initialize(); } /// diff --git a/samples/todoapp-tutorial/ClientApp/Converters/BooleanToImageConverter.cs b/samples/todoapp-tutorial/ClientApp/Converters/BooleanToImageConverter.cs index 6993ae71..4d6c53d2 100644 --- a/samples/todoapp-tutorial/ClientApp/Converters/BooleanToImageConverter.cs +++ b/samples/todoapp-tutorial/ClientApp/Converters/BooleanToImageConverter.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Globalization; using System.Windows.Data; using System.Windows.Media.Imaging; diff --git a/samples/todoapp-tutorial/ClientApp/MainWindow.xaml b/samples/todoapp-tutorial/ClientApp/MainWindow.xaml index 4255fae7..8767fcf4 100644 --- a/samples/todoapp-tutorial/ClientApp/MainWindow.xaml +++ b/samples/todoapp-tutorial/ClientApp/MainWindow.xaml @@ -1,4 +1,4 @@ - items = []; + + [ObservableProperty] + private string addItemTitle = string.Empty; + + [RelayCommand] + public async Task AddItemAsync(CancellationToken cancellationToken = default) + { + try + { + var addition = await todoService.AddTodoItemAsync(AddItemTitle, cancellationToken); + Items.Add(addition); + AddItemTitle = string.Empty; + } + catch (Exception ex) + { + await alertService.ShowErrorAlertAsync("Error adding item", ex.Message); + } + } + + [RelayCommand] + public async Task UpdateItemAsync(TodoItem item, CancellationToken cancellationToken = default) + { + try + { + TodoItem? storedItem = await todoService.GetTodoItemAsync(item.Id, cancellationToken); + if (storedItem is not null) + { + storedItem.IsComplete = !storedItem.IsComplete; + var replacedItem = await todoService.ReplaceTodoItemAsync(storedItem, cancellationToken); + var idx = Items.IndexOf(item); + Items[idx] = replacedItem; + } + else + { + await alertService.ShowErrorAlertAsync("Item not found", "The item was not found in the database."); + } + } + catch (Exception ex) + { + await alertService.ShowErrorAlertAsync("Error updating item", ex.Message); + } + } + + [RelayCommand] + public async Task RefreshItemsAsync(CancellationToken cancellationToken = default) + { + try + { + IsRefreshing = true; + List dbItems = await todoService.GetAllTodoItemsAsync(cancellationToken); + Items.Clear(); + foreach (var dbItem in dbItems) + { + Items.Add(dbItem); + } + } + catch (Exception ex) + { + await alertService.ShowErrorAlertAsync("Error refreshing items", ex.Message); + } + finally + { + IsRefreshing = false; + } + } +} \ No newline at end of file