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.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user