TestMainViewModel.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using Avalonia.Controls;
  7. using CommunityToolkit.Mvvm.ComponentModel;
  8. using CommunityToolkit.Mvvm.Input;
  9. using EntranseTesting.Models;
  10. using Microsoft.EntityFrameworkCore;
  11. using MsBox.Avalonia;
  12. using MsBox.Avalonia.Enums;
  13. using ReactiveUI;
  14. namespace EntranseTesting.ViewModels
  15. {
  16. public partial class TestMainViewModel : ObservableObject
  17. {
  18. [ObservableProperty] TestPageViewModel testPages = new TestPageViewModel();
  19. [ObservableProperty] TestResultViewModel testResults = new TestResultViewModel();
  20. [ObservableProperty] string? groupUser = "";
  21. [ObservableProperty] string? nameUser = "";
  22. public void ClickToQuestion(int numQuestion)
  23. {
  24. changeResponse();
  25. TestPages.ProgressButtons[TestPages.NumQuestion - 1].Active = false;
  26. TestPages.NumQuestion = numQuestion;
  27. TestPages.ProgressButtons[TestPages.NumQuestion - 1].Active = true;
  28. if (TestPages.NumQuestion == TestPages.CountQuestion)
  29. TestPages.ButtonValue = "Çàâåðøèòü òåñò";
  30. else
  31. TestPages.ButtonValue = "Ñëåäóþùèé âîïðîñ";
  32. while (!TestPages.TakeProgressButtons.Contains(TestPages.ProgressButtons[TestPages.NumQuestion - 1]))
  33. {
  34. if (TestPages.NumQuestion > TestPages.TakeProgressButtons.Last().Num)
  35. TestPages.SkipItem++;
  36. else
  37. TestPages.SkipItem--;
  38. }
  39. TestPages.changingPage();
  40. }
  41. public void changeResponse()
  42. {
  43. if (TestPages.QuestionsCollection.Count > 0)
  44. {
  45. switch (TestPages.QuestionsCollection[TestPages.NumQuestion - 1].IdCategoryNavigation.Name)
  46. {
  47. case "Âîïðîñ ñ 1 âàðèàíòîì îòâåòà":
  48. {
  49. Response.SaveChangesChoosing(TestPages.QuestionsCollection[TestPages.NumQuestion - 1].Id, false, TestPages.TestC1A.Element);
  50. break;
  51. }
  52. case "Âîïðîñ ñ íåñêîëüêèìè âàðèàíòàìè îòâåòà":
  53. {
  54. Response.SaveChangesChoosing(TestPages.QuestionsCollection[TestPages.NumQuestion - 1].Id, true, TestPages.TestCMA.Element);
  55. break;
  56. }
  57. case "Ãîðèçîíòàëüíîå óïîðÿäî÷èâàíèå ýëåìåíòîâ":
  58. case "Âåðòèêàëüíîå óïîðÿäî÷èâàíèå ýëåìåíòîâ":
  59. {
  60. Response.SaveChangesArrangement(TestPages.QuestionsCollection[TestPages.NumQuestion - 1].Id, TestPages.TestAE.Element);
  61. break;
  62. }
  63. case "Ñîîòíîøåíèå âåëè÷èí":
  64. {
  65. Response.SaveChangesMatchTheValue(TestPages.QuestionsCollection[TestPages.NumQuestion - 1].Id, TestPages.TestMV.Elements);
  66. break;
  67. }
  68. case "Ñîîòíîøåíèå ýëåìåíòîâ":
  69. {
  70. Response.SaveChangesMatchTheElement(TestPages.QuestionsCollection[TestPages.NumQuestion - 1].Id, TestPages.TestME.Matches);
  71. break;
  72. }
  73. case "Ïîäñòàíîâêà îòâåòîâ":
  74. {
  75. Response.SaveChangesCAFS(TestPages.QuestionsCollection[TestPages.NumQuestion - 1].Id, TestPages.TestCAFS.Element);
  76. break;
  77. }
  78. }
  79. TestPages.ProgressButtons[TestPages.NumQuestion - 1].Check = Response.change;
  80. }
  81. }
  82. }
  83. }