123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using AvaloniaApplication1.Models;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- namespace AvaloniaApplication1.ViewModels
- {
- public class CoursesListViewModel : ReactiveObject
- {
- public static ScoolContext DB = new ScoolContext();
- private List<Course>? courses;
- public List<Course>? Courses { get => courses; set => this.RaiseAndSetIfChanged(ref courses, value); }
- public CoursesListViewModel()
- {
- Courses = DB.Courses.Include(x=>x.TeachersCourses).ToList();
- }
-
- public static List<string> OrderNameOrHours => new List<string>() {"Áåç ñîðòèðîâêè", "Ïî èìåíè À-ß", "Ïî èìåíè ß-À", "Ïî êîëè÷åñòâó ÷àñîâ (ïî âîçðàñòàíèþ)", "Ïî êîëè÷åñòâó ÷àñîâ (ïî óáûâàíèþ)" };
- private string selectedNameOrHour = OrderNameOrHours[0];
- public string SelectedNameOrHour
- {
- get => selectedNameOrHour;
- set
- {
- selectedNameOrHour = value;
- Filter();
- }
- }
- public static List<string> FilterByHours => new List<string>() { "Áåç ôèëüòðà", "50 ÷àñîâ èëè ìåíüøå", "îò 50 äî 100 ÷àñîâ", "áîëåå 100 ÷àñîâ" };
- private string selectedFilter = FilterByHours[0];
- public string SelectedFilter
- {
- get => selectedFilter;
- set
- {
- selectedFilter = value;
- Filter();
- }
- }
- private string nameOrHoursFind;
- public string NameOrHoursFind
- {
- get => nameOrHoursFind;
- set
- {
- nameOrHoursFind = value;
- Filter();
- }
- }
- public void Filter()
- {
- Courses = DB.Courses.Include(x => x.TeachersCourses).ToList();
- if(SelectedNameOrHour != "Áåç ñîðòèðîâêè")
- {
- switch(SelectedNameOrHour)
- {
- case "Ïî èìåíè À-ß":
- Courses = Courses.OrderBy(x=>x.Course1).ToList();
- break;
- case "Ïî èìåíè ß-À":
- Courses = Courses.OrderByDescending(x => x.Course1).ToList();
- break;
- case "Ïî êîëè÷åñòâó ÷àñîâ (ïî âîçðàñòàíèþ)":
- Courses = Courses.OrderBy(x => x.HoursCount).ToList();
- break;
- case "Ïî êîëè÷åñòâó ÷àñîâ (ïî óáûâàíèþ)":
- Courses = Courses.OrderByDescending(x => x.HoursCount).ToList();
- break;
- }
- }
- if (SelectedFilter != "Áåç ôèëüòðà")
- {
- switch (SelectedNameOrHour)
- {
- case "50 ÷àñîâ èëè ìåíüøå":
- Courses = Courses.Where(x => x.HoursCount <= 50).ToList();
- break;
- case "îò 50 äî 100 ÷àñîâ":
- Courses = Courses.Where(x => x.HoursCount > 50 && x.HoursCount <= 100).ToList();
- break;
- case "áîëåå 100 ÷àñîâ":
- Courses = Courses.Where(x => x.HoursCount > 100).ToList();
- break;
- }
- }
- if(NameOrHoursFind != null && NameOrHoursFind != "")
- {
- Courses = Courses.Where(x=>x.Course1.ToLower().Contains(NameOrHoursFind.ToLower()) || NameOrHoursFind == Convert.ToString(x.HoursCount)).ToList();
- }
- }
- }
- }
|