public void AddNode(AddNodeRequestDao addNode) { using (SqlConnection sql = new SqlConnection(_conStr)) { sql.Open(); using (var cmd = new SqlCommand()) { cmd.Connection = sql; AddNodeInternal(addNode, cmd); } sql.Close(); } }
private void AddNodeInternal(AddNodeRequestDao addNode,SqlCommand cmd) { cmd.CommandText = addNode.ParentId == null ? SqlQueries.InsertRootNode : SqlQueries.InsertFullNode; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Id", addNode.Id); cmd.Parameters.AddWithValue("@Text", addNode.StringValue); cmd.Parameters.AddWithValue("@Value", addNode.DigitValue); cmd.Parameters.AddWithValue("@UserId", addNode.UserId); if (addNode.ParentId != null) { cmd.Parameters.AddWithValue("@ParentId", addNode.ParentId); } cmd.Parameters.AddWithValue("@Generation", addNode.Generation); cmd.Parameters.AddWithValue("@DateCreation", DateTime.Now); cmd.ExecuteNonQuery(); }