12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OUP
- {
- public class ViewModel : BaseViewModel
- {
- private RelayCommand _submitCommand;
- public RelayCommand SubmitCommand
- {
- get
- {
- return _submitCommand ??
- (_submitCommand = new RelayCommand(x =>
- {
- if (_product.IdProduct == 0)
- {
-
- Helper.GetContext().Product.Add(_product);
- }
- Helper.GetContext().SaveChanges();
- }));
- }
- }
- private Product _product;
- private ObservableCollection<Product> _products;
- public ObservableCollection<Product> Products
- {
- get => _products;
- set
- {
- _products = value;
- OnPropertyChanged();
- }
- }
- public Product Product
- {
- get => _product;
- set
- {
- _product = value;
- OnPropertyChanged();
- }
- }
- public ViewModel(Product product)
- {
- _product = product;
- _products = new ObservableCollection<Product>(Helper.GetContext().Product);
- }
- }
- }
|