TestMatchTheValueViewModel.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text.RegularExpressions;
  7. using CommunityToolkit.Mvvm.ComponentModel;
  8. using EntranseTesting.Models;
  9. using EntranseTesting.Models.customClass;
  10. using Microsoft.EntityFrameworkCore;
  11. using ReactiveUI;
  12. namespace EntranseTesting.ViewModels
  13. {
  14. public partial class TestMatchTheValueViewModel : ObservableObject
  15. {
  16. [ObservableProperty] int numberTask;
  17. [ObservableProperty] string question;
  18. [ObservableProperty] List<ItemMatchTheValue> elements = new List<ItemMatchTheValue>();
  19. [ObservableProperty] List<ElementOfEquality> info = new List<ElementOfEquality>();
  20. [ObservableProperty] List<QuestionImage> qImage = new List<QuestionImage>();
  21. [ObservableProperty] List<string> chooseValue = new List<string>();
  22. public TestMatchTheValueViewModel(int numberTask)
  23. {
  24. EntranceTestingContext baseConnection = new EntranceTestingContext();
  25. this.numberTask = numberTask;
  26. Question = baseConnection.Questions.FirstOrDefault(tb => tb.Id == numberTask).Name;
  27. QImage = baseConnection.QuestionImages.Where(tb => tb.IdQuestion == numberTask).ToList();
  28. Info = baseConnection.ElementOfEqualities.Include(tb => tb.RatioOfElementEqualityIdElement1Navigations).Include(tb => tb.RatioOfElementEqualityIdElement2Navigations).Where(tb => tb.IdQuestion == numberTask).ToList();
  29. for (int i = 0; i < Info.Count/2; i++)
  30. Elements.Add(new ItemMatchTheValue(Info.Select(tb => tb.Name).ToList()));
  31. //çàïîëíÿåì äàííûå
  32. int responseIndex = Response.IndexResponse(numberTask);
  33. if (Response.responseUsers[responseIndex].UserResponseMatchTheValues.Count > 0)//åñëè ïîëüçîâàòåëü íå îòâå÷àë
  34. {
  35. List<UserResponseMatchTheValue> _response = Response.responseUsers[responseIndex].UserResponseMatchTheValues.ToList();
  36. int i = 0;
  37. foreach (UserResponseMatchTheValue item in _response)
  38. {
  39. Elements[i].Elem1 = Info.FirstOrDefault(tb => tb.Id == item.IdElement1).Name;
  40. Elements[i].Elem2 = Info.FirstOrDefault(tb => tb.Id == item.IdElement2).Name;
  41. i++;
  42. }
  43. }
  44. }
  45. }
  46. }