Basic comments on announcements
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user