private static void AddRootOption(long id) { var serializer = new Serializer(); using (var ctx = new DatabaseContext(Config.DB_CONNECTION_STRING)) { var option = ctx.WP_Options.FirstOrDefault(x => x.option_name == "code_category_children"); if (option == null) { option = new wp_option { option_name = "code_category_children" }; ctx.WP_Options.Add(option); tree = new Hashtable(); } else { tree = (Hashtable)serializer.Deserialize(option.option_value); } if (!tree.ContainsKey(id)) { tree.Add(id, new ArrayList()); } option.option_value = serializer.Serialize(tree); ctx.SaveChanges(); } }
private static void AddOptionEntry(long id, long parentId) { using (var ctx = new DatabaseContext(Config.DB_CONNECTION_STRING)) { var wp_option = new wp_option { option_name = "taxonomy_" + id, option_value = "a:1:{s:13:\"category_icon\";s:0:\"\";}" }; ctx.WP_Options.Add(wp_option); ((ArrayList)tree[parentId]).Add(id); var option = ctx.WP_Options.First(x => x.option_name == "code_category_children"); option.option_value = new Serializer().Serialize(tree); ctx.SaveChanges(); // if not root nodes and not contained in root nodes then add to relevant root node } }