88
99namespace Blog_Dirty_
1010{
11- sealed class PostsManager
11+ public class PostsManager
1212 {
1313 private PostsRepository _repository ;
1414
15- PostsManager ( )
15+ public PostsManager ( )
1616 {
1717 _repository = new PostsRepository ( ) ;
1818 _repository . createDatabase ( ) ;
@@ -26,7 +26,7 @@ public bool isPostExists(string postName)
2626 {
2727 try
2828 {
29- SqlCommand checkIfExists = new SqlCommand ( "select count(*) from users where PostName= @postName" ) ; //connection at end
29+ SqlCommand checkIfExists = new SqlCommand ( "select count(*) from posts where PostName= @postName" ) ; //connection at end
3030 checkIfExists . Parameters . AddWithValue ( "postName" , postName ) ;
3131
3232 _repository . executeQuery ( checkIfExists ) ;
@@ -47,7 +47,7 @@ public void addPost(User user, string postName, string postData)
4747 {
4848 string username = user . UserName ;
4949
50- SqlCommand addToDatabase = new SqlCommand ( "insert into Users (username, postName, postData) values(@username, @postName, @postData)" ) ;
50+ SqlCommand addToDatabase = new SqlCommand ( "insert into posts (username, postName, postData) values(@username, @postName, @postData)" ) ;
5151
5252 addToDatabase . Parameters . AddWithValue ( "username" , username ) ;
5353 addToDatabase . Parameters . AddWithValue ( "postName" , postName ) ;
@@ -65,9 +65,11 @@ public void removePost(Posts posts)
6565 }
6666 else
6767 {
68- SqlCommand deleteFromDatabase = new SqlCommand ( "DELETE from Posts Where PostName = '" + postName + "'" ) ;
68+ string username = posts . username ;
69+ SqlCommand deleteFromDatabase = new SqlCommand ( "DELETE from Posts Where PostName = '" + postName + "'" + "AND username = " + "'username'" ) ;
6970
7071 deleteFromDatabase . Parameters . AddWithValue ( "PostName" , postName ) ;
72+ deleteFromDatabase . Parameters . AddWithValue ( "username" , username ) ;
7173
7274 _repository . executeQuery ( deleteFromDatabase ) ;
7375 }
@@ -76,9 +78,9 @@ public void removePost(Posts posts)
7678 public void searchForUserPosts ( string username )
7779 {
7880 string query = "SELECT * from Posts Where username = '" + username + "'" ;
79- SqlCommand searchInDatabase = new SqlCommand ( "SELECT * from Posts Where username = '" + username + "'" ) ;
81+ // SqlCommand searchInDatabase = new SqlCommand("SELECT * from Posts Where username = '" + username + "'");
8082
81- searchInDatabase . Parameters . AddWithValue ( "username" , username ) ;
83+ // searchInDatabase.Parameters.AddWithValue("username", username);
8284
8385 DataTable dataTable = new DataTable ( ) ;
8486
0 commit comments