Example #1
0
        public TestSetEditViewModel()
        {
            try
            {
                this.selectedTest    = new TestSet();
                this.testSetsModel   = BootStrapper.Resolve <ITestSetsModel>();
                this.categoriesModel = BootStrapper.Resolve <ICategoriesModel>();

                this.items = new ObservableCollection <TestItem>();
                if (this.selectedTest.Items != null)
                {
                    foreach (TestItem item in this.selectedTest.Items)
                    {
                        this.items.Add(item);
                    }
                }
                this.categories       = this.categoriesModel.GetAll();
                this.languages        = this.testSetsModel.GetAllLanguages();
                this.SelectedLanguage = TestLanguage.English;
            }
            catch (Exception ex)
            {
                ApplicationErrorHandler.HandleException(ex);
            }
        }
Example #2
0
        private void CreateQuestionEditCommand()
        {
            this.questionEdit = new RelayCommand <TestItem>(item =>
            {
                try
                {
                    TestItemEditView win = new TestItemEditView(item);
                    if (win.ShowDialog() ?? false)
                    {
                        this.selectedItem = item;
                        this.items.Remove(this.selectedItem);
                        item.Question = win.Question;
                        item.Answer   = win.Answer;
                        item.Example  = win.Example;
                        this.items.Add(item);
                    }

                    this.SelectedQuestion = null;

                    base.RaisePropertyChanged("SelectedQuestion");
                    base.RaisePropertyChanged("Questions");
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #3
0
        private void CreateFilterByCategoryCommand()
        {
            this.filterByCategory = new RelayCommand(() =>
            {
                try
                {
                    if (this.selectedCategory == null)
                    {
                        return;
                    }

                    this.tests = new ObservableCollection <TestSet>();

                    foreach (TestSet test in this.testSetsModel.GetAll().Where(x => x.Category.Id == this.selectedCategory.Id))
                    {
                        this.tests.Add(test);
                    }
                    base.RaisePropertyChanged("Tests");
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #4
0
        private void CreateQuestionAddCommand()
        {
            this.questionAdd = new RelayCommand(() =>
            {
                try
                {
                    TestItemEditView win = new TestItemEditView();
                    if (win.ShowDialog() ?? false)
                    {
                        TestItem item = new TestItem()
                        {
                            Question = win.Question,
                            Answer   = win.Answer,
                            Example  = win.Example
                        };

                        this.AddItem(item);
                    }
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #5
0
        private void CreateSaveCommand()
        {
            this.save = new RelayCommand(() =>
            {
                try
                {
                    this.selectedTest.Items.Clear();

                    foreach (TestItem item in this.items)
                    {
                        this.selectedTest.Items.Add(item);
                    }

                    if (this.selectedTest.Id > 0)
                    {
                        this.testSetsModel.Update(this.selectedTest);
                    }
                    else
                    {
                        this.testSetsModel.Add(this.selectedTest);
                    }

                    ApplicationMessage.Send(MessageType.TestsDisplay, MessageType.TestsDisplay.ToString());
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #6
0
 public ScoresViewModel()
 {
     try
     {
         this.model  = BootStrapper.Resolve <IScoreModel>();
         this.scores = this.model.GetAll();
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #7
0
 public CategoriesViewModel(ICategoriesModel model)
 {
     try
     {
         this.model = model;
         this.GetAllCategories();
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
 public RunnerTestSetViewModel()
 {
     try
     {
         this.wrongAnswers  = new List <TestItem>();
         this.testSetsModel = BootStrapper.Resolve <ITestSetsModel>();
         this.scoreModel    = BootStrapper.Resolve <IScoreModel>();
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #9
0
 public TestSetsViewModel()
 {
     try
     {
         this.testSetsModel   = BootStrapper.Resolve <ITestSetsModel>();
         this.categoriesModel = BootStrapper.Resolve <ICategoriesModel>();
         this.tests           = this.testSetsModel.GetAll();
         this.categories      = this.categoriesModel.GetAll();
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #10
0
 private void CreateDisplayQuestionsCommand()
 {
     this.displayQuestions = new RelayCommand <TestSet>(test =>
     {
         try
         {
             ApplicationMessage.Send(MessageType.TestQuestionsDisplay, test);
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #11
0
 private void CreateAddCommand()
 {
     try
     {
         this.add = new RelayCommand(() =>
         {
             ApplicationMessage.Send <string>(Messages.Enum.MessageType.TestAdd, "Add test");
         });
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #12
0
 private void CreateEditCommand()
 {
     try
     {
         this.edit = new RelayCommand <TestSet>(test =>
         {
             ApplicationMessage.Send(MessageType.TestEdit, test);
         });
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #13
0
 private void CreateAddCategoryCommand()
 {
     try
     {
         this.addCategory = new RelayCommand(() =>
         {
             ApplicationMessage.Send(MessageType.CategoryAdd, MessageType.CategoryAdd.ToString());
         });
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #14
0
 private void CreateRunCommand()
 {
     this.run = new RelayCommand <TestSet>(test =>
     {
         try
         {
             ApplicationMessage.Send(MessageType.TestRun, test);
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #15
0
 private void CreateEditCategoryCommand()
 {
     this.editCategory = new RelayCommand <Category>(category =>
     {
         try
         {
             ApplicationMessage.Send(MessageType.CategoryEdit, category);
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #16
0
 private void CreatePreviousCommand()
 {
     try
     {
         this.previousCommand = new RelayCommand(() =>
         {
             ApplicationMessage.Send(MessageType.PreviousViewDisplay, "Display previous view");
         });
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #17
0
 private void CreateCancelCommand()
 {
     this.cancel = new RelayCommand(() =>
     {
         try
         {
             ApplicationMessage.Send(MessageType.TestsDisplay, MessageType.TestsDisplay.ToString());
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #18
0
        private void CreateCheckAnswerCommand()
        {
            this.checkAnswer = new RelayCommand(() =>
            {
                try
                {
                    if (string.IsNullOrEmpty(this.userAnswer))
                    {
                        return;
                    }

                    if (this.userAnswer.ToUpper() != this.items[this.questionNumber].Answer.ToUpper())
                    {
                        this.wrongAnswers.Add(this.items[this.questionNumber]);
                        CorrectAnswerWindow win = new CorrectAnswerWindow(this.items[this.questionNumber]);
                        win.ShowDialog();
                    }

                    this.questionNumber++;
                    base.RaisePropertyChanged("Score");

                    if (this.questionNumber == this.items.Count)
                    {
                        WrongAnswersWindow win = new WrongAnswersWindow(this.wrongAnswers);
                        win.ShowDialog();
                        decimal score = (this.questionNumber - this.wrongAnswers.Count) / (decimal)this.questionNumber;
                        this.scoreModel.SaveScore(new Score()
                        {
                            ScoreValue = score, TestHeaderId = this.test.Id
                        });

                        ApplicationMessage.Send(MessageType.TestsDisplay, "Display tests");

                        return;
                    }

                    base.RaisePropertyChanged("Question");
                    this.userAnswer = string.Empty;
                    base.RaisePropertyChanged("Answer");
                    base.RaisePropertyChanged("QuestionNumber");
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #19
0
 private void CreateCancelCommand()
 {
     try
     {
         if (this.cancelCommand == null)
         {
             this.cancelCommand = new RelayCommand(() =>
             {
                 ApplicationMessage.Send(MessageType.CategoriesDisplay, MessageType.CategoriesDisplay.ToString());
             });
         }
     }
     catch (Exception ex)
     {
         ApplicationErrorHandler.HandleException(ex);
     }
 }
Example #20
0
 private void CreateDeleteCategoryCommand()
 {
     this.deleteCategory = new RelayCommand <Category>(category =>
     {
         try
         {
             DeleteConfirmWindow win = new DeleteConfirmWindow();
             if (win.ShowDialog() == true)
             {
                 this.model.Delete(category);
                 this.GetAllCategories();
             }
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #21
0
 private void CreateDisplayPreviousCommand()
 {
     this.displayPreviousCommand = new RelayCommand(() =>
     {
         try
         {
             if (this.questionNo > 0)
             {
                 this.questionNo--;
                 this.RaiseNavigationProperties();
                 this.DisplayFlashcards();
             }
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #22
0
 private void CreateDisplayNextCommand()
 {
     this.displayNextCommand = new RelayCommand(() =>
     {
         try
         {
             if (this.questionNo < this.testHeader.Items.Count)
             {
                 this.questionNo++;
                 this.RaiseNavigationProperties();
                 this.DisplayFlashcards();
             }
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #23
0
 private void CreateDeleteCommand()
 {
     this.delete = new RelayCommand <TestSet>(test =>
     {
         try
         {
             DeleteConfirmWindow win = new DeleteConfirmWindow();
             if (win.ShowDialog() ?? false)
             {
                 this.testSetsModel.Delete(test);
                 this.tests = this.testSetsModel.GetAll();
                 base.RaisePropertyChanged("Tests");
             }
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #24
0
 private void CreateQuestionDeleteCommand()
 {
     this.questionDelete = new RelayCommand <TestItem>(item =>
     {
         try
         {
             DeleteConfirmWindow win = new DeleteConfirmWindow();
             if (win.ShowDialog() ?? false)
             {
                 this.items.Remove(item);
                 this.selectedItem = null;
                 base.RaisePropertyChanged("Questions");
                 base.RaisePropertyChanged("SelectedQuestion");
                 base.RaisePropertyChanged("QuestionQuantity");
             }
         }
         catch (Exception ex)
         {
             ApplicationErrorHandler.HandleException(ex);
         }
     });
 }
Example #25
0
        private void CreateSaveCommand()
        {
            this.saveCommand = new RelayCommand(() =>
            {
                try
                {
                    if (this.Category.Id > 0)
                    {
                        this.model.Update(this.Category);
                    }
                    else
                    {
                        this.model.Add(this.Category);
                    }

                    ApplicationMessage.Send(MessageType.CategoriesDisplay, MessageType.CategoriesDisplay.ToString());
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #26
0
        private void CreateImportCommand()
        {
            this.importCommand = new RelayCommand(() =>
            {
                try
                {
                    OpenFileDialog dlg     = new OpenFileDialog();
                    Nullable <bool> result = dlg.ShowDialog();

                    if (result == true)
                    {
                        var itemsToImport = TestItemsImporter.ReadTestItems(dlg.FileName);
                        foreach (var item in itemsToImport)
                        {
                            this.AddItem(item);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ApplicationErrorHandler.HandleException(ex);
                }
            });
        }
Example #27
0
 protected void Application_Error(object sender, EventArgs e)
 {
     ApplicationErrorHandler.OnError <ErrorController>(((MvcApplication)sender).Context, Server.GetLastError(),
                                                       "Error", "Index");
 }
Example #28
0
 void MvcApplication_Error(object sender, EventArgs e)
 {
     //全局系统异常处理
     ApplicationErrorHandler.ApplicationError(this);
 }