Vizual_Zurnal/Zurnal_Vizual/ViewModels/MainWindowViewModel.cs

101 lines
3.4 KiB
C#
Raw Normal View History

2024-12-09 09:21:48 +00:00
using Avalonia.Controls;
using data.RemoteData.RemoteDataBase.DAO;
2024-12-06 07:26:58 +00:00
using ReactiveUI;
2024-12-09 09:21:48 +00:00
using System;
2024-12-06 07:26:58 +00:00
using System.Collections.ObjectModel;
using System.Reactive;
2024-12-09 09:21:48 +00:00
namespace Zurnal_Vizual.Views.MainWindow
2024-12-06 07:26:58 +00:00
{
2024-12-09 09:21:48 +00:00
public class MainViewModel : ReactiveObject
2024-12-06 07:26:58 +00:00
{
private ObservableCollection<GroupDao> _groups;
private GroupDao _selectedGroup;
private ObservableCollection<UserDao> _students;
private string _selectedSortOption;
public ObservableCollection<GroupDao> Groups
{
get => _groups;
set => this.RaiseAndSetIfChanged(ref _groups, value);
}
public GroupDao SelectedGroup
{
get => _selectedGroup;
2024-12-09 09:21:48 +00:00
set
{
this.RaiseAndSetIfChanged(ref _selectedGroup, value);
LoadStudents();
}
2024-12-06 07:26:58 +00:00
}
public ObservableCollection<UserDao> Students
{
get => _students;
set => this.RaiseAndSetIfChanged(ref _students, value);
}
public string SelectedSortOption
{
get => _selectedSortOption;
2024-12-09 09:21:48 +00:00
set
{
this.RaiseAndSetIfChanged(ref _selectedSortOption, value);
SortStudents();
}
2024-12-06 07:26:58 +00:00
}
public ReactiveCommand<Unit, Unit> DeleteAllStudentsCommand { get; }
public ReactiveCommand<Unit, Unit> ImportStudentsCommand { get; }
2024-12-09 09:21:48 +00:00
private ObservableCollection<string> _sortOptions;
public ObservableCollection<string> SortOptions
{
get => _sortOptions;
set => this.RaiseAndSetIfChanged(ref _sortOptions, value);
}
2024-12-06 07:26:58 +00:00
2024-12-09 09:21:48 +00:00
public MainViewModel()
2024-12-06 07:26:58 +00:00
{
DeleteAllStudentsCommand = ReactiveCommand.Create(DeleteAllStudents);
ImportStudentsCommand = ReactiveCommand.Create(ImportStudents);
Groups = new ObservableCollection<GroupDao>();
Students = new ObservableCollection<UserDao>();
2024-12-09 09:21:48 +00:00
SortOptions = new ObservableCollection<string> { "По имени", "По дате" };
}
public void LoadStudents()
{
//реализовать загрузку студентов по выбранной группе
}
public void SortStudents()
{
//реализовать сортеровку пользователей (студентов) по имени и Id
2024-12-06 07:26:58 +00:00
}
2024-12-09 09:21:48 +00:00
public void DeleteAllStudents()
{
//реализовать удоление студентов по имени или Id
}
public void ImportStudents()
{
//реализовать добавление студентов по средсвам 2 полей для ввода текста
2024-12-06 07:26:58 +00:00
}
2024-12-09 09:21:48 +00:00
public void ShowContextMenu(Window window)
{
var contextMenu = new ContextMenu();
var deleteItem = new MenuItem { Header = "Удалить всех студентов" };
deleteItem.Click += (sender, e) => DeleteAllStudentsCommand.Execute().Subscribe();
contextMenu.Items.Add(deleteItem);
var importItem = new MenuItem { Header = "Импортировать студентов" };
importItem.Click += (sender, e) => ImportStudentsCommand.Execute().Subscribe();
contextMenu.Items.Add(importItem);
window.ContextMenu = contextMenu;
2024-12-06 07:26:58 +00:00
}
}
}