public bool AddDocument(Blog newBlog, string Login) { using (var connection = new SqlConnection(connectionsString)) { var command = new SqlCommand("insert into BlogDB.Blogs (UserID, Document, Tag) values (@userid, @document, @tag)", connection); command.Parameters.AddWithValue("@userid", FindId(Login)); command.Parameters.AddWithValue("@document", newBlog.Document); command.Parameters.AddWithValue("@tag", newBlog.Tag); connection.Open(); return command.ExecuteNonQuery() == 1; } }
public IEnumerable<Blog> GetBlogByText(string Text) { var result = new List<Blog>(); using (var connection = new SqlConnection(connectionsString)) { var command = new SqlCommand("select BlogID, UserID, Document, Tag from BlogDB.Blogs where Document like @text", connection); command.Parameters.AddWithValue("@text", "%"+Text+"%"); connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var blog = new Blog(); blog.BlogID = reader.GetInt32(0); blog.Login = GetLoginByID(reader.GetInt32(1)); blog.Document = reader.GetString(2); blog.Tag = reader.GetString(3); result.Add(blog); } } } return result; }
public IEnumerable<Blog> GetBlogByName(string Login) { var result = new List<Blog>(); using (var connection = new SqlConnection(connectionsString)) { var command = new SqlCommand("select BlogID, Document, Login, Tag from BlogDB.Blogs " + "join BlogDB.Users on Users.UserID = Blogs.UserID where Login=@login", connection); command.Parameters.AddWithValue("@login", Login); connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var blog = new Blog(); blog.BlogID = reader.GetInt32(0); blog.Document = reader.GetString(1); blog.Login = reader.GetString(2); blog.Tag = reader.GetString(3); result.Add(blog); } } } return result; }