public bool CreatePost(Post post)
{
string queryString =
"INSERT INTO [dbo].posts ([dbo].posts.postid, postname, source, createdtime, mimetype, accountid, text, rating) " +
"VALUES (@postid, @postname, @source, @createdtime, @mimetype, @accountid, @text, @rating); " +
"INSERT INTO tags ([dbo].tags.postid, tag) " +
"VALUES(@postid, @tag)";
using (SqlConnection connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("postid", post.PostId);
command.Parameters.AddWithValue("postname", post.NamePost);
command.Parameters.AddWithValue("source", post.Image);
command.Parameters.AddWithValue("createdtime", post.CreatedTime);
command.Parameters.AddWithValue("mimetype", post.MimeType);
command.Parameters.AddWithValue("accountid", post.AccountId);
command.Parameters.AddWithValue("text", post.Text);
command.Parameters.AddWithValue("rating", post.Rating);
command.Parameters.AddWithValue("tag", post.tmp);
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception e)
{
var stack = e.StackTrace;
throw new Exception();
}
}
return true;
}