-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddUserVM.cs
More file actions
141 lines (94 loc) · 3.06 KB
/
AddUserVM.cs
File metadata and controls
141 lines (94 loc) · 3.06 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Project01.Model;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace Project01
{
public partial class AddUserVM : ObservableObject
{
[ObservableProperty]
public string firstname;
[ObservableProperty]
public string lastname;
[ObservableProperty]
public int age;
[ObservableProperty]
public string dateofbirth;
[ObservableProperty]
public double gpa;
//To change the tile
[ObservableProperty]
public string title;
[ObservableProperty]
public BitmapImage selectedImage;
public AddUserVM(User u)
{
Student = u;
firstname = Student.FirstName;
lastname = Student.LastName;
age = Student.Age;
gpa = Student.Gpa;
dateofbirth = Student.DateOfBirth;
selectedImage=Student.Image;
}
public AddUserVM()
{
}
//get image
[RelayCommand]
public void UploadPhoto()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Image files | *.bmp; *.png; *.jpg";
dialog.FilterIndex = 1;
if (dialog.ShowDialog() == true)
{
selectedImage = new BitmapImage(new Uri(dialog.FileName));
MessageBox.Show("Imgae successfuly uploded!", "successfull");
}
}
public User Student { get; private set; }
public Action CloseAction { get; internal set; }
[RelayCommand]
public void Save()
{
if (Gpa < 0 || Gpa > 4) {
MessageBox.Show("GPA value must be between 0 and 4.", "Error" );
return;
}
if(Student==null)
{
Student = new User()
{
FirstName = firstname,
LastName = lastname,
Age = age,
DateOfBirth = dateofbirth,
Gpa = gpa,
Image = selectedImage
};
}
else
{
Student.FirstName = firstname;
Student.LastName = lastname;
Student.Age = age;
Student.Gpa = gpa;
Student.Image = selectedImage;
Student.DateOfBirth = dateofbirth;
}
if(Student.FirstName != null ) {
CloseAction(); }
Application.Current.MainWindow.Show();
}
}
}