MyProgramsTemplate.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using AvaloniaApplication4.Models;
  2. using AvaloniaApplication4.ViewModels;
  3. using DynamicData;
  4. using ReactiveUI;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace AvaloniaApplication4.AdditionalModels
  12. {
  13. /// <summary>
  14. /// шаблон программы для вкладки мои программы
  15. /// </summary>
  16. public class MyProgramsTemplate: ViewModelBase
  17. {
  18. private List<ProgramsWithSubject> subjectsList = new List<ProgramsWithSubject>();
  19. public List<ProgramsWithSubject> SubjectsList
  20. {
  21. get { return subjectsList; }
  22. set
  23. {
  24. if (subjectsList == value)
  25. return;
  26. subjectsList = value;
  27. OnPropertyChanged("SubjectsList");
  28. }
  29. }
  30. public string Title { get; set; }
  31. public string Code { get; set; }
  32. public string searchQuery = string.Empty;
  33. List<ProgramsWithSubject> staticProgramsWithSubject;
  34. public MyProgramsTemplate(string title, string code, List<ProgramsWithSubject> subjectsList)
  35. {
  36. Title = title;
  37. Code = code;
  38. SubjectsList = subjectsList;
  39. staticProgramsWithSubject = subjectsList;
  40. }
  41. public void SearchSubjects()
  42. {
  43. if (searchQuery != null && searchQuery != string.Empty && searchQuery != "")
  44. {
  45. SubjectsList = staticProgramsWithSubject.Where(x=>x.IdSubjectNavigation.IdCodeAcademicSubject.ToLower().StartsWith(searchQuery.ToLower()) || x.IdSubjectNavigation.NameSubject.ToLower().StartsWith(searchQuery.ToLower())).ToList();
  46. }
  47. else SubjectsList = staticProgramsWithSubject;
  48. }
  49. public string SearchQuery
  50. {
  51. get
  52. {
  53. return searchQuery;
  54. }
  55. set
  56. {
  57. if (searchQuery == value) return;
  58. searchQuery = value;
  59. SearchSubjects();
  60. OnPropertyChanged("SearchQuery");
  61. }
  62. }
  63. }
  64. }