Example #1
0
        public EditorViewModel(IRepository<Quiz> quizRepo,
                               IRepository<Category> categoryRepo,
                               IRepository<Question> questionRepo,
                               INotificationService notificationService,
                               IWindowService windowService)
        {
            _windowService = windowService;
            _notificationService = notificationService;
            _quizRepo = quizRepo;
            _questionRepo = questionRepo;
            _categoryRepo = categoryRepo;

            AllQuizes = new ObservableCollection<QuizViewModel>();
            AllQuestions = new ObservableCollection<QuestionViewModel>();
            AllCategories = new ObservableCollection<CategoryViewModel>();

            notificationService.OnStartedLoading += NotificationService_OnLoadingChanged;
            notificationService.OnStoppedLoading += NotificationService_OnLoadingChanged;
            notificationService.OnNewDisplayMessage += NotificationService_OnNewDisplayMessage;
            notificationService.OnMessageReceived += NotificationService_OnMessageReceived;

            LoadingVisibility = Visibility.Hidden;
            NotificationVisibility = Visibility.Hidden;

            RemoveQuizCommand = new RelayCommand(OnRemoveQuiz, CanRemoveQuiz);
            AddQuizCommand = new RelayCommand(OnAddQuiz);
            RemoveQuestionCommand = new RelayCommand(OnRemoveQuestion, CanRemoveQuestion);
            AddQuestionCommand = new RelayCommand(OnAddQuestion);
            AddAnswerCommand = new RelayCommand(OnAddAnwer, CanAddAnswer);
            RemoveAnswerCommand = new RelayCommand(OnRemoveAnswer, CanRemoveAnswer);
            SaveQuestionCommand = new RelayCommand(OnSaveQuestion, CanSaveQuestion);
            CloseNotificationCommand = new RelayCommand(OnCloseNotification);

            Task.Run(() =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    LoadingVisibility = Visibility.Visible;
                });

                var allQuizes = new List<QuizViewModel>();
                var allQuestions = new List<QuestionViewModel>();
                var allCategories = new List<CategoryViewModel>();

                foreach (var quiz in _quizRepo.GetAllItems())
                {                
                    allQuizes.Add(new QuizViewModel(quiz, _quizRepo, _questionRepo, _categoryRepo, notificationService));
                }

                foreach (var question in _questionRepo.GetAllItems())
                {
                    allQuestions.Add(new QuestionViewModel(question, _questionRepo, _categoryRepo, _notificationService));
                }

                foreach (var categorie in _categoryRepo.GetAllItems())
                {
                    allCategories.Add(new CategoryViewModel(categorie, _categoryRepo, _notificationService));
                }

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    allQuizes.ForEach(q => AllQuizes.Add(q));
                    allQuestions.ForEach(q => AllQuestions.Add(q));
                    allCategories.ForEach(c => AllCategories.Add(c));

                    RaisePropertyChanged("AllQuizes");
                    RaisePropertyChanged("AllQuestions");
                    RaisePropertyChanged("AllCategories");
                    LoadingVisibility = Visibility.Hidden;
                });
            });            

            SelectedQuiz = new QuizViewModel(new Quiz() { Questions = new List<QuizQuestion>() }, _quizRepo, _questionRepo, _categoryRepo, notificationService);
            SelectedQuestion = new QuestionViewModel(new Question() { Answers = new List<Answer>(), Category = new Category() }, _questionRepo, _categoryRepo, _notificationService);
            NewCategory = new CategoryViewModel(new Category(), _categoryRepo, _notificationService);
            //SelectedTabIndex = 1;
        }
 public static ThemeClassificationEntity GetThemeClassificationEntityByTitle(IRepository<ThemeClassificationEntity> repository, string title)
 {
     return repository.GetAllItems<ThemeClassificationEntity>().FirstOrDefault(e => e.Title == title);
 }