-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindowVM.cs
More file actions
109 lines (86 loc) · 3.02 KB
/
MainWindowVM.cs
File metadata and controls
109 lines (86 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Project01.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
namespace Project01
{
public partial class MainWindowVM : ObservableObject
{
[ObservableProperty]
public ObservableCollection<User> users;
[ObservableProperty]
public User selectedUser=null;
public void CloseMainWindow()
{
Application.Current.MainWindow.Close();
}
[RelayCommand]
public void messeag()
{
MessageBox.Show($"{selectedUser.FirstName} GPA value must be between 0 and 4.", "Error");
}
[RelayCommand]
public void AddStudent()
{
var vm = new AddUserVM();
vm.title = "ADD USER";
AddUserWindow window = new AddUserWindow(vm);
window.ShowDialog();
if (vm.Student.FirstName != null)
{
users.Add(vm.Student);
}
}
[RelayCommand]
public void Delete()
{
if (selectedUser != null)
{
string name = selectedUser.FirstName;
users.Remove(selectedUser);
MessageBox.Show($"{name} is Deleted successfuly.", "DELETED \a ");
}
else
{
MessageBox.Show("Plese Select Student before Delete.", "Error");
}
}
[RelayCommand]
public void ExecuteEditStudentCommand()
{
if (selectedUser != null)
{
var vm = new AddUserVM(selectedUser);
vm.title = "EDIT USER";
var window = new AddUserWindow(vm);
window.ShowDialog();
int index = users.IndexOf(selectedUser);
users.RemoveAt(index);
users.Insert(index, vm.Student);
}
else
{
MessageBox.Show("Please Select the student", "Warning!");
}
}
public MainWindowVM()
{
users = new ObservableCollection<User>();
BitmapImage image1 = new BitmapImage(new Uri("/Model/Images/1.png", UriKind.Relative));
users.Add(new User(12, "Shewon", "Perera", "12/1/2000",image1,2));
BitmapImage image2 = new BitmapImage(new Uri("/Model/Images/2.png", UriKind.Relative));
users.Add(new User(12, "Ahir", "Dias", "12/1/2000",image2,2));
BitmapImage image3 = new BitmapImage(new Uri("/Model/Images/3.png", UriKind.Relative));
users.Add(new User(12, "Liya", "Dion", "12/1/2000",image3, 4));
BitmapImage image4= new BitmapImage(new Uri("/Model/Images/4.png", UriKind.Relative));
users.Add(new User(12, "Sely", "Leon", "12/1/2000", image4,2));
}
}
}