private void ReloadBonViewModels() { int?currentID = null; if (CurrentBon != null) { currentID = CurrentBon.ID; } //_allBons.Clear(); ObservableCollection <BonViewModel> obs2 = new ObservableCollection <BonViewModel>(); foreach (IReceipt bon in this._bons) { //BonViewModel bvm = new BonViewModel(bon, this._DBConnection); BonViewModel bvm = new BonViewModel(bon, _DBConnection); if (_allBons != null) { BonViewModel bvm2 = _allBons.Where(x => x.ID.Equals(bvm.ID)).FirstOrDefault(); if (bvm2 != null) { bvm.Balance = bvm2.Balance; } } bvm.PropertyChanged -= EventuellBetragGeändert; bvm.PropertyChanged += EventuellBetragGeändert; bvm.PropertyChanged -= CurrentBonSaved; bvm.PropertyChanged += CurrentBonSaved; obs2.Insert(0, bvm); } if (_allBons != null) { foreach (BonViewModel bonvm in obs2) { BonViewModel a = _allBons.Where(x => x.ID.Equals(bonvm.ID)).FirstOrDefault() as BonViewModel; if (a != null) { bonvm.CanBeEdited = a.CanBeEdited; } } } _allBons = obs2; if (AllBons.Count == 0) { CurrentBon = null; } else if (currentID != null) { CurrentBon = _allBons.Where(x => x.ID.Equals(currentID)).FirstOrDefault(); } RaisePropertyChanged("AllBons"); }
private void CreateBon(object obj) { IReceipt newBon = new BonnyUI.Model.Receipt(); if (CurrentBon != null) { newBon.User = CurrentBon.User; } _bons.Add(newBon); BonViewModel bvm = new BonViewModel(newBon, _DBConnection); bvm.ShopViewModel = _shopAdmin.AllShops[0]; bvm.CanBeEdited = true; bvm.PropertyChanged -= EventuellBetragGeändert; bvm.PropertyChanged += EventuellBetragGeändert; bvm.PropertyChanged -= CurrentBonSaved; bvm.PropertyChanged += CurrentBonSaved; _allBons.Insert(0, bvm); RaisePropertyChanged("AllBons"); CurrentBon = bvm; RaisePropertyChanged("CurrentBon"); }