Skip to content

Commit 0fdf0c0

Browse files
committed
Sort in database
1 parent 4ded0fe commit 0fdf0c0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public bool AddPost(Entities.PostText post, string login)
176176
{
177177
using (SqlConnection con = new SqlConnection(ConnectionString))
178178
{
179-
SqlCommand command = new SqlCommand("SELECT Post_Title, Post_Id FROM dbo.Posts WHERE User_Name = @Name", con);
179+
SqlCommand command = new SqlCommand("SELECT Post_Title, Post_Id FROM dbo.Posts WHERE User_Name = @Name ORDER BY Time DESC", con);
180180
command.Parameters.Add(new SqlParameter("@Name", user));
181181
con.Open();
182182
var reader = command.ExecuteReader();
@@ -392,7 +392,7 @@ public bool AddComment(Entities.Comment comment)
392392
{
393393
using (SqlConnection con = new SqlConnection(ConnectionString))
394394
{
395-
SqlCommand command = new SqlCommand("SELECT Post_ID, User_Name, Comment_ID, Text, Time FROM dbo.Comments WHERE Post_ID = CAST(@Post_ID AS NVARCHAR(36)) ORDER BY Time", con);
395+
SqlCommand command = new SqlCommand("SELECT Post_ID, User_Name, Comment_ID, Text, Time FROM dbo.Comments WHERE Post_ID = CAST(@Post_ID AS NVARCHAR(36)) ORDER BY Time DESC", con);
396396
command.Parameters.Add(new SqlParameter("@Post_ID", Post_ID));
397397
con.Open();
398398
var reader = command.ExecuteReader();
@@ -417,7 +417,7 @@ public bool AddComment(Entities.Comment comment)
417417
{
418418
using (SqlConnection con = new SqlConnection(ConnectionString))
419419
{
420-
SqlCommand command = new SqlCommand("SELECT Post_Id, Comment_ID, Text, Time FROM dbo.Comments WHERE User_Name = @Name ORDER BY Time", con);
420+
SqlCommand command = new SqlCommand("SELECT Post_Id, Comment_ID, Text, Time FROM dbo.Comments WHERE User_Name = @Name ORDER BY Time DESC", con);
421421
command.Parameters.Add(new SqlParameter("@Name", name));
422422
con.Open();
423423
var reader = command.ExecuteReader();
@@ -463,7 +463,7 @@ public bool DeleteCommentById(Guid id)
463463
{
464464
using (SqlConnection con = new SqlConnection(ConnectionString))
465465
{
466-
SqlCommand command = new SqlCommand("SELECT Login, E_mail, Title FROM dbo.Users, dbo.Roles WHERE Users.Role_Id = Roles.Id", con);
466+
SqlCommand command = new SqlCommand("SELECT Login, E_mail, Title FROM dbo.Users, dbo.Roles WHERE Users.Role_Id = Roles.Id ORDER BY Login", con);
467467
con.Open();
468468
var reader = command.ExecuteReader();
469469
while (reader.Read())
@@ -708,7 +708,7 @@ public bool AddAvatar(Entities.Avatar avatar)
708708
{
709709
using (SqlConnection con = new SqlConnection(ConnectionString))
710710
{
711-
SqlCommand command = new SqlCommand("SELECT Post_Title, Post_Id FROM dbo.Posts", con);
711+
SqlCommand command = new SqlCommand("SELECT Post_Title, Post_Id FROM dbo.Posts ORDER BY Time DESC", con);
712712
con.Open();
713713
var reader = command.ExecuteReader();
714714

EPAM.MyBlog.v11.suo

-1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)