ActivityPage.xaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace ModuleExam
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для ActivityPage.xaml
  19. /// </summary>
  20. public partial class ActivityPage : Page
  21. {
  22. ExamEntities DB = new ExamEntities();
  23. List<int> postsAdmin = new List<int>();
  24. List<usersmetrics> um;
  25. int UserId;
  26. public ActivityPage(int id)
  27. {
  28. InitializeComponent();
  29. users user = new users();
  30. user = DB.users.FirstOrDefault(x=>x.id == id);
  31. um = DB.usersmetrics.Where(x=>x.id_user == id).ToList();
  32. postsAdmin = DB.posts.Where(x => x.id_role == 1).Select(x => x.id).ToList();
  33. if (postsAdmin.Contains(id))
  34. {
  35. AdminButtons.Visibility = Visibility.Visible;
  36. }
  37. SurNamPat.Text = $"{user.surname} {user.firstname} {user.patronymic}";
  38. UserPost.Text = DB.posts.Where(x=>x.id == user.id_post).Select(x=>x.title).FirstOrDefault();
  39. UsersCoef.ItemsSource = um;
  40. SumFinalRate();
  41. List<RatingList> RateList = RatingPage.RatingCalculate();
  42. RatingList rl1 = RateList.FirstOrDefault(x=>x.UserId == id);
  43. Place.Text = (RateList.IndexOf(rl1)+1).ToString();
  44. UserId = id;
  45. }
  46. public void SumFinalRate()
  47. {
  48. double finalRate = 0;
  49. foreach(usersmetrics u in um)
  50. {
  51. finalRate += (double)u.coefficient;
  52. }
  53. FinalRate.Text = finalRate.ToString();
  54. }
  55. private void ToRatePage(object sender, RoutedEventArgs e)
  56. {
  57. MainFrame.MFrame.Navigate(new RatingPage(UserId));
  58. }
  59. private void ToUserDataPage(object sender, RoutedEventArgs e)
  60. {
  61. MainFrame.MFrame.Navigate(new UserData(UserId));
  62. }
  63. private void Exit(object sender, RoutedEventArgs e)
  64. {
  65. MainFrame.MFrame.Navigate(new Auth());
  66. }
  67. }
  68. }