diff --git a/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs b/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs index 8eefef6..9f20f63 100644 --- a/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs +++ b/StudentHouseDashboard/HouseData/Repositories/AnnouncementRepository.cs @@ -54,17 +54,17 @@ namespace StudentHouseDashboard.Repositories { List announcements = new List(); UserManager userManager = new UserManager(); - if (c == null) + if (c == null || c < 0) { c = 10; } - if (p == null) + if (p == null || p < 0) { p = 0; } using (SqlConnection conn = CreateConnection()) { - string sql = "SELECT TOP(@count) * FROM Users WHERE ID > @start;"; + string sql = "SELECT * FROM Announcements ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;"; SqlCommand sqlCommand = new SqlCommand(sql, conn); sqlCommand.Parameters.AddWithValue("@start", p * c); sqlCommand.Parameters.AddWithValue("@count", c); diff --git a/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs b/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs index e738a63..39cc686 100644 --- a/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs +++ b/StudentHouseDashboard/HouseData/Repositories/UserRepository.cs @@ -73,17 +73,17 @@ namespace StudentHouseDashboard.Repositories public List GetUsersByPage(int? p, int? c) { List users = new List(); - if (c == null) + if (c == null || c < 0) { - c = 0; + c = 10; } - if (p == null) + if (p == null || p < 0) { p = 0; } using (SqlConnection conn = CreateConnection()) { - string sql = "SELECT TOP(@count) * FROM Users WHERE ID > @start;"; + string sql = "SELECT * FROM Users ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;"; SqlCommand sqlCommand = new SqlCommand(sql, conn); sqlCommand.Parameters.AddWithValue("@start", p * c); sqlCommand.Parameters.AddWithValue("@count", c); diff --git a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml index 608c2d0..2d3c06e 100644 --- a/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml +++ b/StudentHouseDashboard/WebApp/Pages/Announcements.cshtml @@ -4,6 +4,7 @@ @{ ViewData["Title"] = "Announcements"; List users = (List)ViewData["users"]; + int currentPage = @Convert.ToInt32(ViewData["page"]); } @foreach (User user in users) @@ -18,16 +19,34 @@ } -