Delete, Edit Announcement, style fixes

This commit is contained in:
Dimitar Byalkov
2023-05-14 12:57:32 +02:00
parent 765fa8774d
commit 1adaef73e7
10 changed files with 178 additions and 7 deletions

View File

@@ -37,6 +37,27 @@ namespace Data
}
return announcements;
}
public Announcement GetAnnouncementById(int id)
{
UserRepository userRepository = new UserRepository();
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
{
string sql = "SELECT * FROM Announcements WHERE ID = @id;";
SqlCommand cmd = new SqlCommand(sql, conn);
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);
conn.Close();
return announcement;
}
}
public List<Announcement> GetAnnouncementsByPage(int? p, int? c)
{
List<Announcement> announcements = new List<Announcement>();