internal BorderouContext() : base() { BorderouRepository = new BorderouRepository(); BorderouList = new ObservableCollection <Borderou>(BorderouRepository.BorderouList); BorderouView = (ListCollectionView)CollectionViewSource.GetDefaultView(BorderouList); Summary = BorderouList.Count + " entries."; BorderouList.CollectionChanged += Borderou_CollectionChanged; SumaCostCurier = 0; SumaTransportFactura = 0; SumaValoareFactura = 0; }
private void Borderou_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { int newIndex = e.NewStartingIndex; BorderouRepository.AddNewRecord(BorderouList[newIndex]); } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { List <Borderou> tempListOfRemovedItems = e.OldItems.OfType <Borderou>().ToList(); BorderouRepository.DelRecord(tempListOfRemovedItems[0].Factura); } /*else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace) * { * List<Movie> tempListOfMovies = e.NewItems.OfType<Movie>().ToList(); * MovieRepository.UpdateRecord(tempListOfMovies[0]); // As the IDs are unique, only one row will be effected hence first index only * } */ }