From 543b9c2aaf1e5ca0eb4513b4f6ab2deee046dcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 21 Aug 2025 17:18:35 +0200 Subject: [PATCH] Listviews of Products and users --- .../AdventureWorks.MAUI.csproj | 3 + AdventureWorks.MAUI/AppShell.xaml | 4 +- .../ProductViewModelCommands.cs | 26 ++++++ .../CommandClasses/UserViewModelCommands.cs | 53 +++++++++++ AdventureWorks.MAUI/MauiProgram.cs | 14 ++- .../Views/ProductListView.xaml | 49 ++++++++++ .../Views/ProductListView.xaml.cs | 24 +++++ AdventureWorks.MAUI/Views/UserDetailView.xaml | 40 ++++---- .../Views/UserDetailView.xaml.cs | 12 +-- AdventureWorks.MAUI/Views/UserListView.xaml | 53 +++++++++-- .../Views/UserListView.xaml.cs | 14 ++- .../ViewModelClasses/ProductViewModel.cs | 91 +++++++++++++++++++ .../ViewModelClasses/UserViewModel.cs | 16 ++++ 13 files changed, 358 insertions(+), 41 deletions(-) create mode 100644 AdventureWorks.MAUI/CommandClasses/ProductViewModelCommands.cs create mode 100644 AdventureWorks.MAUI/CommandClasses/UserViewModelCommands.cs create mode 100644 AdventureWorks.MAUI/Views/ProductListView.xaml create mode 100644 AdventureWorks.MAUI/Views/ProductListView.xaml.cs create mode 100644 AdventureWorks.ViewModelLayer/ViewModelClasses/ProductViewModel.cs diff --git a/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj b/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj index e4b34aa..594654d 100644 --- a/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj +++ b/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj @@ -99,6 +99,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile diff --git a/AdventureWorks.MAUI/AppShell.xaml b/AdventureWorks.MAUI/AppShell.xaml index 70b2b9b..df776a3 100644 --- a/AdventureWorks.MAUI/AppShell.xaml +++ b/AdventureWorks.MAUI/AppShell.xaml @@ -19,8 +19,8 @@ Route="UserListView" /> + ContentTemplate="{DataTemplate views:ProductListView}" + Route="ProductListView" /> repo) : base(repo) + { + } + #endregion + public void LoadProducts() + { + Get(); + } + public void LoadProductById(int id) + { + ProductObject = Get(id); + } + } +} diff --git a/AdventureWorks.MAUI/CommandClasses/UserViewModelCommands.cs b/AdventureWorks.MAUI/CommandClasses/UserViewModelCommands.cs new file mode 100644 index 0000000..78d693b --- /dev/null +++ b/AdventureWorks.MAUI/CommandClasses/UserViewModelCommands.cs @@ -0,0 +1,53 @@ +using AdventureWorks.EntityLayer; +using AdventureWorks.ViewModelLayer; +using Common.Library; +using System.Windows.Input; + +namespace AdventureWorks.MAUI.CommandClasses; + +public class UserViewModelCommands : UserViewModel +{ + #region constructors + public UserViewModelCommands() : base() + { + + } + public UserViewModelCommands(IRepository repo) : base(repo) + { + } + public UserViewModelCommands(IRepository repo, IRepository phoneRepo) : base(repo, phoneRepo) + { + } + #endregion + + #region Private Variables + private bool _IsSaveCommandEnabled = true; + #endregion + + #region Public Properties + public bool IsSaveCommandEnabled + { + get { return _IsSaveCommandEnabled; } + set + { + _IsSaveCommandEnabled = value; + RaisePropertyChanged(nameof(IsSaveCommandEnabled)); + } + } + #endregion + + #region Commands + public ICommand SaveCommand { get; private set; } + #endregion + + #region Init Method + public override void Init() + { + base.Init(); + SaveCommand = new Command(() => Save(), () => IsSaveCommandEnabled); + } + #endregion + +} + + diff --git a/AdventureWorks.MAUI/MauiProgram.cs b/AdventureWorks.MAUI/MauiProgram.cs index 34a7fa6..75b4f12 100644 --- a/AdventureWorks.MAUI/MauiProgram.cs +++ b/AdventureWorks.MAUI/MauiProgram.cs @@ -1,7 +1,7 @@ using AdventureWorks.DataLayer; using AdventureWorks.EntityLayer; +using AdventureWorks.MAUI.CommandClasses; using AdventureWorks.MAUI.Views; -using AdventureWorks.ViewModelLayer; using Common.Library; using Microsoft.Extensions.Logging; @@ -27,9 +27,17 @@ namespace AdventureWorks.MAUI builder.Services.AddScoped, UserRepository>(); builder.Services.AddScoped, ColorRepository>(); builder.Services.AddScoped, PhoneTypeRepository>(); - builder.Services.AddScoped(); + + builder.Services.AddScoped(); builder.Services.AddScoped(); -#if WINDOWS + builder.Services.AddScoped(); + + builder.Services.AddScoped, ProductRepository>(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + +#if XWINDOWS SetWindowOptions(builder); SetWindowHandlers(); #endif diff --git a/AdventureWorks.MAUI/Views/ProductListView.xaml b/AdventureWorks.MAUI/Views/ProductListView.xaml new file mode 100644 index 0000000..1bcdf04 --- /dev/null +++ b/AdventureWorks.MAUI/Views/ProductListView.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + +