//Create 2 examples foreach CodeLanguage from Database public static void CodeSnippedExampleForeachCodeLanguageInDatabase() { int ExamplePerLanguage = 2; for (int l = 0; l < DbCodeLanguage.GetallLanguages().Count; l++) { for (int examples = 0; examples < ExamplePerLanguage; examples++) { SnippetInfo snippetInfo = new SnippetInfo( 9999, UserInfo.Userinformation.ID, 9999, "Name" + examples, "Code" + examples, DateTime.Now, "Usage" + examples, DateTime.Now, "Description" + examples, DateTime.Now, DbCodeLanguage.GetallLanguages()[l].ID,//<------------- DateTime.Now ); System.Threading.Thread.Sleep(1000); DbSnippets.AddNewSnippet(snippetInfo); } } }
//Get all snippetsinfo related to CollectionID private static List <SnippetInfo> GetSnippetsRelatedToCollection(int CollectionID) { /* * if code snippetcollectionID = ID * Get Snippet ID * Get SnippetInfo from ID and add to list */ //Create Temp List <SnippetInfo> Temp = null; //create connection and open it MySqlConnection connection = DbInfo.Connection(); //Build Mysql command MySqlCommand cmd = connection.CreateCommand(); //Add the CommandText cmd.CommandText = "SELECT `ID`, `CodeSnippetsID`, `SnippetCollectionID` FROM `snipped_codecollection` WHERE `SnippetCollectionID` = @CollectionID"; //Add Parameter cmd.Parameters.AddWithValue("@CollectionID", CollectionID); //Create reader MySqlDataReader reader = cmd.ExecuteReader(); //While reading while (reader.Read()) { Temp.Add(DbSnippets.GetSnippetInfoFromID(int.Parse(reader["CodeSnippetsID"].ToString()))); } //Return Value return(Temp); }