-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
111 lines (96 loc) · 3.48 KB
/
MainWindow.xaml.cs
File metadata and controls
111 lines (96 loc) · 3.48 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
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.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Content_Management_System.HelpMethods;
using Content_Management_System.HelpMethods.Users;
using Content_Management_System.Models;
using Content_Management_System.Pages;
namespace Content_Management_System
{
public partial class MainWindow : Window
{
private UserAuth _userAuth;
public MainWindow()
{
InitializeComponent();
_userAuth = new UserAuth();
}
private void LeaveBtn_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show(
"Are you sure you want to exit?",
"Exit confirmation",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
Application.Current.Shutdown();
}
}
private void SubmitBtn_Click(object sender, RoutedEventArgs e)
{
bool greska = false;
string poruka = "";
if (string.IsNullOrWhiteSpace(name.Text))
{
poruka += "Username is required\n";
greska = true;
}
if (string.IsNullOrWhiteSpace(password.Password))
{
poruka += "Password is required\n";
greska = true;
}
if (greska)
{
errorLabel.Content = poruka;
}
else
{
bool validUser = _userAuth.UserAuthentication(name.Text, password.Password);
if (validUser)
{
errorLabel.Content = "";
DoubleAnimation fillAnimation = new DoubleAnimation
{
From = 0,
To = 363, // fill height
Duration = new Duration(TimeSpan.FromSeconds(1)),
EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut }
};
fillAnimation.Completed += (s, ev) => //when the animation is complete, do this...
{
var usersData = new Data();
var users = usersData.DeSerializeObject<List<User>>("Users.xml");
var loggedInUser = users?.FirstOrDefault(u => u.Username.Equals(name.Text, StringComparison.OrdinalIgnoreCase));
TableWindow tableWindow = new TableWindow(loggedInUser.UserRole);
if (loggedInUser != null && loggedInUser.UserRole != UserRole.Admin)
{
tableWindow.HideAdminButtons();
}
tableWindow.Show();
this.Close();
};
SpiceFill.BeginAnimation(HeightProperty, fillAnimation);
}
else
{
errorLabel.Content = "User doesn't exist";
}
}
}
}
}