diff --git a/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs b/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs index 45ea60e..80468f1 100644 --- a/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs +++ b/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs @@ -24,12 +24,15 @@ namespace StudentHouseDashboard.Repositories while (reader.Read()) { - // ID, Name, Password, Role - announcements.Add(new Announcement(Convert.ToInt32(reader["ID"]), - userManager.GetUserById(Convert.ToInt32(reader["Author"])), - reader["Description"].ToString(), reader["Title"].ToString(), + Announcement announcement = new Announcement(Convert.ToInt32(reader["ID"]), + userManager.GetUserById(Convert.ToInt32(reader["Author"])), + reader["Description"].ToString(), reader["Title"].ToString(), (DateTime)reader["PublishDate"], (bool)reader["IsImportant"], - (bool)reader["IsSticky"])); + (bool)reader["IsSticky"]); + CommentRepository commentRepository = new CommentRepository(); + announcement.Comments = commentRepository.GetAllCommentsOnAnnouncement(announcement.ID); + // ID, Name, Password, Role + announcements.Add(announcement); } conn.Close(); } diff --git a/StudentHouseDashboard/HouseData/Repositories/CommentRepository.cs b/StudentHouseDashboard/HouseData/Repositories/CommentRepository.cs new file mode 100644 index 0000000..68a7257 --- /dev/null +++ b/StudentHouseDashboard/HouseData/Repositories/CommentRepository.cs @@ -0,0 +1,38 @@ +using System.Data.SqlClient; +using StudentHouseDashboard.Models; + +namespace StudentHouseDashboard.Repositories; + +public class CommentRepository +{ + public CommentRepository() + { + + } + + public List GetAllCommentsOnAnnouncement(int announcementID) + { + List comments = new List(); + using (SqlConnection connection = SqlConnectionHelper.CreateConnection()) + { + string sql = "SELECT c.ID, c.Author, c.Description, c.Title, c.PublishDate, " + + "u.ID UserID, u.Name UserName, u.Password, u.Role FROM AnnouncementsComments ac " + + "INNER JOIN Comments c ON c.ID = ac.CommentID " + + "INNER JOIN Users u ON u.ID = c.Author " + + "WHERE ac.AnnouncementID = @announcementID"; + SqlCommand sqlCommand = new SqlCommand(sql, connection); + sqlCommand.Parameters.AddWithValue("@announcementID", announcementID); + var reader = sqlCommand.ExecuteReader(); + while (reader.Read()) + { + comments.Add(new Comment((int)reader["ID"], + new User((int)reader["UserID"], reader["UserName"].ToString(), + reader["Password"].ToString(), (UserRole)reader["Role"]), + reader["Description"].ToString(), reader["Title"].ToString(), + (DateTime)reader["PublishDate"])); + } + } + + return comments; + } +} \ No newline at end of file diff --git a/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml index f77f73e..883ee11 100644 --- a/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml +++ b/StudentHouseDashboard/WebApp/Pages/Announcement.cshtml @@ -6,24 +6,26 @@ ViewData["Title"] = $"{announcement.Title}"; }

@announcement.Title

-
-
-
-

Title:

-

Author:

-

Description:

-

Date:

-

Important:

-

Pinned:

+

Published @announcement.PublishDate.ToString("g") by @announcement.Author.Name + @(announcement.IsImportant ? "Important" : "") @(announcement.IsSticky ? "Sticky" : "")

+
+

@Html.Raw(announcement.Description.Replace(Environment.NewLine, "
"))

+
+

Comments

+@if (announcement.Comments.Count() == 0) +{ +

No comments found

+} +else +{ + foreach (Comment comment in announcement.Comments) + { +
+
+
@comment.Author.Name
+

@Html.Raw(comment.Description.Replace(Environment.NewLine, "
"))

+ Respond +
-
-

@announcement.Title

-

@announcement.Author.Name

-

@announcement.Description

-

@announcement.PublishDate.ToString("g")

-

@announcement.IsImportant.ToString()

-

@announcement.IsSticky.ToString()

-
-
-
- + } +} \ No newline at end of file diff --git a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml index 3cda7e7..8f32e68 100644 --- a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml +++ b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml @@ -14,7 +14,7 @@
@announcement.Title
@announcement.Author.Name
-

@announcement.Description

+

@announcement.Description.PadRight(100).Trim()

More details @if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN") { @@ -41,7 +41,7 @@ @: @:
  • @(currentPage - 1)
  • } -
  • @currentPage
  • +
  • @currentPage @if (announcements.Count == 0) { @:
  • diff --git a/StudentHouseDashboard/WebApp/Pages/Index.cshtml b/StudentHouseDashboard/WebApp/Pages/Index.cshtml index 5c61320..0fc1d5c 100644 --- a/StudentHouseDashboard/WebApp/Pages/Index.cshtml +++ b/StudentHouseDashboard/WebApp/Pages/Index.cshtml @@ -6,19 +6,5 @@

    Student House Dashboard

    -

    The communication solution for shared accomodation.

    - -
    -

    Why choose our solution?

    -
    -

    Student House Dashboard helps tenants organise common household chores even if they don't know each other very well.

    -
    -
    - -
    -

    Is it difficult to use?

    -
    -

    Student House Dashboard is focused on providing a simple and powerful system for its users which helps them get on with their day without any worries.

    -
    -
    + Announcements
    \ No newline at end of file diff --git a/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs b/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs index 9824b0a..78bf0a5 100644 --- a/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs +++ b/StudentHouseDashboard/WebApp/Pages/Index.cshtml.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WebApp.Pages { + [Authorize] public class IndexModel : PageModel { private readonly ILogger _logger; diff --git a/StudentHouseDashboard/WinForms/WinForms.csproj b/StudentHouseDashboard/WinForms/WinForms.csproj index c671066..e0fd031 100644 --- a/StudentHouseDashboard/WinForms/WinForms.csproj +++ b/StudentHouseDashboard/WinForms/WinForms.csproj @@ -5,6 +5,7 @@ net6.0-windows enable true + true enable