Basic comments on announcements

This commit is contained in:
Dimitar Byalkov
2023-04-19 16:55:14 +02:00
parent daf034c71e
commit 55a2319405
7 changed files with 75 additions and 43 deletions

View File

@@ -24,12 +24,15 @@ namespace StudentHouseDashboard.Repositories
while (reader.Read())
{
// ID, Name, Password, Role
announcements.Add(new Announcement(Convert.ToInt32(reader["ID"]),
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();
}

View File

@@ -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;
}
}

View File

@@ -6,24 +6,26 @@
ViewData["Title"] = $"{announcement.Title}";
}
<h1>@announcement.Title</h1>
<div class="container">
<div class="row">
<div class="col">
<p>Title: </p>
<p>Author: </p>
<p>Description: </p>
<p>Date: </p>
<p>Important: </p>
<p>Pinned: </p>
<p>Published @announcement.PublishDate.ToString("g") by @announcement.Author.Name
@(announcement.IsImportant ? "Important" : "") @(announcement.IsSticky ? "Sticky" : "")</p>
<hr />
<p>@Html.Raw(announcement.Description.Replace(Environment.NewLine, "<br />"))</p>
<br/>
<h3>Comments</h3>
@if (announcement.Comments.Count() == 0)
{
<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 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>
}
}

View File

@@ -14,7 +14,7 @@
<div class="card-body">
<h5 class="card-title">@announcement.Title</h5>
<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>
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN")
{
@@ -41,7 +41,7 @@
@: </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)
{
@: <li class="page-item disabled">

View File

@@ -6,19 +6,5 @@
<div class="text-center">
<h1>Student House Dashboard</h1>
<p>The communication solution for shared accomodation.</p>
<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>
<a class="btn btn-primary" asp-page="Announcements">Announcements</a>
</div>

View File

@@ -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<IndexModel> _logger;

View File

@@ -5,6 +5,7 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>