Refactoring - split data, logic and model layers; custom network exception

This commit is contained in:
Dimitar Byalkov
2023-05-12 12:13:11 +02:00
parent 81109f3d6c
commit ee0b063eec
48 changed files with 256 additions and 160 deletions

View File

@@ -1,5 +1,5 @@
using StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using Logic;
using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;

View File

@@ -1,5 +1,5 @@
using StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using Logic;
using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;

View File

@@ -1,5 +1,5 @@
using StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using Logic;
using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -61,26 +61,47 @@ namespace WinForms
private void btnDeleteUser_Click(object sender, EventArgs e)
{
User currentUser = (User)lbUsers.SelectedItem;
if (MessageBox.Show($"Are you sure you want to delete\n{currentUser.Name}\n{currentUser.Role}", "Delete user", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (lbUsers.SelectedIndex == -1)
{
UserManager userManager = new UserManager();
userManager.DisableUser(currentUser.ID);
MessageBox.Show("Please select an item from the list");
}
else
{
User currentUser = (User)lbUsers.SelectedItem;
if (MessageBox.Show($"Are you sure you want to delete\n{currentUser.Name}\n{currentUser.Role}", "Delete user", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
UserManager userManager = new UserManager();
userManager.DisableUser(currentUser.ID);
}
}
RefreshLists();
}
private void btnUpdateUser_Click(object sender, EventArgs e)
{
UserForm userForm = new UserForm((User)lbUsers.SelectedItem, false);
userForm.ShowDialog();
if (lbUsers.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
UserForm userForm = new UserForm((User)lbUsers.SelectedItem, false);
userForm.ShowDialog();
}
RefreshLists();
}
private void btnViewUser_Click(object sender, EventArgs e)
{
UserForm userForm = new UserForm((User)lbUsers.SelectedItem, true);
userForm.ShowDialog();
if (lbUsers.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
UserForm userForm = new UserForm((User)lbUsers.SelectedItem, true);
userForm.ShowDialog();
}
RefreshLists();
}

View File

@@ -74,6 +74,7 @@
//
tbPassword.Location = new Point(81, 90);
tbPassword.Name = "tbPassword";
tbPassword.PasswordChar = '*';
tbPassword.Size = new Size(161, 23);
tbPassword.TabIndex = 4;
//

View File

@@ -1,5 +1,5 @@
using StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using Logic;
using Models;
namespace WinForms
{

View File

@@ -1,5 +1,5 @@
using StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using Logic;
using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -34,7 +34,6 @@ namespace WinForms
if (user != null)
{
tbUsername.Text = user.Name;
tbPassword.Text = user.Password;
cbUserRole.SelectedIndex = (int)user.Role;
}
@@ -55,7 +54,14 @@ namespace WinForms
}
else
{
userManager.UpdateUser(this.user.ID, tbUsername.Text, BCrypt.Net.BCrypt.HashPassword(tbPassword.Text), (UserRole)cbUserRole.SelectedItem);
if (string.IsNullOrEmpty(tbPassword.Text))
{
//userManager.UpdateUser(this.user.ID, tbUsername.Text,)
}
else
{
userManager.UpdateUser(this.user.ID, tbUsername.Text, BCrypt.Net.BCrypt.HashPassword(tbPassword.Text), (UserRole)cbUserRole.SelectedItem);
}
}
this.DialogResult = DialogResult.OK;
}

View File

@@ -10,7 +10,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\HouseData\StudentHouseDashboard.csproj" />
<ProjectReference Include="..\Logic\Logic.csproj" />
<ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup>
<ItemGroup>