ResultPage.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Design;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace PsychoTest.Pages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для ResultPage.xaml
  20. /// </summary>
  21. public partial class ResultPage : Page
  22. {
  23. public PsychoBase DB = new PsychoBase();
  24. Users_Tests ut = new Users_Tests();
  25. int id;
  26. public ResultPage(int test_id, int user_id, double result_count)
  27. {
  28. InitializeComponent();
  29. id = user_id;
  30. ut = DB.Users_Tests.Where(x=>x.Id_user == user_id && x.Results.Id_test == test_id).FirstOrDefault();
  31. DefineResult(test_id, user_id, result_count);
  32. }
  33. public void DefineResult(int test_id, int user_id, double result_count)
  34. {
  35. List<Results> resus = DB.Results.Where(x => x.Id_test == test_id).ToList();
  36. resus = resus.OrderBy(x=>x.Score_count).ToList();
  37. Results content = null;
  38. int result_count_int = Convert.ToInt32(result_count);
  39. foreach(Results res in resus)
  40. {
  41. if(result_count_int >= res.Score_count)
  42. {
  43. content = new Results();
  44. content.Result_id = res.Result_id;
  45. content.Result_name = res.Result_name;
  46. content.Description = res.Description;
  47. }
  48. }
  49. if(content == null)
  50. {
  51. content = new Results();
  52. content.Result_id = resus[0].Result_id;
  53. content.Result_name = resus[0].Result_name;
  54. content.Description = resus[0].Description;
  55. }
  56. ResultName.Text = content.Result_name;
  57. ResultText.Text = content.Description;
  58. if(ut!=null)
  59. {
  60. ut.Id_result = content.Result_id;
  61. DB.SaveChanges();
  62. }
  63. else
  64. {
  65. ut = new Users_Tests() { Id_result = content.Result_id, Id_user = user_id };
  66. DB.Users_Tests.Add(ut);
  67. DB.SaveChanges();
  68. }
  69. }
  70. private void GoTests(object sender, RoutedEventArgs e)
  71. {
  72. MainFrame.frame.Navigate(new UserTests(id));
  73. }
  74. }
  75. }