From 1649eaa992e421e1e0083d402c87002890e81173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 20 Aug 2025 12:08:46 +0200 Subject: [PATCH] Using dependency injection and viewmodel etc --- .../AdventureWorks.DataLayer.csproj | 14 + .../DataClasses/ColorRepository.cs | 75 +++ .../DataClasses/PhoneTypeRepository.cs | 51 ++ .../DataClasses/ProductRepository.cs | 519 ++++++++++++++++++ .../DataClasses/UserRepository.cs | 163 ++++++ .../EntityClasses/Color.cs | 33 ++ .../EntityClasses/PhoneType.cs | 32 ++ .../EntityClasses/Product.cs | 152 +++++ AdventureWorks.MAUI.sln | 6 + .../AdventureWorks.MAUI.csproj | 1 + AdventureWorks.MAUI/App.xaml | 5 - AdventureWorks.MAUI/MauiProgram.cs | 14 +- AdventureWorks.MAUI/Views/UserDetailView.xaml | 2 +- .../Views/UserDetailView.xaml.cs | 8 +- .../AdventureWorks.ViewModelLayer.csproj | 1 + .../ViewModelClasses/UserViewModel.cs | 88 ++- Common.Library/Interfaces/IRepository.cs | 10 + 17 files changed, 1143 insertions(+), 31 deletions(-) create mode 100644 AdventureWorks.DataLayer/AdventureWorks.DataLayer.csproj create mode 100644 AdventureWorks.DataLayer/DataClasses/ColorRepository.cs create mode 100644 AdventureWorks.DataLayer/DataClasses/PhoneTypeRepository.cs create mode 100644 AdventureWorks.DataLayer/DataClasses/ProductRepository.cs create mode 100644 AdventureWorks.DataLayer/DataClasses/UserRepository.cs create mode 100644 AdventureWorks.EntityLayer/EntityClasses/Color.cs create mode 100644 AdventureWorks.EntityLayer/EntityClasses/PhoneType.cs create mode 100644 AdventureWorks.EntityLayer/EntityClasses/Product.cs create mode 100644 Common.Library/Interfaces/IRepository.cs diff --git a/AdventureWorks.DataLayer/AdventureWorks.DataLayer.csproj b/AdventureWorks.DataLayer/AdventureWorks.DataLayer.csproj new file mode 100644 index 0000000..72b9661 --- /dev/null +++ b/AdventureWorks.DataLayer/AdventureWorks.DataLayer.csproj @@ -0,0 +1,14 @@ + + + + net9.0 + enable + enable + + + + + + + + diff --git a/AdventureWorks.DataLayer/DataClasses/ColorRepository.cs b/AdventureWorks.DataLayer/DataClasses/ColorRepository.cs new file mode 100644 index 0000000..19abdd9 --- /dev/null +++ b/AdventureWorks.DataLayer/DataClasses/ColorRepository.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using AdventureWorks.EntityLayer; +using Common.Library; + +namespace AdventureWorks.DataLayer; + +/// +/// This class creates some fake data for Colors. +/// +public partial class ColorRepository : IRepository +{ + #region Get Method + /// + /// Get all Color objects + /// + /// A list of Color objects + public ObservableCollection Get() + { + return new ObservableCollection + { + new AdventureWorks.EntityLayer.Color { + ColorId = 1, + ColorName = "Black", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 2, + ColorName = "Blue", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 3, + ColorName = "Gray", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 4, + ColorName = "Multi", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 5, + ColorName = "Red", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 6, + ColorName = "Silver", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 7, + ColorName = "Silver/Black", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 8, + ColorName = "White", + }, + new AdventureWorks.EntityLayer.Color { + ColorId = 9, + ColorName = "Yellow", + } + }; + } + #endregion + + #region Get(id) Method + /// + /// Get a single Color object + /// + /// The value to locate + /// A valid Color object object, or null if not found + public AdventureWorks.EntityLayer.Color? Get(int id) + { + return Get().Where(row => row.ColorId == id).FirstOrDefault(); + } + #endregion +} \ No newline at end of file diff --git a/AdventureWorks.DataLayer/DataClasses/PhoneTypeRepository.cs b/AdventureWorks.DataLayer/DataClasses/PhoneTypeRepository.cs new file mode 100644 index 0000000..cb309ad --- /dev/null +++ b/AdventureWorks.DataLayer/DataClasses/PhoneTypeRepository.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using AdventureWorks.EntityLayer; +using Common.Library; + +namespace AdventureWorks.DataLayer; + +/// +/// This class creates some fake data for Phone Types. +/// +public partial class PhoneTypeRepository : IRepository +{ + #region Get Method + /// + /// Get all PhoneType objects + /// + /// A list of PhoneType objects + public ObservableCollection Get() + { + return new ObservableCollection + { + new PhoneType { + PhoneTypeId = 1, + TypeDescription = "Home", + }, + new PhoneType { + PhoneTypeId = 2, + TypeDescription = "Mobile", + }, + new PhoneType { + PhoneTypeId = 3, + TypeDescription = "Other", + } + }; + } + #endregion + + #region Get(id) Method + /// + /// Get a single PhoneType object + /// + /// The value to locate + /// A valid PhoneType object object, or null if not found + public PhoneType? Get(int id) + { + return Get().Where(row => row.PhoneTypeId == id).FirstOrDefault(); + } + #endregion +} \ No newline at end of file diff --git a/AdventureWorks.DataLayer/DataClasses/ProductRepository.cs b/AdventureWorks.DataLayer/DataClasses/ProductRepository.cs new file mode 100644 index 0000000..1962499 --- /dev/null +++ b/AdventureWorks.DataLayer/DataClasses/ProductRepository.cs @@ -0,0 +1,519 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using AdventureWorks.EntityLayer; +using Common.Library; + +namespace AdventureWorks.DataLayer; + +/// +/// This class creates some fake data for Products. +/// +public partial class ProductRepository : IRepository +{ + #region Get Method + /// + /// Get all Product objects + /// + /// A list of Product objects + public ObservableCollection Get() + { + return new ObservableCollection + { + new Product { + ProductID = 680, + Name = @"HL Road Frame - Black, 58", + ProductNumber = @"FR-R92B-58", + Color = @"Black", + StandardCost = 1059.3100m, + ListPrice = 1431.5000m, + Size = @"58", + Weight = 1016.04m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("6/1/2002 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 706, + Name = @"HL Road Frame - Red, 58", + ProductNumber = @"FR-R92R-58", + Color = @"Red", + StandardCost = 1059.3100m, + ListPrice = 1431.5000m, + Size = @"58", + Weight = 1016.04m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("6/1/2002 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 707, + Name = @"Sport-100 Helmet, Red", + ProductNumber = @"HL-U509-R", + Color = @"Red", + StandardCost = 13.0863m, + ListPrice = 34.9900m, + Size = string.Empty, + Weight = null, + ProductCategoryID = 35, + ProductModelID = 33, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 708, + Name = @"Sport-100 Helmet, Black", + ProductNumber = @"HL-U509", + Color = @"Black", + StandardCost = 13.0863m, + ListPrice = 34.9900m, + Size = string.Empty, + Weight = null, + ProductCategoryID = 35, + ProductModelID = 33, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 709, + Name = @"Mountain Bike Socks, M", + ProductNumber = @"SO-B909-M", + Color = @"White", + StandardCost = 3.3963m, + ListPrice = 9.5000m, + Size = @"M", + Weight = null, + ProductCategoryID = 27, + ProductModelID = 18, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2006 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 710, + Name = @"Mountain Bike Socks, L", + ProductNumber = @"SO-B909-L", + Color = @"White", + StandardCost = 3.3963m, + ListPrice = 9.5000m, + Size = @"L", + Weight = null, + ProductCategoryID = 27, + ProductModelID = 18, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2006 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 711, + Name = @"Sport-100 Helmet, Blue", + ProductNumber = @"HL-U509-B", + Color = @"Blue", + StandardCost = 13.0863m, + ListPrice = 34.9900m, + Size = string.Empty, + Weight = null, + ProductCategoryID = 35, + ProductModelID = 33, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 712, + Name = @"AWC Logo Cap", + ProductNumber = @"CA-1098", + Color = @"Multi", + StandardCost = 6.9223m, + ListPrice = 8.9900m, + Size = string.Empty, + Weight = null, + ProductCategoryID = 23, + ProductModelID = 2, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 713, + Name = @"Long-Sleeve Logo Jersey, S", + ProductNumber = @"LJ-0192-S", + Color = @"Multi", + StandardCost = 38.4923m, + ListPrice = 49.9900m, + Size = @"S", + Weight = null, + ProductCategoryID = 25, + ProductModelID = 11, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 714, + Name = @"Long-Sleeve Logo Jersey, M", + ProductNumber = @"LJ-0192-M", + Color = @"Multi", + StandardCost = 38.4923m, + ListPrice = 49.9900m, + Size = @"M", + Weight = null, + ProductCategoryID = 25, + ProductModelID = 11, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 715, + Name = @"Long-Sleeve Logo Jersey, L", + ProductNumber = @"LJ-0192-L", + Color = @"Multi", + StandardCost = 38.4923m, + ListPrice = 49.9900m, + Size = @"L", + Weight = null, + ProductCategoryID = 25, + ProductModelID = 11, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 716, + Name = @"Long-Sleeve Logo Jersey, XL", + ProductNumber = @"LJ-0192-X", + Color = @"Multi", + StandardCost = 38.4923m, + ListPrice = 49.9900m, + Size = @"XL", + Weight = null, + ProductCategoryID = 25, + ProductModelID = 11, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 717, + Name = @"HL Road Frame - Red, 62", + ProductNumber = @"FR-R92R-62", + Color = @"Red", + StandardCost = 868.6342m, + ListPrice = 1431.5000m, + Size = @"62", + Weight = 1043.26m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 718, + Name = @"HL Road Frame - Red, 44", + ProductNumber = @"FR-R92R-44", + Color = @"Red", + StandardCost = 868.6342m, + ListPrice = 1431.5000m, + Size = @"44", + Weight = 961.61m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 719, + Name = @"HL Road Frame - Red, 48", + ProductNumber = @"FR-R92R-48", + Color = @"Red", + StandardCost = 868.6342m, + ListPrice = 1431.5000m, + Size = @"48", + Weight = 979.75m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 720, + Name = @"HL Road Frame - Red, 52", + ProductNumber = @"FR-R92R-52", + Color = @"Red", + StandardCost = 868.6342m, + ListPrice = 1431.5000m, + Size = @"52", + Weight = 997.90m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 721, + Name = @"HL Road Frame - Red, 56", + ProductNumber = @"FR-R92R-56", + Color = @"Red", + StandardCost = 868.6342m, + ListPrice = 1431.5000m, + Size = @"56", + Weight = 1016.04m, + ProductCategoryID = 18, + ProductModelID = 6, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 722, + Name = @"LL Road Frame - Black, 58", + ProductNumber = @"FR-R38B-58", + Color = @"Black", + StandardCost = 204.6251m, + ListPrice = 337.2200m, + Size = @"58", + Weight = 1115.83m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 723, + Name = @"LL Road Frame - Black, 60", + ProductNumber = @"FR-R38B-60", + Color = @"Black", + StandardCost = 204.6251m, + ListPrice = 337.2200m, + Size = @"60", + Weight = 1124.90m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 724, + Name = @"LL Road Frame - Black, 62", + ProductNumber = @"FR-R38B-62", + Color = @"Black", + StandardCost = 204.6251m, + ListPrice = 337.2200m, + Size = @"62", + Weight = 1133.98m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = null, + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 725, + Name = @"LL Road Frame - Red, 44", + ProductNumber = @"FR-R38R-44", + Color = @"Red", + StandardCost = 187.1571m, + ListPrice = 337.2200m, + Size = @"44", + Weight = 1052.33m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2007 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 726, + Name = @"LL Road Frame - Red, 48", + ProductNumber = @"FR-R38R-48", + Color = @"Red", + StandardCost = 187.1571m, + ListPrice = 337.2200m, + Size = @"48", + Weight = 1070.47m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2007 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 727, + Name = @"LL Road Frame - Red, 52", + ProductNumber = @"FR-R38R-52", + Color = @"Red", + StandardCost = 187.1571m, + ListPrice = 337.2200m, + Size = @"52", + Weight = 1088.62m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2007 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 728, + Name = @"LL Road Frame - Red, 58", + ProductNumber = @"FR-R38R-58", + Color = @"Red", + StandardCost = 187.1571m, + ListPrice = 337.2200m, + Size = @"58", + Weight = 1115.83m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2007 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 729, + Name = @"LL Road Frame - Red, 60", + ProductNumber = @"FR-R38R-60", + Color = @"Red", + StandardCost = 187.1571m, + ListPrice = 337.2200m, + Size = @"60", + Weight = 1124.90m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2007 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 730, + Name = @"LL Road Frame - Red, 62", + ProductNumber = @"FR-R38R-62", + Color = @"Red", + StandardCost = 187.1571m, + ListPrice = 337.2200m, + Size = @"62", + Weight = 1133.98m, + ProductCategoryID = 18, + ProductModelID = 9, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2007 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 731, + Name = @"ML Road Frame - Red, 44", + ProductNumber = @"FR-R72R-44", + Color = @"Red", + StandardCost = 352.1394m, + ListPrice = 594.8300m, + Size = @"44", + Weight = 1006.97m, + ProductCategoryID = 18, + ProductModelID = 16, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2006 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 732, + Name = @"ML Road Frame - Red, 48", + ProductNumber = @"FR-R72R-48", + Color = @"Red", + StandardCost = 352.1394m, + ListPrice = 594.8300m, + Size = @"48", + Weight = 1025.11m, + ProductCategoryID = 18, + ProductModelID = 16, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2006 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 733, + Name = @"ML Road Frame - Red, 52", + ProductNumber = @"FR-R72R-52", + Color = @"Red", + StandardCost = 352.1394m, + ListPrice = 594.8300m, + Size = @"52", + Weight = 1043.26m, + ProductCategoryID = 18, + ProductModelID = 16, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2006 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + }, + new Product { + ProductID = 734, + Name = @"ML Road Frame - Red, 58", + ProductNumber = @"FR-R72R-58", + Color = @"Red", + StandardCost = 352.1394m, + ListPrice = 594.8300m, + Size = @"58", + Weight = 1070.47m, + ProductCategoryID = 18, + ProductModelID = 16, + SellStartDate = Convert.ToDateTime("7/1/2005 12:00:00 AM"), + SellEndDate = Convert.ToDateTime("6/30/2006 12:00:00 AM"), + DiscontinuedDate = null, + ModifiedDate = Convert.ToDateTime("3/11/2008 10:01:36 AM"), + } + }; + } + #endregion + + #region Get(id) Method + /// + /// Get a single Product object + /// + /// The value to locate + /// A valid Product object object, or null if not found + public Product? Get(int id) + { + return Get().Where(row => row.ProductID == id).FirstOrDefault(); + } + #endregion +} \ No newline at end of file diff --git a/AdventureWorks.DataLayer/DataClasses/UserRepository.cs b/AdventureWorks.DataLayer/DataClasses/UserRepository.cs new file mode 100644 index 0000000..65b1c94 --- /dev/null +++ b/AdventureWorks.DataLayer/DataClasses/UserRepository.cs @@ -0,0 +1,163 @@ +using AdventureWorks.EntityLayer; +using Common.Library; +using System.Collections.ObjectModel; + +namespace AdventureWorks.DataLayer; + +public partial class UserRepository : IRepository +{ + #region Get Method + public ObservableCollection Get() + { + // This method should return a collection of User objects. + // For now, returning an empty collection. + return new ObservableCollection() + { + new User + { + UserId = 1, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + }, + + new User + { + UserId = 2, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + }, + + new User + { + UserId = 3, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + }, + new User + { + UserId = 3, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + }, + new User + { + UserId = 4, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + }, + new User + { + UserId = 5, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + }, + new User + { + UserId = 6, + LoginId = @"SallyJones615", + FirstName = @"Sally", + LastName = @"Jones", + Email = @"sally@jones.com", + Password = @"password123", + Phone = @"555-1234", + PhoneType = @"Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + } + + + + + }; + } + + public User? Get(int id) + { + return Get().Where(row => row.UserId == id).FirstOrDefault(); + } + #endregion +} diff --git a/AdventureWorks.EntityLayer/EntityClasses/Color.cs b/AdventureWorks.EntityLayer/EntityClasses/Color.cs new file mode 100644 index 0000000..4a73fa5 --- /dev/null +++ b/AdventureWorks.EntityLayer/EntityClasses/Color.cs @@ -0,0 +1,33 @@ +using System; +using Common.Library; + +namespace AdventureWorks.EntityLayer; + +public class Color : EntityBase +{ + #region Private Variables + private int _ColorId; + private string _ColorName = string.Empty; + #endregion + + #region Public Properties + public int ColorId + { + get { return _ColorId; } + set + { + _ColorId = value; + RaisePropertyChanged(nameof(ColorId)); + } + } + + public string ColorName + { + get { return _ColorName; } + set { + _ColorName = value; + RaisePropertyChanged(nameof(ColorName)); + } + } + #endregion +} \ No newline at end of file diff --git a/AdventureWorks.EntityLayer/EntityClasses/PhoneType.cs b/AdventureWorks.EntityLayer/EntityClasses/PhoneType.cs new file mode 100644 index 0000000..bd2ba45 --- /dev/null +++ b/AdventureWorks.EntityLayer/EntityClasses/PhoneType.cs @@ -0,0 +1,32 @@ +using System; +using Common.Library; + +namespace AdventureWorks.EntityLayer; + +public class PhoneType : EntityBase +{ + #region Private Variables + private int _PhoneTypeId; + private string _TypeDescription = string.Empty; + #endregion + + #region Public Properties + public int PhoneTypeId + { + get { return _PhoneTypeId; } + set { + _PhoneTypeId = value; + RaisePropertyChanged(nameof(PhoneTypeId)); + } + } + + public string TypeDescription + { + get { return _TypeDescription; } + set { + _TypeDescription = value; + RaisePropertyChanged(nameof(TypeDescription)); + } + } + #endregion +} \ No newline at end of file diff --git a/AdventureWorks.EntityLayer/EntityClasses/Product.cs b/AdventureWorks.EntityLayer/EntityClasses/Product.cs new file mode 100644 index 0000000..59de2d7 --- /dev/null +++ b/AdventureWorks.EntityLayer/EntityClasses/Product.cs @@ -0,0 +1,152 @@ +using System; +using Common.Library; + +namespace AdventureWorks.EntityLayer; + +public partial class Product : EntityBase +{ + #region Private Variables + private int _ProductID; + private string _Name = string.Empty; + private string _ProductNumber = string.Empty; + private string _Color = string.Empty; + private decimal _StandardCost; + private decimal _ListPrice; + private string _Size = string.Empty; + private decimal? _Weight; + private int? _ProductCategoryID; + private int? _ProductModelID; + private DateTime _SellStartDate; + private DateTime? _SellEndDate; + private DateTime? _DiscontinuedDate; + private DateTime _ModifiedDate; + #endregion + + #region Public Properties + public int ProductID + { + get { return _ProductID; } + set { + _ProductID = value; + RaisePropertyChanged(nameof(ProductID)); + } + } + + public string Name + { + get { return _Name; } + set { + _Name = value; + RaisePropertyChanged(nameof(Name)); + } + } + + public string ProductNumber + { + get { return _ProductNumber; } + set { + _ProductNumber = value; + RaisePropertyChanged(nameof(ProductNumber)); + } + } + + public string Color + { + get { return _Color; } + set { + _Color = value; + RaisePropertyChanged(nameof(Color)); + } + } + + public decimal StandardCost + { + get { return _StandardCost; } + set { + _StandardCost = value; + RaisePropertyChanged(nameof(StandardCost)); + } + } + + public decimal ListPrice + { + get { return _ListPrice; } + set { + _ListPrice = value; + RaisePropertyChanged(nameof(ListPrice)); + } + } + + public string Size + { + get { return _Size; } + set { + _Size = value; + RaisePropertyChanged(nameof(Size)); + } + } + + public decimal? Weight + { + get { return _Weight; } + set { + _Weight = value; + RaisePropertyChanged(nameof(Weight)); + } + } + + public int? ProductCategoryID + { + get { return _ProductCategoryID; } + set { + _ProductCategoryID = value; + RaisePropertyChanged(nameof(ProductCategoryID)); + } + } + + public int? ProductModelID + { + get { return _ProductModelID; } + set { + _ProductModelID = value; + RaisePropertyChanged(nameof(ProductModelID)); + } + } + + public DateTime SellStartDate + { + get { return _SellStartDate; } + set { + _SellStartDate = value; + RaisePropertyChanged(nameof(SellStartDate)); + } + } + + public DateTime? SellEndDate + { + get { return _SellEndDate; } + set { + _SellEndDate = value; + RaisePropertyChanged(nameof(SellEndDate)); + } + } + + public DateTime? DiscontinuedDate + { + get { return _DiscontinuedDate; } + set { + _DiscontinuedDate = value; + RaisePropertyChanged(nameof(DiscontinuedDate)); + } + } + + public DateTime ModifiedDate + { + get { return _ModifiedDate; } + set { + _ModifiedDate = value; + RaisePropertyChanged(nameof(ModifiedDate)); + } + } + #endregion +} \ No newline at end of file diff --git a/AdventureWorks.MAUI.sln b/AdventureWorks.MAUI.sln index 485093d..e7cf121 100644 --- a/AdventureWorks.MAUI.sln +++ b/AdventureWorks.MAUI.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Library", "Common.Li EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventureWorks.ViewModelLayer", "AdventureWorks.ViewModelLayer\AdventureWorks.ViewModelLayer.csproj", "{3E3C685B-CA66-4E12-83BC-B872BC5FD933}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventureWorks.DataLayer", "AdventureWorks.DataLayer\AdventureWorks.DataLayer.csproj", "{BE1C17A0-A605-451E-822D-230216754875}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,6 +36,10 @@ Global {3E3C685B-CA66-4E12-83BC-B872BC5FD933}.Debug|Any CPU.Build.0 = Debug|Any CPU {3E3C685B-CA66-4E12-83BC-B872BC5FD933}.Release|Any CPU.ActiveCfg = Release|Any CPU {3E3C685B-CA66-4E12-83BC-B872BC5FD933}.Release|Any CPU.Build.0 = Release|Any CPU + {BE1C17A0-A605-451E-822D-230216754875}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE1C17A0-A605-451E-822D-230216754875}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE1C17A0-A605-451E-822D-230216754875}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE1C17A0-A605-451E-822D-230216754875}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj b/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj index 7cc1bff..e4b34aa 100644 --- a/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj +++ b/AdventureWorks.MAUI/AdventureWorks.MAUI.csproj @@ -65,6 +65,7 @@ + diff --git a/AdventureWorks.MAUI/App.xaml b/AdventureWorks.MAUI/App.xaml index 0ff7012..26e5dbc 100644 --- a/AdventureWorks.MAUI/App.xaml +++ b/AdventureWorks.MAUI/App.xaml @@ -5,11 +5,6 @@ x:Class="AdventureWorks.MAUI.App"> - - Home - Mobile - Other - diff --git a/AdventureWorks.MAUI/MauiProgram.cs b/AdventureWorks.MAUI/MauiProgram.cs index 6658fcd..34a7fa6 100644 --- a/AdventureWorks.MAUI/MauiProgram.cs +++ b/AdventureWorks.MAUI/MauiProgram.cs @@ -1,4 +1,9 @@ -using Microsoft.Extensions.Logging; +using AdventureWorks.DataLayer; +using AdventureWorks.EntityLayer; +using AdventureWorks.MAUI.Views; +using AdventureWorks.ViewModelLayer; +using Common.Library; +using Microsoft.Extensions.Logging; //#if Windows using Microsoft.Maui.LifecycleEvents; @@ -18,7 +23,12 @@ namespace AdventureWorks.MAUI fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); - + //DI Services + builder.Services.AddScoped, UserRepository>(); + builder.Services.AddScoped, ColorRepository>(); + builder.Services.AddScoped, PhoneTypeRepository>(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); #if WINDOWS SetWindowOptions(builder); SetWindowHandlers(); diff --git a/AdventureWorks.MAUI/Views/UserDetailView.xaml b/AdventureWorks.MAUI/Views/UserDetailView.xaml index b88c88d..351ddff 100644 --- a/AdventureWorks.MAUI/Views/UserDetailView.xaml +++ b/AdventureWorks.MAUI/Views/UserDetailView.xaml @@ -135,7 +135,7 @@ Text="{Binding UserObject.Phone}"/> - diff --git a/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs b/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs index bb9d695..ebe9844 100644 --- a/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs +++ b/AdventureWorks.MAUI/Views/UserDetailView.xaml.cs @@ -3,10 +3,10 @@ namespace AdventureWorks.MAUI.Views; public partial class UserDetailView : ContentPage { - public UserDetailView() + public UserDetailView(UserViewModel viewModel) { InitializeComponent(); - + ViewModel = viewModel; } public UserViewModel ViewModel { get; set; } @@ -15,10 +15,10 @@ public partial class UserDetailView : ContentPage { base.OnAppearing(); - ViewModel = new(); - BindingContext = ViewModel; + ViewModel.GetPhoneTypes(); + ViewModel.Get(1); // Assuming you want to get the user with ID 1 } private void SaveButton_Clicked(object sender, EventArgs e) diff --git a/AdventureWorks.ViewModelLayer/AdventureWorks.ViewModelLayer.csproj b/AdventureWorks.ViewModelLayer/AdventureWorks.ViewModelLayer.csproj index 72b9661..138bf4c 100644 --- a/AdventureWorks.ViewModelLayer/AdventureWorks.ViewModelLayer.csproj +++ b/AdventureWorks.ViewModelLayer/AdventureWorks.ViewModelLayer.csproj @@ -7,6 +7,7 @@ + diff --git a/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs b/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs index 4d69bec..4a81d01 100644 --- a/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs +++ b/AdventureWorks.ViewModelLayer/ViewModelClasses/UserViewModel.cs @@ -6,8 +6,28 @@ namespace AdventureWorks.ViewModelLayer; public class UserViewModel : ViewModelBase { + #region Constructors + public UserViewModel() : base() + { + + } + + public UserViewModel(IRepository repo) : base() + { + Repository = repo; + } + public UserViewModel(IRepository repo, IRepository phoneRepo) + { + Repository = repo; + _PhoneTypeRepository = phoneRepo; + } + #endregion + #region Private Variables private User? _UserObject = new(); + private readonly IRepository? Repository; + private readonly IRepository? _PhoneTypeRepository; + private ObservableCollection _PhoneTypesList = new(); #endregion #region public Properties @@ -22,6 +42,18 @@ public class UserViewModel : ViewModelBase } } + + public ObservableCollection PhoneTypesList + { + get { return _PhoneTypesList; } + set + { + _PhoneTypesList = value; + RaisePropertyChanged(nameof(PhoneTypesList)); + } + + } + #endregion #region Get Method @@ -37,26 +69,34 @@ public class UserViewModel : ViewModelBase { try { - UserObject = new User + if (Repository != null) { - UserId = id, - LoginId = "SallyJones615", - FirstName = "Sally", - LastName = "Jones", - Email = "sally@jones.com", - Password = "password123", - Phone = "555-1234", - PhoneType = "Mobile", - IsFullTime = true, - IsEnrolledIn401k = false, - IsEnrolledInFlexTime = false, - IsEnrolledInHealthCare = true, - IsEnrolledInHSA = false, - IsActive = true, - BirthDate = Convert.ToDateTime("1975-11-04"), - StartTime = new TimeSpan(8, 0, 0) + UserObject = Repository.Get(id); + } + else + { + UserObject = new User + { - }; + UserId = id, + LoginId = "SallyJones615", + FirstName = "Sally", + LastName = "Jones", + Email = "sally@jones.com", + Password = "password123", + Phone = "555-1234", + PhoneType = "Mobile", + IsFullTime = true, + IsEnrolledIn401k = false, + IsEnrolledInFlexTime = false, + IsEnrolledInHealthCare = true, + IsEnrolledInHSA = false, + IsActive = true, + BirthDate = Convert.ToDateTime("1975-11-04"), + StartTime = new TimeSpan(8, 0, 0) + + }; + } } catch (Exception ex) { @@ -65,9 +105,19 @@ public class UserViewModel : ViewModelBase return UserObject; } - #endregion + #region GetPhoneTypesMethod + public ObservableCollection GetPhoneTypes() + { + if (_PhoneTypesList != null) + { + var list = _PhoneTypeRepository.Get(); + PhoneTypesList = new ObservableCollection(list.Select(row => row.TypeDescription)); + } + return PhoneTypesList; + } + #endregion #region Save Method public virtual bool Save() diff --git a/Common.Library/Interfaces/IRepository.cs b/Common.Library/Interfaces/IRepository.cs new file mode 100644 index 0000000..48ab94c --- /dev/null +++ b/Common.Library/Interfaces/IRepository.cs @@ -0,0 +1,10 @@ +using System.Collections.ObjectModel; + + +namespace Common.Library; + +public interface IRepository +{ + ObservableCollection Get(); + TEntity? Get(int id); +}