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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AdventureWorks.MAUI/Views/ProductListView.xaml.cs b/AdventureWorks.MAUI/Views/ProductListView.xaml.cs
new file mode 100644
index 0000000..a1a75c4
--- /dev/null
+++ b/AdventureWorks.MAUI/Views/ProductListView.xaml.cs
@@ -0,0 +1,24 @@
+using AdventureWorks.MAUI.CommandClasses;
+
+namespace AdventureWorks.MAUI.Views;
+
+public partial class ProductListView : ContentPage
+{
+ public ProductListView(ProductViewModelCommands viewModel)
+ {
+ InitializeComponent();
+ ViewModel = viewModel;
+ }
+
+ private readonly ProductViewModelCommands ViewModel;
+
+
+ protected override void OnAppearing()
+ {
+ base.OnAppearing();
+ BindingContext = ViewModel;
+ ViewModel.Get();
+ }
+
+
+}
\ No newline at end of file
diff --git a/AdventureWorks.MAUI/Views/UserDetailView.xaml b/AdventureWorks.MAUI/Views/UserDetailView.xaml
index 351ddff..43ed546 100644
--- a/AdventureWorks.MAUI/Views/UserDetailView.xaml
+++ b/AdventureWorks.MAUI/Views/UserDetailView.xaml
@@ -4,8 +4,8 @@
x:Class="AdventureWorks.MAUI.Views.UserDetailView"
xmlns:partial="clr-namespace:AdventureWorks.MAUI.ViewsPartial"
xmlns:converters="clr-namespace:AdventureWorks.MAUI.Converters"
- xmlns:vm="clr-namespace:AdventureWorks.ViewModelLayer;assembly=AdventureWorks.ViewModelLayer"
- x:DataType="vm:UserViewModel"
+ xmlns:vm="clr-namespace:AdventureWorks.MAUI.CommandClasses"
+ x:DataType="vm:UserViewModelCommands"
Title="User Information">
@@ -53,18 +53,20 @@
Text="First Name" />
+ Text="{Binding UserObject.FirstName}" />
+ Text="{Binding UserObject.LastName}" />
-
+ Text="{Binding UserObject.Email}" />
+
+
+ Text="Still Employed" />
+ Grid.Row="7" />
-
+
+ GroupName="EmployeeType" />
-
-
+
+
+ Grid.Row="8" />
+ HorizontalOptions="Start" />
+ Grid.Row="9" />
+ Grid.Row="10" />
+ Text="{Binding UserObject.Phone}" />
-
+
diff --git a/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs b/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs
index ebe9844..375262f 100644
--- a/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs
+++ b/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs
@@ -1,15 +1,16 @@
-using AdventureWorks.ViewModelLayer;
+using AdventureWorks.MAUI.CommandClasses;
+
namespace AdventureWorks.MAUI.Views;
public partial class UserDetailView : ContentPage
{
- public UserDetailView(UserViewModel viewModel)
+ public UserDetailView(UserViewModelCommands viewModel)
{
InitializeComponent();
ViewModel = viewModel;
}
- public UserViewModel ViewModel { get; set; }
+ public UserViewModelCommands ViewModel { get; set; }
protected override void OnAppearing()
{
@@ -21,8 +22,5 @@ public partial class UserDetailView : ContentPage
ViewModel.Get(1); // Assuming you want to get the user with ID 1
}
- private void SaveButton_Clicked(object sender, EventArgs e)
- {
- System.Diagnostics.Debugger.Break();
- }
+
}
\ No newline at end of file
diff --git a/AdventureWorks.MAUI/Views/UserListView.xaml b/AdventureWorks.MAUI/Views/UserListView.xaml
index 2dfca07..99aa408 100644
--- a/AdventureWorks.MAUI/Views/UserListView.xaml
+++ b/AdventureWorks.MAUI/Views/UserListView.xaml
@@ -1,16 +1,49 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AdventureWorks.MAUI/Views/UserListView.xaml.cs b/AdventureWorks.MAUI/Views/UserListView.xaml.cs
index 02c74d5..d1d225d 100644
--- a/AdventureWorks.MAUI/Views/UserListView.xaml.cs
+++ b/AdventureWorks.MAUI/Views/UserListView.xaml.cs
@@ -1,10 +1,22 @@
+using AdventureWorks.MAUI.CommandClasses;
+
namespace AdventureWorks.MAUI.Views;
public partial class UserListView : ContentPage
{
- public UserListView()
+ public UserListView(UserViewModelCommands viewModel)
{
InitializeComponent();
+ ViewModel = viewModel;
+ }
+
+ private readonly UserViewModelCommands ViewModel;
+
+ protected override void OnAppearing()
+ {
+ base.OnAppearing();
+ BindingContext = ViewModel;
+ ViewModel.Get();
}
private async void NavigateToDetail_Clicked(object sender, EventArgs e)
diff --git a/AdventureWorks.ViewModelLayer/ViewModelClasses/ProductViewModel.cs b/AdventureWorks.ViewModelLayer/ViewModelClasses/ProductViewModel.cs
new file mode 100644
index 0000000..2344583
--- /dev/null
+++ b/AdventureWorks.ViewModelLayer/ViewModelClasses/ProductViewModel.cs
@@ -0,0 +1,91 @@
+using AdventureWorks.EntityLayer;
+using Common.Library;
+using System.Collections.ObjectModel;
+
+namespace AdventureWorks.ViewModelLayer.ViewModelClasses;
+
+public class ProductViewModel : ViewModelBase
+{
+ #region Constructors
+ public ProductViewModel() : base()
+ {
+ }
+ public ProductViewModel(IRepository repo) : base()
+ {
+ Repository = repo;
+ }
+ #endregion
+
+ #region Private Variables
+ private Product? _ProductObject = new();
+ private ObservableCollection _ProductList = new();
+ private readonly IRepository? Repository;
+ #endregion
+
+ #region Public Properties
+ public Product? ProductObject
+ {
+ get { return _ProductObject; }
+ set
+ {
+ _ProductObject = value;
+ RaisePropertyChanged(nameof(ProductObject));
+ }
+ }
+ public ObservableCollection ProductList
+ {
+ get { return _ProductList; }
+ set
+ {
+ _ProductList = value;
+ RaisePropertyChanged(nameof(ProductList));
+ }
+ }
+ #endregion
+
+ public ObservableCollection Get()
+ {
+ if (Repository != null)
+ {
+ ProductList = new ObservableCollection(Repository.Get());
+ }
+ return ProductList;
+ }
+
+ public Product Get(int id)
+ {
+ try
+ {
+ if (Repository != null)
+ {
+ ProductObject = Repository.Get(id);
+ }
+ else
+ {
+ ProductObject = new Product
+ {
+ ProductID = id,
+ Name = "A new product",
+ Color = "Black",
+ StandardCost = 10,
+ ListPrice = 20,
+ SellStartDate = Convert.ToDateTime("2020-10-15"),
+ Size = "LG"
+ };
+ }
+
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
+ return ProductObject;
+ }
+
+ public bool Save()
+ {
+ throw new NotImplementedException("Save method is not implemented yet.");
+ }
+
+}
diff --git a/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs b/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs
index 4a81d01..10e0bca 100644
--- a/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs
+++ b/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs
@@ -25,6 +25,7 @@ public class UserViewModel : ViewModelBase
#region Private Variables
private User? _UserObject = new();
+ private ObservableCollection _UserList = new();
private readonly IRepository? Repository;
private readonly IRepository? _PhoneTypeRepository;
private ObservableCollection _PhoneTypesList = new();
@@ -43,6 +44,16 @@ public class UserViewModel : ViewModelBase
}
+ public ObservableCollection UserList
+ {
+ get { return _UserList; }
+ set
+ {
+ _UserList = value;
+ RaisePropertyChanged(nameof(UserList));
+ }
+ }
+
public ObservableCollection PhoneTypesList
{
get { return _PhoneTypesList; }
@@ -59,6 +70,11 @@ public class UserViewModel : ViewModelBase
#region Get Method
public ObservableCollection Get()
{
+ if (Repository != null)
+ {
+ UserList = new ObservableCollection(Repository.Get());
+ }
+
return new();
}