public QuizListVM() { dbContext = new QuizDBAccess(); var quizList = dbContext.All().Select(q => new QuizVM(q)); SelectedQuiz = new QuizVM(); Quizes = new ObservableCollection <QuizVM>(quizList); SaveQuiz = new RelayCommand(AddOrUpdateQuiz, canSave); DeleteQuiz = new RelayCommand(RemoveQuiz, canRemove); ClearQuiz = new RelayCommand(ClearSelectedQuiz, canClear); }
private void AddOrUpdateQuiz(object parameter) { if (_quiz.Id != 0) // Update selected quiz { dbContext.Update(_quiz.Quiz); } else // Add new quiz { Quizes.Add(_quiz); dbContext.Insert(_quiz.Quiz); } SelectedQuiz = new QuizVM(); }
private void ClearSelectedQuiz(object parameter) { SelectedQuiz = new QuizVM(); }
private void RemoveQuiz(object parameter) { dbContext.Delete(_quiz.Quiz); Quizes.Remove(_quiz); SelectedQuiz = new QuizVM(); }