Last active
October 22, 2017 10:17
-
-
Save andy51002000/07a9194912431cd2ac52cf3aab6dab57 to your computer and use it in GitHub Desktop.
This class is responsible for providing proper data to view in MVVM, such as the collection of movies, ..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SimpleMVVM.Common; | |
using SimpleMVVM.Data; | |
using SimpleMVVM.Models; | |
using System; | |
using System.Collections.ObjectModel; | |
using System.Windows.Input; | |
namespace SimpleMVVM.ViewModels | |
{ | |
public class MovieListViewModel : ViewModelBase | |
{ | |
private ObservableCollection<Movie> movies; | |
private ICommand deleteAllMoviesCommand; | |
private Movie selectedMovie; | |
private FakeDatabase dbConext; | |
public ObservableCollection<Movie> Movies | |
{ | |
get => movies; | |
set | |
{ | |
movies = value; | |
NotifyPropertyChanged("Movies"); | |
} | |
} | |
public ICommand DeleteAllMoviesCommand { get => deleteAllMoviesCommand; } | |
public Movie SelectedMovie | |
{ | |
get => selectedMovie; | |
set | |
{ | |
selectedMovie = value; | |
NotifyPropertyChanged("SelectedMovie"); | |
} | |
} | |
public MovieListViewModel(FakeDatabase fakeDatabase) | |
{ | |
this.dbConext = fakeDatabase; | |
movies = dbConext.Movies; | |
deleteAllMoviesCommand = new RelayCommand(new Action(deleteAllMovies)); | |
} | |
private async void deleteAllMovies() | |
{ | |
await dbConext.Clear(); | |
Movies.Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment