diff --git a/StudentHouseDashboard/HouseData/ClassDiagram1.cd b/StudentHouseDashboard/HouseData/ClassDiagram1.cd index d453a73..5ce63f9 100644 --- a/StudentHouseDashboard/HouseData/ClassDiagram1.cd +++ b/StudentHouseDashboard/HouseData/ClassDiagram1.cd @@ -1,74 +1,72 @@  - - - AAAACAAAAAEgAEAAiAAAAAAAAAAAAAAAAAAAAAAAIhA= - Models\Announcement.cs - - - - - - - AAAAAAAAAAFgAEAAiAAAAAAAAAAAAAAAAAAAAAAAABA= - Models\Comment.cs - - - - - AAAAAAAEAAAgAEAAiAAAAAAAAAAAAAAAAAAAAAQAAAA= - Models\Complaint.cs + AAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIhA= + Models\Announcement.cs - + - + - AAAAAAAAAAEgAEAAiAAAAAAgAAAAAAAAAAAAAEAAABA= + AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA= + Models\Comment.cs + + + + + + + AAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAA= + Models\Complaint.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAEAAAAA= Models\Event.cs - - AAAAAAAAAAAAAAAAEQAAAAAAAAAAAAAAAAAAAAAAAAA= + AAAAAAAAAAAAAAAAEAAAABQAAAAEAAACAAAAAgAAAAA= Models\User.cs - - + + - AAAAAAAAAAAgAEAAiAAAAAAAAAAAAAAAAAAAAAAAAAA= - Models\IMessage.cs + AAAAAAAAQAAoAEAAqAAAAIAAAAAAAAAAAAAAAAAAAAA= + Models\GenericMessage.cs - + - + AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA= Models\IVotable.cs - + AAAEgAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= Models\ComplaintSeverity.cs - + AAAAAAAABAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAA= Models\ComplaintStatus.cs - + AAQAAAAAAAAAAAAAAAAAAAAAQAAAAQAAAAAAAAAAAAA= Models\UserRole.cs diff --git a/StudentHouseDashboard/HouseData/Managers/AnnouncementManager.cs b/StudentHouseDashboard/HouseData/Managers/AnnouncementManager.cs new file mode 100644 index 0000000..197b6e4 --- /dev/null +++ b/StudentHouseDashboard/HouseData/Managers/AnnouncementManager.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentHouseDashboard.Managers +{ + public class AnnouncementManager + { + } +} diff --git a/StudentHouseDashboard/HouseData/Managers/UserManager.cs b/StudentHouseDashboard/HouseData/Managers/UserManager.cs new file mode 100644 index 0000000..76ac731 --- /dev/null +++ b/StudentHouseDashboard/HouseData/Managers/UserManager.cs @@ -0,0 +1,41 @@ +using StudentHouseDashboard.Models; +using StudentHouseDashboard.Repositories; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace StudentHouseDashboard.Managers +{ + public class UserManager + { + private UserRepository userRepository; + public UserManager() + { + userRepository = new UserRepository(); + } + public List GetAllUsers() + { + return userRepository.GetAllUsers(); + } + public User GetUserById(int id) + { + return userRepository.GetUserById(id); + } + public bool CreateUser(string name, string password, UserRole role) + { + return userRepository.CreateUser(name, password, role); + } + public void UpdateUser(int id, string name, string password, UserRole role) + { + userRepository.UpdateUser(id, name, password, role); + } + public void DisableUser(int id) + { + userRepository.DisableUser(id); + } + } +} diff --git a/StudentHouseDashboard/HouseData/Models/Announcement.cs b/StudentHouseDashboard/HouseData/Models/Announcement.cs index 13942eb..5b7b6b3 100644 --- a/StudentHouseDashboard/HouseData/Models/Announcement.cs +++ b/StudentHouseDashboard/HouseData/Models/Announcement.cs @@ -5,37 +5,29 @@ using System.Text; namespace StudentHouseDashboard.Models { - public class Announcement : IMessage, IVotable + public class Announcement : GenericMessage, IVotable { + public Announcement(User author, string description, string title, DateTime publishDate, bool isImportant, bool isSticky) : base(author, description, title, publishDate) + { + IsImportant = isImportant; + IsSticky = isSticky; + } + public List Comments { - get => default; - set - { - } + get;set; } - public int IsImportant + public bool IsImportant { - get => default; - set - { - } + get;set; } - public int IsSticky + public bool IsSticky { - get => default; - set - { - } + get; set; } - public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public void DownVote() { throw new NotImplementedException(); diff --git a/StudentHouseDashboard/HouseData/Models/Comment.cs b/StudentHouseDashboard/HouseData/Models/Comment.cs index 986e658..f3f7b69 100644 --- a/StudentHouseDashboard/HouseData/Models/Comment.cs +++ b/StudentHouseDashboard/HouseData/Models/Comment.cs @@ -5,19 +5,11 @@ using System.Text; namespace StudentHouseDashboard.Models { - public class Comment : IMessage, IVotable + public class Comment : GenericMessage, IVotable { - public int Responses + public Comment(User author, string description, string title, DateTime publishDate) : base(author, description, title, publishDate) { - get => default; - set - { - } } - public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public void DownVote() { diff --git a/StudentHouseDashboard/HouseData/Models/Complaint.cs b/StudentHouseDashboard/HouseData/Models/Complaint.cs index aca9789..8700a2c 100644 --- a/StudentHouseDashboard/HouseData/Models/Complaint.cs +++ b/StudentHouseDashboard/HouseData/Models/Complaint.cs @@ -5,27 +5,27 @@ using System.Text; namespace StudentHouseDashboard.Models { - public class Complaint : IMessage + public class Complaint : GenericMessage { + public Complaint(User author, string description, string title, DateTime publishDate, ComplaintStatus status, ComplaintSeverity severity) : base(author, description, title, publishDate) + { + Status = status; + Severity = severity; + } + public ComplaintStatus Status { - get => default; - set - { - } + get;set; } public ComplaintSeverity Severity { - get => default; - set - { - } + get;set; } - public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public List Responses + { + get;set; + } } } \ No newline at end of file diff --git a/StudentHouseDashboard/HouseData/Models/Event.cs b/StudentHouseDashboard/HouseData/Models/Event.cs index 7b95477..8823179 100644 --- a/StudentHouseDashboard/HouseData/Models/Event.cs +++ b/StudentHouseDashboard/HouseData/Models/Event.cs @@ -5,37 +5,22 @@ using System.Text; namespace StudentHouseDashboard.Models { - public class Event : IMessage, IVotable + public class Event : GenericMessage { - public int StartDate + public Event(User author, string description, string title, DateTime publishDate, DateTime startDate, DateTime endDate) : base(author, description, title, publishDate) { - get => default; - set - { - } + StartDate = startDate; + EndDate = endDate; } - public int EndDate + public DateTime StartDate { - get => default; - set - { - } + get;set; } - public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public void DownVote() + public DateTime EndDate { - throw new NotImplementedException(); - } - - public void UpVote() - { - throw new NotImplementedException(); + get;set; } } } \ No newline at end of file diff --git a/StudentHouseDashboard/HouseData/Models/GenericMessage.cs b/StudentHouseDashboard/HouseData/Models/GenericMessage.cs new file mode 100644 index 0000000..3ba7d1b --- /dev/null +++ b/StudentHouseDashboard/HouseData/Models/GenericMessage.cs @@ -0,0 +1,45 @@ +using StudentHouseDashboard.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace StudentHouseDashboard +{ + public abstract class GenericMessage + { + private User author; + private string description; + private string title; + private DateTime publishDate; + + protected GenericMessage(User author, string description, string title, DateTime publishDate) + { + Author = author; + Description = description; + Title = title; + PublishDate = publishDate; + } + + public User Author + { + get => author; + set => author = value; + } + public string Description + { + get => description; + set => description = value; + } + public string Title + { + get => title; + set => title = value; + } + public DateTime PublishDate + { + get => publishDate; + set => publishDate = value; + } + } +} \ No newline at end of file diff --git a/StudentHouseDashboard/HouseData/Models/IMessage.cs b/StudentHouseDashboard/HouseData/Models/IMessage.cs deleted file mode 100644 index b463fc4..0000000 --- a/StudentHouseDashboard/HouseData/Models/IMessage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace StudentHouseDashboard.Models -{ - public interface IMessage - { - string Title { get; set; } - string Description { get; set; } - User Author { get; set; } - DateTime PublishDate { get; set; } - } -} \ No newline at end of file diff --git a/StudentHouseDashboard/HouseData/Models/IVotable.cs b/StudentHouseDashboard/HouseData/Models/IVotable.cs index 8d3fcf2..5b8c37c 100644 --- a/StudentHouseDashboard/HouseData/Models/IVotable.cs +++ b/StudentHouseDashboard/HouseData/Models/IVotable.cs @@ -7,7 +7,13 @@ namespace StudentHouseDashboard.Models { public interface IVotable { - void UpVote(); - void DownVote(); + void UpVote() + { + throw new NotImplementedException(); + } + void DownVote() + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/StudentHouseDashboard/HouseData/Models/User.cs b/StudentHouseDashboard/HouseData/Models/User.cs index 28e4a2e..5f892d5 100644 --- a/StudentHouseDashboard/HouseData/Models/User.cs +++ b/StudentHouseDashboard/HouseData/Models/User.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; @@ -7,20 +8,42 @@ namespace StudentHouseDashboard.Models { public class User { - public User(int username, UserRole role) + private int id; + private string name; + private string password; + private UserRole role; + + public User(int id, string name, string password, UserRole role) { - Username = username; + Id = id; + Name = name; + Password = password; Role = role; } - - public int Username + public User() { - get;set; + + } + public int Id + { + get; private set; } + public string Name + { + get => name; + set => name = value; + } + [PasswordPropertyText(true)] + public string Password + { + get => password; + set => password = value; + } public UserRole Role { - get;set; + get => role; + set => role = value; } } } \ No newline at end of file diff --git a/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs b/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs new file mode 100644 index 0000000..55d7297 --- /dev/null +++ b/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs @@ -0,0 +1,53 @@ +using StudentHouseDashboard.Managers; +using StudentHouseDashboard.Models; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentHouseDashboard.Repositories +{ + public class AnnouncementRepository + { + private string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;"; + public AnnouncementRepository() { } + private SqlConnection CreateConnection() + { + SqlConnection connection = new SqlConnection(connectionString); + try + { + connection.Open(); + } + catch (Exception) + { + Console.WriteLine("Database connection error. Are you connected to the VDI VPN?"); + } + + return connection; + } + public List GetAllAnnouncements() + { + var announcements = new List(); + UserManager userManager = new UserManager(); + using (SqlConnection conn = CreateConnection()) + { + string sql = "SELECT * FROM Announcements;"; + SqlCommand cmd = new SqlCommand(sql, conn); + var reader = cmd.ExecuteReader(); + + while (reader.Read()) + { + // ID, Name, Password, Role + announcements.Add(new Announcement(userManager.GetUserById(Convert.ToInt32(reader["ID"])), + reader["Description"].ToString(), reader["Title"].ToString(), + (DateTime)reader["PublishDate"], (bool)reader["IsImportant"], + (bool)reader["IsSticky"])); + } + conn.Close(); + } + return announcements; + } + } +} diff --git a/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs b/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs new file mode 100644 index 0000000..66e4ef0 --- /dev/null +++ b/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Data.SqlClient; +using StudentHouseDashboard.Models; +using System.Data; +using System.Xml.Linq; + +namespace StudentHouseDashboard.Repositories +{ + public class UserRepository + { + private string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;"; + + public UserRepository() { } + private SqlConnection CreateConnection() + { + SqlConnection connection = new SqlConnection(connectionString); + try + { + connection.Open(); + } + catch (Exception) + { + Console.WriteLine("Database connection error. Are you connected to the VDI VPN?"); + } + + return connection; + } + public List GetAllUsers() + { + var users = new List(); + + using (SqlConnection conn = CreateConnection()) + { + string sql = "SELECT * FROM Users;"; + SqlCommand cmd = new SqlCommand(sql, conn); + var reader = cmd.ExecuteReader(); + + while (reader.Read()) + { + // ID, Name, Password, Role + users.Add(new User(Convert.ToInt32(reader["ID"]), + reader["Name"].ToString(), + reader["Password"].ToString(), + (UserRole)reader["Role"]) + ); + } + conn.Close(); + } + return users; + } + public User GetUserById(int id) + { + using (SqlConnection conn = CreateConnection()) + { + string sql = "SELECT * FROM Users WHERE ID = @id;"; + SqlCommand cmd = new SqlCommand(sql, conn); + cmd.Parameters.AddWithValue("@id", id); + var reader = cmd.ExecuteReader(); + + reader.Read(); + // ID, Name, Password, Role + return new User(Convert.ToInt32(reader["ID"]), + reader["Name"].ToString(), + reader["Password"].ToString(), + (UserRole)reader["Role"]); + } + } + public bool CreateUser(string name, string password, UserRole role) + { + using (SqlConnection conn = CreateConnection()) + { + string sql = "INSERT INTO Users (Name, Password, Role) VALUES (@name, @pass, @role);"; + SqlCommand cmd = new SqlCommand(sql, conn); + cmd.Parameters.AddWithValue("@name", name); + cmd.Parameters.AddWithValue("@pass", password); + cmd.Parameters.AddWithValue("@role", (int)role); + int writer = cmd.ExecuteNonQuery(); + if (writer == 1) + { + return true; + } + else return false; + } + } + public bool UpdateUser(int id, string name, string password, UserRole role) + { + using (SqlConnection conn = CreateConnection()) + { + string sql = "UPDATE Users " + + "SET Name = @name, Password = @pass, Role = @role " + + "WHERE ID = @id;"; + SqlCommand cmd = new SqlCommand(sql, conn); + cmd.Parameters.AddWithValue("@name", name); + cmd.Parameters.AddWithValue("@pass", password); + cmd.Parameters.AddWithValue("@role", (int)role); + cmd.Parameters.AddWithValue("@id", id); + int writer = cmd.ExecuteNonQuery(); + if (writer == 1) + { + return true; + } + else return false; + } + } + public bool DisableUser(int id) + { + using (SqlConnection conn = CreateConnection()) + { + string sql = "UPDATE Users " + + "SET Name = 'Deleted User @id', Password = '0', Role = @role " + + "WHERE ID = @id;"; + SqlCommand cmd = new SqlCommand(sql, conn); + cmd.Parameters.AddWithValue("@id", id); + int writer = cmd.ExecuteNonQuery(); + if (writer == 1) + { + return true; + } + else return false; + } + } + } +} diff --git a/StudentHouseDashboard/HouseData/StudentHouseDashboard.csproj b/StudentHouseDashboard/HouseData/StudentHouseDashboard.csproj index e83ebeb..4c947ef 100644 --- a/StudentHouseDashboard/HouseData/StudentHouseDashboard.csproj +++ b/StudentHouseDashboard/HouseData/StudentHouseDashboard.csproj @@ -7,7 +7,7 @@ - + diff --git a/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml new file mode 100644 index 0000000..aade10c --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml @@ -0,0 +1,4 @@ +@page +@model WebApp.Pages.AnnouncementModel +@{ +} diff --git a/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs new file mode 100644 index 0000000..703589b --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Pages +{ + public class AnnouncementModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml new file mode 100644 index 0000000..596e222 --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml @@ -0,0 +1,15 @@ +@page +@model WebApp.Pages.AnnouncementsModel +@{ + ViewData["Title"] = "Announcements"; +} + +
+
+
Card title
+
Card subtitle
+

Some quick example text to build on the card title and make up the bulk of the card's content.

+ Card link + Another link +
+
diff --git a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs new file mode 100644 index 0000000..98595e8 --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Pages +{ + public class AnnouncementsModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/StudentHouseDashboard/WebApp/Pages/Login.cshtml b/StudentHouseDashboard/WebApp/Pages/Login.cshtml new file mode 100644 index 0000000..b8e10fe --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Login.cshtml @@ -0,0 +1,26 @@ +@page +@model WebApp.Pages.LoginModel +@{ + ViewData["Title"] = "Login"; +} + +

@ViewData["Title"]

+ +@if (ViewData["confirm"] != null) +{ + +} + +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs new file mode 100644 index 0000000..cd37796 --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using StudentHouseDashboard.Models; +using StudentHouseDashboard.Managers; + +namespace WebApp.Pages +{ + public class LoginModel : PageModel + { + [BindProperty] + public User MyUser { get; set; } + + public void OnGet() + { + } + + public void OnPost() + { + var userManager = new UserManager(); + + foreach (var item in userManager.GetAllUsers()) + { + if (item.Name == MyUser.Name && BCrypt.Net.BCrypt.Verify(MyUser.Password, item.Password)) + { + MyUser = item; + ViewData["confirm"] = $"Welcome, {MyUser.Name}! {MyUser.Id}, {MyUser.Password}, {MyUser.Role}"; + } + } + + } + } +} diff --git a/StudentHouseDashboard/WebApp/Pages/Register.cshtml b/StudentHouseDashboard/WebApp/Pages/Register.cshtml new file mode 100644 index 0000000..86b7fd6 --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Register.cshtml @@ -0,0 +1,30 @@ +@page +@model WebApp.Pages.RegisterModel +@{ + ViewData["Title"] = "Register"; +} + +

@ViewData["Title"]

+ +@if (ViewData["confirm"] != null) +{ + +} + +
+
+ + +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs new file mode 100644 index 0000000..7c0fb3f --- /dev/null +++ b/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using StudentHouseDashboard.Managers; +using StudentHouseDashboard.Models; + +namespace WebApp.Pages +{ + public class RegisterModel : PageModel + { + [BindProperty] + public User MyUser { get; set; } + public void OnGet() + { + } + public void OnPost() + { + var userManager = new UserManager(); + if (userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role)) + { + ViewData["confirm"] = $"Successfully registered {MyUser.Name}!"; + } + } + } +} diff --git a/StudentHouseDashboard/WebApp/Pages/Shared/_Layout.cshtml b/StudentHouseDashboard/WebApp/Pages/Shared/_Layout.cshtml index 1f32b26..aed1928 100644 --- a/StudentHouseDashboard/WebApp/Pages/Shared/_Layout.cshtml +++ b/StudentHouseDashboard/WebApp/Pages/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - WebApp + @ViewData["Title"] - StudentHouseDashboard @@ -12,7 +12,7 @@