Skip to content

Instantly share code, notes, and snippets.

@andy51002000
Last active October 22, 2017 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy51002000/07a9194912431cd2ac52cf3aab6dab57 to your computer and use it in GitHub Desktop.
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, ..
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