UserActivity.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Exam.Classes;
  2. using Exam.Pages;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. namespace Exam
  10. {
  11. /// <summary>
  12. /// Класс личного рейтинга пользователя
  13. /// </summary>
  14. public partial class UserActivity : Page
  15. {
  16. List<string> users_string = new List<string>();
  17. List<usersmetrics> um;
  18. List<users> all;
  19. public UserActivity(users user)
  20. {
  21. InitializeComponent();
  22. if (DBContext.Connect.posts.FirstOrDefault(x => x.id == user.id_post).id_role == 1)
  23. {
  24. all = DBContext.Connect.users.Where(x => x.id_post != 5 && x.id_post != 7 && x.id_post != 8).ToList();
  25. users_string.AddRange(all.Select(x => x.surname + " " + x.firstname + " " + x.patronymic));
  26. CBUsers.Visibility = Visibility.Visible;
  27. CBUsers.ItemsSource = users_string;
  28. }
  29. um = DBContext.Connect.usersmetrics.Where(x => x.id_user == user.id).ToList();
  30. LVUsers.ItemsSource = um;
  31. TBAllPoints.Text = "Всего: " + FindAllPoints();
  32. TBPosition.Text = "Позиция в рейтинге: " + FindPosition(user);
  33. }
  34. public double FindAllPoints()
  35. {
  36. return Convert.ToDouble(um.Sum(x=>x.coefficient));
  37. }
  38. public int FindPosition(users current_user)
  39. {
  40. return Methods.FindRating().FirstOrDefault(x=>x.id_user == current_user.id).position;
  41. }
  42. private void User_Changed(object sender, SelectionChangedEventArgs e)
  43. {
  44. users selected_user = all[CBUsers.SelectedIndex];
  45. um = DBContext.Connect.usersmetrics.Where(x => x.id_user == selected_user.id).ToList();
  46. LVUsers.ItemsSource = um;
  47. TBAllPoints.Text = "Всего: " + FindAllPoints();
  48. TBPosition.Text = "Позиция в рейтинге: " + FindPosition(selected_user);
  49. }
  50. }
  51. }