Listviews of Products and users
This commit is contained in:
@ -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<Product> repo) : base()
|
||||
{
|
||||
Repository = repo;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
private Product? _ProductObject = new();
|
||||
private ObservableCollection<Product> _ProductList = new();
|
||||
private readonly IRepository<Product>? Repository;
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
public Product? ProductObject
|
||||
{
|
||||
get { return _ProductObject; }
|
||||
set
|
||||
{
|
||||
_ProductObject = value;
|
||||
RaisePropertyChanged(nameof(ProductObject));
|
||||
}
|
||||
}
|
||||
public ObservableCollection<Product> ProductList
|
||||
{
|
||||
get { return _ProductList; }
|
||||
set
|
||||
{
|
||||
_ProductList = value;
|
||||
RaisePropertyChanged(nameof(ProductList));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public ObservableCollection<Product> Get()
|
||||
{
|
||||
if (Repository != null)
|
||||
{
|
||||
ProductList = new ObservableCollection<Product>(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.");
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,6 +25,7 @@ public class UserViewModel : ViewModelBase
|
||||
|
||||
#region Private Variables
|
||||
private User? _UserObject = new();
|
||||
private ObservableCollection<User> _UserList = new();
|
||||
private readonly IRepository<User>? Repository;
|
||||
private readonly IRepository<PhoneType>? _PhoneTypeRepository;
|
||||
private ObservableCollection<string> _PhoneTypesList = new();
|
||||
@ -43,6 +44,16 @@ public class UserViewModel : ViewModelBase
|
||||
|
||||
}
|
||||
|
||||
public ObservableCollection<User> UserList
|
||||
{
|
||||
get { return _UserList; }
|
||||
set
|
||||
{
|
||||
_UserList = value;
|
||||
RaisePropertyChanged(nameof(UserList));
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<string> PhoneTypesList
|
||||
{
|
||||
get { return _PhoneTypesList; }
|
||||
@ -59,6 +70,11 @@ public class UserViewModel : ViewModelBase
|
||||
#region Get Method
|
||||
public ObservableCollection<User> Get()
|
||||
{
|
||||
if (Repository != null)
|
||||
{
|
||||
UserList = new ObservableCollection<User>(Repository.Get());
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user