CartViewModel.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using examPrepare.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace examPrepare.ViewModels
  9. {
  10. public class CartViewModel : INotifyPropertyChanged
  11. {
  12. private List<ProductModel> _products = new List<ProductModel>();
  13. public List<ProductModel> Products {
  14. get { return _products; }
  15. set { _products = value; OnPropertyChanged("Products"); }
  16. }
  17. public void notifyChange() { OnPropertyChanged("Products"); }
  18. public CartViewModel()
  19. {
  20. List<Product> rawProcuts = GlobalInfo.conn.Product.ToList();
  21. foreach (Product product in rawProcuts)
  22. {
  23. if (GlobalInfo.cart.ContainsKey(product.ProductArticleNumber))
  24. {
  25. ProductModel p = new ProductModel(product);
  26. p.count = GlobalInfo.cart[product.ProductArticleNumber];
  27. _products.Add(p);
  28. }
  29. }
  30. }
  31. public event PropertyChangedEventHandler PropertyChanged;
  32. protected void OnPropertyChanged(string propertyName)
  33. {
  34. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  35. }
  36. }
  37. }