Basic comments on announcements
This commit is contained in:
@@ -24,12 +24,15 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
// ID, Name, Password, Role
|
Announcement announcement = new Announcement(Convert.ToInt32(reader["ID"]),
|
||||||
announcements.Add(new Announcement(Convert.ToInt32(reader["ID"]),
|
userManager.GetUserById(Convert.ToInt32(reader["Author"])),
|
||||||
userManager.GetUserById(Convert.ToInt32(reader["Author"])),
|
reader["Description"].ToString(), reader["Title"].ToString(),
|
||||||
reader["Description"].ToString(), reader["Title"].ToString(),
|
|
||||||
(DateTime)reader["PublishDate"], (bool)reader["IsImportant"],
|
(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();
|
conn.Close();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Data.SqlClient;
|
||||||
|
using StudentHouseDashboard.Models;
|
||||||
|
|
||||||
|
namespace StudentHouseDashboard.Repositories;
|
||||||
|
|
||||||
|
public class CommentRepository
|
||||||
|
{
|
||||||
|
public CommentRepository()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Comment> GetAllCommentsOnAnnouncement(int announcementID)
|
||||||
|
{
|
||||||
|
List<Comment> comments = new List<Comment>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@@ -6,24 +6,26 @@
|
|||||||
ViewData["Title"] = $"{announcement.Title}";
|
ViewData["Title"] = $"{announcement.Title}";
|
||||||
}
|
}
|
||||||
<h1>@announcement.Title</h1>
|
<h1>@announcement.Title</h1>
|
||||||
<div class="container">
|
<p>Published @announcement.PublishDate.ToString("g") by @announcement.Author.Name
|
||||||
<div class="row">
|
@(announcement.IsImportant ? "Important" : "") @(announcement.IsSticky ? "Sticky" : "")</p>
|
||||||
<div class="col">
|
<hr />
|
||||||
<p>Title: </p>
|
<p>@Html.Raw(announcement.Description.Replace(Environment.NewLine, "<br />"))</p>
|
||||||
<p>Author: </p>
|
<br/>
|
||||||
<p>Description: </p>
|
<h3>Comments</h3>
|
||||||
<p>Date: </p>
|
@if (announcement.Comments.Count() == 0)
|
||||||
<p>Important: </p>
|
{
|
||||||
<p>Pinned: </p>
|
<p>No comments found</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (Comment comment in announcement.Comments)
|
||||||
|
{
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">@comment.Author.Name</h5>
|
||||||
|
<p class="card-text">@Html.Raw(comment.Description.Replace(Environment.NewLine, "<br />"))</p>
|
||||||
|
<a href="#">Respond</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
}
|
||||||
<p>@announcement.Title</p>
|
}
|
||||||
<p>@announcement.Author.Name</p>
|
|
||||||
<p>@announcement.Description</p>
|
|
||||||
<p>@announcement.PublishDate.ToString("g")</p>
|
|
||||||
<p>@announcement.IsImportant.ToString()</p>
|
|
||||||
<p>@announcement.IsSticky.ToString()</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
@@ -14,7 +14,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">@announcement.Title</h5>
|
<h5 class="card-title">@announcement.Title</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">@announcement.Author.Name</h6>
|
<h6 class="card-subtitle mb-2 text-muted">@announcement.Author.Name</h6>
|
||||||
<p class="card-text">@announcement.Description</p>
|
<p class="card-text">@announcement.Description.PadRight(100).Trim()</p>
|
||||||
<a href="./Announcement?id=@announcement.ID" class="btn btn-primary">More details</a>
|
<a href="./Announcement?id=@announcement.ID" class="btn btn-primary">More details</a>
|
||||||
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN")
|
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN")
|
||||||
{
|
{
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
@: </li>
|
@: </li>
|
||||||
@: <li class="page-item"><a class="page-link" href="./Announcements?p=@(currentPage - 1)">@(currentPage - 1)</a></li>
|
@: <li class="page-item"><a class="page-link" href="./Announcements?p=@(currentPage - 1)">@(currentPage - 1)</a></li>
|
||||||
}
|
}
|
||||||
<li class="page-item"><a class="page-link">@currentPage</a></li>
|
<li class="page-item"><a class="page-link">@currentPage</a>
|
||||||
@if (announcements.Count == 0)
|
@if (announcements.Count == 0)
|
||||||
{
|
{
|
||||||
@: <li class="page-item disabled">
|
@: <li class="page-item disabled">
|
||||||
|
@@ -6,19 +6,5 @@
|
|||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1>Student House Dashboard</h1>
|
<h1>Student House Dashboard</h1>
|
||||||
<p>The communication solution for shared accomodation.</p>
|
<a class="btn btn-primary" asp-page="Announcements">Announcements</a>
|
||||||
|
|
||||||
<div class="px-4 py-5 my-5 text-center">
|
|
||||||
<h2 class="display-5 fw-bold">Why choose our solution?</h2>
|
|
||||||
<div class="col-lg-6 mx-auto">
|
|
||||||
<p class="lead mb-4">Student House Dashboard helps tenants organise common household chores even if they don't know each other very well.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="px-4 py-5 my-5 text-center">
|
|
||||||
<h2 class="display-5 fw-bold">Is it difficult to use?</h2>
|
|
||||||
<div class="col-lg-6 mx-auto">
|
|
||||||
<p class="lead mb-4">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.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
@@ -1,8 +1,10 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
namespace WebApp.Pages
|
namespace WebApp.Pages
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
public class IndexModel : PageModel
|
public class IndexModel : PageModel
|
||||||
{
|
{
|
||||||
private readonly ILogger<IndexModel> _logger;
|
private readonly ILogger<IndexModel> _logger;
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user