56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
![]() |
using System.Collections.Generic;
|
||
|
using System.Collections.ObjectModel;
|
||
|
using System.Linq;
|
||
|
using Avalonia;
|
||
|
using Avalonia.Controls;
|
||
|
using Avalonia.Interactivity;
|
||
|
using Avalonia.Markup.Xaml;
|
||
|
using kursovaya.Models;
|
||
|
|
||
|
namespace kursovaya;
|
||
|
|
||
|
public partial class StudentsFromAdminWindow : Window
|
||
|
{
|
||
|
public List<Student> dataSourceStudents = new List<Student>();
|
||
|
public ObservableCollection<Student> Students = new ObservableCollection<Student>();
|
||
|
public StudentsFromAdminWindow()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
|
||
|
var ctx = new DatabaseContext();
|
||
|
|
||
|
dataSourceStudents = ctx.Students.ToList();
|
||
|
DisplayStudents();
|
||
|
FlatGrid.ItemsSource = Students;
|
||
|
}
|
||
|
|
||
|
|
||
|
public void DisplayStudents()
|
||
|
{
|
||
|
var ctx = new DatabaseContext();
|
||
|
var temp = dataSourceStudents;
|
||
|
Students.Clear();
|
||
|
|
||
|
foreach (var student in temp)
|
||
|
{
|
||
|
Students.Add(student);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void ButtonBack_OnClick(object? sender, RoutedEventArgs e)
|
||
|
{
|
||
|
Close();
|
||
|
}
|
||
|
|
||
|
private async void ButtonAddStudent_OnClick(object? sender, RoutedEventArgs e)
|
||
|
{
|
||
|
AddStudent addStudent = new AddStudent();
|
||
|
var students = await addStudent.ShowDialog<List<Student>>(this);
|
||
|
|
||
|
if (students == null || students.Count == 0)
|
||
|
return;
|
||
|
|
||
|
dataSourceStudents.AddRange(students);
|
||
|
DisplayStudents();
|
||
|
}
|
||
|
}
|