1234567891011121314151617181920212223242526272829303132333435363738 |
- using examPrepare.Models;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace examPrepare.ViewModels
- {
- public class CartViewModel : INotifyPropertyChanged
- {
- private List<ProductModel> _products = new List<ProductModel>();
- public List<ProductModel> Products {
- get { return _products; }
- set { _products = value; OnPropertyChanged("Products"); }
- }
- public void notifyChange() { OnPropertyChanged("Products"); }
- public CartViewModel()
- {
- List<Product> rawProcuts = GlobalInfo.conn.Product.ToList();
- foreach (Product product in rawProcuts)
- {
- if (GlobalInfo.cart.ContainsKey(product.ProductArticleNumber))
- {
- ProductModel p = new ProductModel(product);
- p.count = GlobalInfo.cart[product.ProductArticleNumber];
- _products.Add(p);
- }
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged(string propertyName)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- }
|