diff --git a/README.md b/README.md index 8e1dccd..90228f6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,24 @@ # Student House Dashboard -Work in progress - Project documentation is available in the docs folder + +## Default user details + +### System administrator +admin +admin + +### Manager +manager +manager + +### Tenant +room1 +room1 + +room2 +room2 + +## FHICT Luna server + +The web application is hosted on the FHICT Luna server at: https://i509645.luna.fhict.nl/ \ No newline at end of file diff --git a/StudentHouseDashboard/Data/AnnouncementRepository.cs b/StudentHouseDashboard/Data/AnnouncementRepository.cs index 8708a47..373d1e0 100644 --- a/StudentHouseDashboard/Data/AnnouncementRepository.cs +++ b/StudentHouseDashboard/Data/AnnouncementRepository.cs @@ -1,13 +1,8 @@ -using Models; -using Logic; -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Logic; using Logic.Exceptions; -using System.Reflection; +using Models; +using System.Data.SqlClient; +using System.Text; namespace Data { @@ -50,13 +45,13 @@ namespace Data cmd.Parameters.AddWithValue("id", id); var reader = cmd.ExecuteReader(); reader.Read(); - Announcement announcement = new Announcement(Convert.ToInt32(reader["ID"]), - userRepository.GetUserById(Convert.ToInt32(reader["Author"])), - reader["Description"].ToString(), reader["Title"].ToString(), - (DateTime)reader["PublishDate"], (bool)reader["IsImportant"], - (bool)reader["IsSticky"]); - CommentRepository commentRepository = new CommentRepository(); - announcement.Comments = commentRepository.GetAllCommentsOnAnnouncement(announcement.ID); + Announcement announcement = new Announcement(Convert.ToInt32(reader["ID"]), + userRepository.GetUserById(Convert.ToInt32(reader["Author"])), + reader["Description"].ToString(), reader["Title"].ToString(), + (DateTime)reader["PublishDate"], (bool)reader["IsImportant"], + (bool)reader["IsSticky"]); + CommentRepository commentRepository = new CommentRepository(); + announcement.Comments = commentRepository.GetAllCommentsOnAnnouncement(announcement.ID); conn.Close(); return announcement; } diff --git a/StudentHouseDashboard/Data/CommentRepository.cs b/StudentHouseDashboard/Data/CommentRepository.cs index 225807a..bcbb098 100644 --- a/StudentHouseDashboard/Data/CommentRepository.cs +++ b/StudentHouseDashboard/Data/CommentRepository.cs @@ -1,8 +1,7 @@ -using System.ComponentModel.Design; -using System.Data.SqlClient; -using Models; using Logic; using Logic.Exceptions; +using Models; +using System.Data.SqlClient; namespace Data; diff --git a/StudentHouseDashboard/Data/ComplaintRepository.cs b/StudentHouseDashboard/Data/ComplaintRepository.cs index d1d4eed..496922d 100644 --- a/StudentHouseDashboard/Data/ComplaintRepository.cs +++ b/StudentHouseDashboard/Data/ComplaintRepository.cs @@ -1,12 +1,8 @@ using Logic; using Logic.Exceptions; using Models; -using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Data { @@ -14,7 +10,7 @@ namespace Data { public ComplaintRepository() { - + } public List GetAllComplaints() { @@ -86,7 +82,7 @@ namespace Data } using (SqlConnection conn = SqlConnectionHelper.CreateConnection()) { - + SqlCommand sqlCommand = new SqlCommand(sql, conn); sqlCommand.Parameters.AddWithValue("@start", p * c); sqlCommand.Parameters.AddWithValue("@count", c); diff --git a/StudentHouseDashboard/Data/EventRepository.cs b/StudentHouseDashboard/Data/EventRepository.cs index 42c8b05..7ef4db6 100644 --- a/StudentHouseDashboard/Data/EventRepository.cs +++ b/StudentHouseDashboard/Data/EventRepository.cs @@ -1,12 +1,7 @@ using Logic; using Logic.Exceptions; using Models; -using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Data { diff --git a/StudentHouseDashboard/Data/SqlConnectionHelper.cs b/StudentHouseDashboard/Data/SqlConnectionHelper.cs index 9b03e2d..77c5f15 100644 --- a/StudentHouseDashboard/Data/SqlConnectionHelper.cs +++ b/StudentHouseDashboard/Data/SqlConnectionHelper.cs @@ -1,10 +1,5 @@ using Logic.Exceptions; -using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Data { diff --git a/StudentHouseDashboard/Data/UserRepository.cs b/StudentHouseDashboard/Data/UserRepository.cs index 1cfbfa1..3688a0f 100644 --- a/StudentHouseDashboard/Data/UserRepository.cs +++ b/StudentHouseDashboard/Data/UserRepository.cs @@ -1,13 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Data.SqlClient; +using Logic; using Models; -using System.Data; -using System.Xml.Linq; -using Logic; +using System.Data.SqlClient; namespace Data { @@ -115,7 +108,7 @@ namespace Data } } - public User GetUserByName(string userName) + public User? GetUserByName(string userName) { using (SqlConnection conn = SqlConnectionHelper.CreateConnection()) { @@ -124,8 +117,14 @@ namespace Data cmd.Parameters.AddWithValue("@userName", userName); var reader = cmd.ExecuteReader(); - return new User(Convert.ToInt32(reader["ID"]), reader["Name"].ToString(), + if (reader.HasRows) + { + reader.Read(); + return new User(Convert.ToInt32(reader["ID"]), reader["Name"].ToString(), reader["Password"].ToString(), (UserRole)reader["Role"]); + } + else { return null; } + } } } diff --git a/StudentHouseDashboard/Logic/AnnouncementManager.cs b/StudentHouseDashboard/Logic/AnnouncementManager.cs index 2874e95..f571453 100644 --- a/StudentHouseDashboard/Logic/AnnouncementManager.cs +++ b/StudentHouseDashboard/Logic/AnnouncementManager.cs @@ -1,11 +1,5 @@ using Models; -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; namespace Logic { diff --git a/StudentHouseDashboard/Logic/CommentManager.cs b/StudentHouseDashboard/Logic/CommentManager.cs index 04a4a33..b20d102 100644 --- a/StudentHouseDashboard/Logic/CommentManager.cs +++ b/StudentHouseDashboard/Logic/CommentManager.cs @@ -1,9 +1,4 @@ using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Logic { @@ -14,7 +9,7 @@ namespace Logic { this.commentRepository = commentRepository; } - + public Comment GetCommentById(int id) { return commentRepository.GetCommentById(id); diff --git a/StudentHouseDashboard/Logic/ComplaintManager.cs b/StudentHouseDashboard/Logic/ComplaintManager.cs index a595710..30d06de 100644 --- a/StudentHouseDashboard/Logic/ComplaintManager.cs +++ b/StudentHouseDashboard/Logic/ComplaintManager.cs @@ -1,16 +1,11 @@ using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Logic { public class ComplaintManager { private IComplaintRepository complaintRepository; - public ComplaintManager(IComplaintRepository complaintRepository) + public ComplaintManager(IComplaintRepository complaintRepository) { this.complaintRepository = complaintRepository; } diff --git a/StudentHouseDashboard/Logic/EventManager.cs b/StudentHouseDashboard/Logic/EventManager.cs index 79847f2..7baad53 100644 --- a/StudentHouseDashboard/Logic/EventManager.cs +++ b/StudentHouseDashboard/Logic/EventManager.cs @@ -1,9 +1,4 @@ using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Logic { @@ -14,7 +9,7 @@ namespace Logic { this.eventRepository = eventRepository; } - public List GetAllEvents() + public List GetAllEvents() { return eventRepository.GetAllEvents(); } diff --git a/StudentHouseDashboard/Logic/Exceptions/DatabaseNetworkException.cs b/StudentHouseDashboard/Logic/Exceptions/DatabaseNetworkException.cs index 0f16393..b175618 100644 --- a/StudentHouseDashboard/Logic/Exceptions/DatabaseNetworkException.cs +++ b/StudentHouseDashboard/Logic/Exceptions/DatabaseNetworkException.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; +using System.Net; namespace Logic.Exceptions { diff --git a/StudentHouseDashboard/Logic/Exceptions/DatabaseOperationException.cs b/StudentHouseDashboard/Logic/Exceptions/DatabaseOperationException.cs index 28ff46c..cbe24d6 100644 --- a/StudentHouseDashboard/Logic/Exceptions/DatabaseOperationException.cs +++ b/StudentHouseDashboard/Logic/Exceptions/DatabaseOperationException.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Logic.Exceptions +namespace Logic.Exceptions { public class DatabaseOperationException : ApplicationException { diff --git a/StudentHouseDashboard/Logic/IAnnouncementRepository.cs b/StudentHouseDashboard/Logic/IAnnouncementRepository.cs index 3cbb7ad..fb55db2 100644 --- a/StudentHouseDashboard/Logic/IAnnouncementRepository.cs +++ b/StudentHouseDashboard/Logic/IAnnouncementRepository.cs @@ -1,10 +1,4 @@ using Models; -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Logic { diff --git a/StudentHouseDashboard/Logic/ICommentRepository.cs b/StudentHouseDashboard/Logic/ICommentRepository.cs index 9217df7..4476fcb 100644 --- a/StudentHouseDashboard/Logic/ICommentRepository.cs +++ b/StudentHouseDashboard/Logic/ICommentRepository.cs @@ -1,5 +1,3 @@ -using System.ComponentModel.Design; -using System.Data.SqlClient; using Models; namespace Logic; diff --git a/StudentHouseDashboard/Logic/IComplaintRepository.cs b/StudentHouseDashboard/Logic/IComplaintRepository.cs index 1f7260a..ef72ea1 100644 --- a/StudentHouseDashboard/Logic/IComplaintRepository.cs +++ b/StudentHouseDashboard/Logic/IComplaintRepository.cs @@ -1,10 +1,4 @@ -using Logic.Exceptions; -using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Models; namespace Logic { diff --git a/StudentHouseDashboard/Logic/IEventRepository.cs b/StudentHouseDashboard/Logic/IEventRepository.cs index aae4bd9..32aaada 100644 --- a/StudentHouseDashboard/Logic/IEventRepository.cs +++ b/StudentHouseDashboard/Logic/IEventRepository.cs @@ -1,9 +1,4 @@ using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Logic { @@ -17,4 +12,3 @@ namespace Logic public void DeleteEvent(int id); } } - \ No newline at end of file diff --git a/StudentHouseDashboard/Logic/IUserRepository.cs b/StudentHouseDashboard/Logic/IUserRepository.cs index 0ef7674..8daf2d4 100644 --- a/StudentHouseDashboard/Logic/IUserRepository.cs +++ b/StudentHouseDashboard/Logic/IUserRepository.cs @@ -1,9 +1,4 @@ using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Logic { diff --git a/StudentHouseDashboard/Logic/UserManager.cs b/StudentHouseDashboard/Logic/UserManager.cs index 6277289..6bd38b5 100644 --- a/StudentHouseDashboard/Logic/UserManager.cs +++ b/StudentHouseDashboard/Logic/UserManager.cs @@ -1,14 +1,4 @@ -using BCrypt.Net; -using Models; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Net.Http; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; +using Models; namespace Logic { diff --git a/StudentHouseDashboard/Models/Announcement.cs b/StudentHouseDashboard/Models/Announcement.cs index d496073..716798b 100644 --- a/StudentHouseDashboard/Models/Announcement.cs +++ b/StudentHouseDashboard/Models/Announcement.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Models +namespace Models { public class Announcement : GenericMessage { @@ -15,16 +10,16 @@ namespace Models public Announcement() { - + } public List Comments { - get;set; + get; set; } public bool IsImportant { - get;set; + get; set; } public bool IsSticky diff --git a/StudentHouseDashboard/Models/Comment.cs b/StudentHouseDashboard/Models/Comment.cs index a49b81a..e080679 100644 --- a/StudentHouseDashboard/Models/Comment.cs +++ b/StudentHouseDashboard/Models/Comment.cs @@ -1,21 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Models +namespace Models { public class Comment : GenericMessage { public Comment() { - + } public Comment(int id, User author, string description, string title, DateTime publishDate) : base(id, author, description, title, publishDate) { Responses = new List(); } - + public List Responses { get; set; } public override string ToString() { diff --git a/StudentHouseDashboard/Models/Complaint.cs b/StudentHouseDashboard/Models/Complaint.cs index f47a582..b1a3d7b 100644 --- a/StudentHouseDashboard/Models/Complaint.cs +++ b/StudentHouseDashboard/Models/Complaint.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Models +namespace Models { public class Complaint : GenericMessage { public Complaint() { - + } public Complaint(int id, User author, string description, string title, DateTime publishDate, ComplaintStatus status, ComplaintSeverity severity) : base(id, author, description, title, publishDate) { @@ -19,17 +14,17 @@ namespace Models public ComplaintStatus Status { - get;set; + get; set; } public ComplaintSeverity Severity { - get;set; + get; set; } public List Responses { - get;set; + get; set; } public override string ToString() { diff --git a/StudentHouseDashboard/Models/ComplaintSeverity.cs b/StudentHouseDashboard/Models/ComplaintSeverity.cs index 0323eb6..c141f2f 100644 --- a/StudentHouseDashboard/Models/ComplaintSeverity.cs +++ b/StudentHouseDashboard/Models/ComplaintSeverity.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; +using System.ComponentModel; namespace Models { diff --git a/StudentHouseDashboard/Models/ComplaintStatus.cs b/StudentHouseDashboard/Models/ComplaintStatus.cs index 712f9cd..af73357 100644 --- a/StudentHouseDashboard/Models/ComplaintStatus.cs +++ b/StudentHouseDashboard/Models/ComplaintStatus.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; +using System.ComponentModel; namespace Models { diff --git a/StudentHouseDashboard/Models/Event.cs b/StudentHouseDashboard/Models/Event.cs index 8e83f5f..56404b0 100644 --- a/StudentHouseDashboard/Models/Event.cs +++ b/StudentHouseDashboard/Models/Event.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Models +namespace Models { public class Event : GenericMessage { public Event() { - + } public Event(int id, User author, string description, string title, DateTime publishDate, DateTime startDate, DateTime endDate) : base(id, author, description, title, publishDate) { @@ -19,12 +14,12 @@ namespace Models public DateTime StartDate { - get;set; + get; set; } public DateTime EndDate { - get;set; + get; set; } public override string ToString() { diff --git a/StudentHouseDashboard/Models/GenericMessage.cs b/StudentHouseDashboard/Models/GenericMessage.cs index 30e86ab..802575d 100644 --- a/StudentHouseDashboard/Models/GenericMessage.cs +++ b/StudentHouseDashboard/Models/GenericMessage.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; +using System.ComponentModel.DataAnnotations; namespace Models { @@ -18,7 +14,7 @@ namespace Models } protected GenericMessage() { - + } public int ID { @@ -27,16 +23,16 @@ namespace Models public User Author { - get;set; + get; set; } public string Description { - get;set; + get; set; } [StringLength(255)] public string Title { - get;set; + get; set; } public DateTime PublishDate { diff --git a/StudentHouseDashboard/Models/User.cs b/StudentHouseDashboard/Models/User.cs index 08f65b3..179ce13 100644 --- a/StudentHouseDashboard/Models/User.cs +++ b/StudentHouseDashboard/Models/User.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; +using System.ComponentModel.DataAnnotations; namespace Models { @@ -25,13 +20,17 @@ namespace Models { get; set; } + + [Required] [StringLength(255)] public string Name { get; set; } + [Required] [DataType(DataType.Password)] + [StringLength(int.MaxValue, MinimumLength = 4)] public string Password { get; set; diff --git a/StudentHouseDashboard/Models/UserRole.cs b/StudentHouseDashboard/Models/UserRole.cs index 44d2522..c0abf98 100644 --- a/StudentHouseDashboard/Models/UserRole.cs +++ b/StudentHouseDashboard/Models/UserRole.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; +using System.ComponentModel; namespace Models { diff --git a/StudentHouseDashboard/Tests/AnnouncementManagerTest.cs b/StudentHouseDashboard/Tests/AnnouncementManagerTest.cs index cbed56c..e144cf3 100644 --- a/StudentHouseDashboard/Tests/AnnouncementManagerTest.cs +++ b/StudentHouseDashboard/Tests/AnnouncementManagerTest.cs @@ -1,10 +1,5 @@ using Logic; using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Tests.Mocks; namespace Tests diff --git a/StudentHouseDashboard/Tests/Mocks/AnnouncementRepositoryFake.cs b/StudentHouseDashboard/Tests/Mocks/AnnouncementRepositoryFake.cs index 4908210..50140ac 100644 --- a/StudentHouseDashboard/Tests/Mocks/AnnouncementRepositoryFake.cs +++ b/StudentHouseDashboard/Tests/Mocks/AnnouncementRepositoryFake.cs @@ -1,13 +1,6 @@ using Logic; using Models; -using System; -using System.Collections.Generic; using System.Data; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; namespace Tests.Mocks { @@ -16,7 +9,7 @@ namespace Tests.Mocks private List announcements; private int currentId; - public AnnouncementRepositoryFake() + public AnnouncementRepositoryFake() { announcements = new List(); currentId = 1; diff --git a/StudentHouseDashboard/Tests/Mocks/UserRepositoryFake.cs b/StudentHouseDashboard/Tests/Mocks/UserRepositoryFake.cs index cb2d411..15f8e53 100644 --- a/StudentHouseDashboard/Tests/Mocks/UserRepositoryFake.cs +++ b/StudentHouseDashboard/Tests/Mocks/UserRepositoryFake.cs @@ -1,10 +1,5 @@ -using Models; -using Logic; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Logic; +using Models; namespace Tests.Mocks { @@ -12,7 +7,7 @@ namespace Tests.Mocks { private List users; private int currentId; - public UserRepositoryFake() + public UserRepositoryFake() { users = new List(); currentId = 1; diff --git a/StudentHouseDashboard/Tests/UserManagerTest.cs b/StudentHouseDashboard/Tests/UserManagerTest.cs index b7496b7..392224d 100644 --- a/StudentHouseDashboard/Tests/UserManagerTest.cs +++ b/StudentHouseDashboard/Tests/UserManagerTest.cs @@ -1,4 +1,3 @@ -using BCrypt.Net; using Logic; using Models; using Tests.Mocks; @@ -26,7 +25,7 @@ namespace Tests // Assert Assert.IsNull(result); } - + [TestMethod] [ExpectedException(typeof(ArgumentException))] public void AuthenticatedUserNullPasswordTest() @@ -133,7 +132,7 @@ namespace Tests // Assert // ArgumentException expected } - + [TestMethod] public void DisableUserTest() { @@ -148,6 +147,6 @@ namespace Tests Assert.AreEqual(user.Name, $"Deleted User {user.ID}"); Assert.AreEqual(user.Password, "0"); } - + } } \ No newline at end of file diff --git a/StudentHouseDashboard/WebApp/Pages/AddComment.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/AddComment.cshtml.cs index 3a1b63c..384bc8b 100644 --- a/StudentHouseDashboard/WebApp/Pages/AddComment.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/AddComment.cshtml.cs @@ -1,5 +1,4 @@ using Logic; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Models; diff --git a/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs index e0ad809..aae6ded 100644 --- a/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs @@ -1,9 +1,6 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Logic; -using Models; -using Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs index 919394a..b28787f 100644 --- a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs @@ -1,9 +1,7 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Logic; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; using Models; -using System.Security.Claims; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Complaint.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Complaint.cshtml.cs index be8479f..54d0f57 100644 --- a/StudentHouseDashboard/WebApp/Pages/Complaint.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Complaint.cshtml.cs @@ -1,9 +1,6 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Logic; -using Models; -using Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Complaints.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Complaints.cshtml.cs index 6f1cb2c..f6398f3 100644 --- a/StudentHouseDashboard/WebApp/Pages/Complaints.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Complaints.cshtml.cs @@ -1,8 +1,6 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Logic; -using Models; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; using System.Security.Claims; namespace WebApp.Pages diff --git a/StudentHouseDashboard/WebApp/Pages/EditAnnouncement.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/EditAnnouncement.cshtml.cs index d35567d..989114b 100644 --- a/StudentHouseDashboard/WebApp/Pages/EditAnnouncement.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/EditAnnouncement.cshtml.cs @@ -24,7 +24,7 @@ namespace WebApp.Pages if (id != null) { Announcement announcement = announcementManager.GetAnnouncementById(id); - if (announcement.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN") ) + if (announcement.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN")) { ViewData["announcement"] = announcement; } diff --git a/StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml.cs index d4bf0d5..a0174e6 100644 --- a/StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml.cs @@ -26,7 +26,7 @@ namespace WebApp.Pages if (id != null) { Event @event = eventManager.GetEventById(id.Value); - if (@event.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN") ) + if (@event.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN")) { ViewData["event"] = @event; } @@ -46,7 +46,7 @@ namespace WebApp.Pages EventManager eventManager = new EventManager(_eventRepository); eventManager.UpdateEvent(Event.ID, Event.Title, Event.Description, Event.StartDate, Event.EndDate); } - + return RedirectToPage("Events"); } } diff --git a/StudentHouseDashboard/WebApp/Pages/Error/401.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Error/401.cshtml.cs index 9a4b419..283981e 100644 --- a/StudentHouseDashboard/WebApp/Pages/Error/401.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Error/401.cshtml.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages.Error diff --git a/StudentHouseDashboard/WebApp/Pages/Error/Unexpected.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Error/Unexpected.cshtml.cs index f6a82ac..0094f05 100644 --- a/StudentHouseDashboard/WebApp/Pages/Error/Unexpected.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Error/Unexpected.cshtml.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages.Error diff --git a/StudentHouseDashboard/WebApp/Pages/Event.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Event.cshtml.cs index 3c66415..b31e541 100644 --- a/StudentHouseDashboard/WebApp/Pages/Event.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Event.cshtml.cs @@ -1,9 +1,6 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Logic; -using Models; -using Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Events.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Events.cshtml.cs index 7adf50a..a016c8b 100644 --- a/StudentHouseDashboard/WebApp/Pages/Events.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Events.cshtml.cs @@ -1,10 +1,6 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Logic; -using Models; -using System.Security.Claims; -using System.Dynamic; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs index 266a117..320eac0 100644 --- a/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs index 004bfda..7221646 100644 --- a/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs @@ -1,11 +1,11 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Data; +using Logic; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; using Models; -using Logic; using System.Security.Claims; -using Data; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Privacy.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Privacy.cshtml.cs index cea862a..ef892dd 100644 --- a/StudentHouseDashboard/WebApp/Pages/Privacy.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Privacy.cshtml.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { diff --git a/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs index 18bbaa3..e0c0a2a 100644 --- a/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs @@ -1,8 +1,8 @@ +using Data; +using Logic; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Logic; using Models; -using Data; namespace WebApp.Pages { @@ -16,9 +16,21 @@ namespace WebApp.Pages public void OnPost() { var userManager = new UserManager(new UserRepository()); - if (userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role) != null) + User? result = null; + try { - ViewData["confirm"] = $"Successfully registered {MyUser.Name}!"; + result = userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role); + } + catch (ArgumentException) + { + ViewData["confirm"] = "An error has occurred. Try a different username."; + } + finally + { + if (result != null) + { + ViewData["confirm"] = $"Successfully registered {MyUser.Name}!"; + } } } } diff --git a/StudentHouseDashboard/WebApp/Program.cs b/StudentHouseDashboard/WebApp/Program.cs index d49db10..8a16d5b 100644 --- a/StudentHouseDashboard/WebApp/Program.cs +++ b/StudentHouseDashboard/WebApp/Program.cs @@ -13,7 +13,8 @@ namespace WebApp // Add services to the container. builder.Services.AddRazorPages(); - builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => { + builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => + { options.LoginPath = new PathString("/Login"); options.AccessDeniedPath = new PathString("/Error/401"); }); diff --git a/StudentHouseDashboard/WinForms/AnnouncementForm.cs b/StudentHouseDashboard/WinForms/AnnouncementForm.cs index d0181c0..3717bc2 100644 --- a/StudentHouseDashboard/WinForms/AnnouncementForm.cs +++ b/StudentHouseDashboard/WinForms/AnnouncementForm.cs @@ -1,15 +1,6 @@ using Data; using Logic; using Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace WinForms { diff --git a/StudentHouseDashboard/WinForms/CommentForm.cs b/StudentHouseDashboard/WinForms/CommentForm.cs index a9a914d..5034f92 100644 --- a/StudentHouseDashboard/WinForms/CommentForm.cs +++ b/StudentHouseDashboard/WinForms/CommentForm.cs @@ -1,15 +1,6 @@ using Data; using Logic; using Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace WinForms { @@ -80,11 +71,11 @@ namespace WinForms { switch (responseType) { - case "announcement": - commentManager.CreateCommentOnAnnouncement(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); + case "announcement": + commentManager.CreateCommentOnAnnouncement(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); break; - case "comment": - commentManager.CreateResponseOnComment(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); + case "comment": + commentManager.CreateResponseOnComment(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); break; case "complaint": commentManager.CreateCommentOnComplaint(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); @@ -111,7 +102,7 @@ namespace WinForms form.ShowDialog(); RefreshComments(); } - + } private void btnEditComment_Click(object sender, EventArgs e) diff --git a/StudentHouseDashboard/WinForms/ComplaintForm.cs b/StudentHouseDashboard/WinForms/ComplaintForm.cs index 8dba92d..88e9b3e 100644 --- a/StudentHouseDashboard/WinForms/ComplaintForm.cs +++ b/StudentHouseDashboard/WinForms/ComplaintForm.cs @@ -1,15 +1,6 @@ using Data; using Logic; using Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace WinForms { diff --git a/StudentHouseDashboard/WinForms/Dashboard.cs b/StudentHouseDashboard/WinForms/Dashboard.cs index 8c15d25..7d38d87 100644 --- a/StudentHouseDashboard/WinForms/Dashboard.cs +++ b/StudentHouseDashboard/WinForms/Dashboard.cs @@ -1,15 +1,6 @@ using Data; using Logic; using Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace WinForms { diff --git a/StudentHouseDashboard/WinForms/EventForm.cs b/StudentHouseDashboard/WinForms/EventForm.cs index 2bca789..a5346e5 100644 --- a/StudentHouseDashboard/WinForms/EventForm.cs +++ b/StudentHouseDashboard/WinForms/EventForm.cs @@ -1,15 +1,6 @@ using Data; using Logic; using Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace WinForms { diff --git a/StudentHouseDashboard/WinForms/UserForm.cs b/StudentHouseDashboard/WinForms/UserForm.cs index 952d0df..99bbd49 100644 --- a/StudentHouseDashboard/WinForms/UserForm.cs +++ b/StudentHouseDashboard/WinForms/UserForm.cs @@ -1,15 +1,6 @@ using Data; using Logic; using Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace WinForms { diff --git a/docs/project-report.docx b/docs/project-report.docx new file mode 100644 index 0000000..ee71f1f Binary files /dev/null and b/docs/project-report.docx differ diff --git a/docs/testplan.docx b/docs/testplan.docx index a425f4f..370579a 100644 Binary files a/docs/testplan.docx and b/docs/testplan.docx differ diff --git a/docs/testplan.pdf b/docs/testplan.pdf new file mode 100644 index 0000000..0e13831 Binary files /dev/null and b/docs/testplan.pdf differ diff --git a/docs/umlclass.pdf b/docs/umlclass.pdf index 594a2e9..f197769 100644 Binary files a/docs/umlclass.pdf and b/docs/umlclass.pdf differ diff --git a/docs/umlclass.vsdx b/docs/umlclass.vsdx index caad035..5377ec9 100644 Binary files a/docs/umlclass.vsdx and b/docs/umlclass.vsdx differ diff --git a/queries.sql b/queries.sql index 59261c1..a0e982e 100644 --- a/queries.sql +++ b/queries.sql @@ -1,6 +1,7 @@ USE dbi509645 GO +-- User roles INSERT INTO UserRole ([Role]) VALUES ('TENANT'), @@ -8,6 +9,7 @@ VALUES ('ADMIN') GO +-- Default users INSERT INTO Users ([Name], [Password], [Role]) VALUES ('admin', 'admin', 2), @@ -15,6 +17,7 @@ VALUES ('room1', 'room1', 0) GO +-- Complaint status INSERT INTO ComplaintStatus ([Status]) VALUES ('FILED'), @@ -23,12 +26,11 @@ VALUES ('ARCHIVED') GO +-- Complaint severity INSERT INTO ComplaintSeverity ([Severity]) VALUES ('LOW'), ('NORMAL'), ('HIGH'), ('URGENT') -GO - -SELECT * FROM Users u JOIN UserRole r ON u.[Role] = r.ID \ No newline at end of file +GO \ No newline at end of file diff --git a/table.sql b/tables.sql similarity index 96% rename from table.sql rename to tables.sql index 66a6bf4..97d0486 100644 --- a/table.sql +++ b/tables.sql @@ -15,6 +15,8 @@ CREATE TABLE Users ( ) GO +-- Used only in previous versions for a contact form +-- no longer needed CREATE TABLE ContactForm ( ID INT PRIMARY KEY IDENTITY NOT NULL, [Name] NVARCHAR(255) NOT NULL,