/// <summary> </summary> public void merge_taxonomy(int[] ids, string newname) { CancelLayout(); CancelView(); log.Info("starting merge proccess"); if (!String.IsNullOrEmpty(Request.Params["deleteTags"])) { mass_delete_taxonomy(ids); return; } dynamic items = new List <_base>(); string name = ""; taxonomy_type oldtype = null; foreach (int id in ids) { taxonomy tax = ActiveRecordBase <taxonomy> .Find(id); oldtype = tax.taxonomy_type; name = tax.name; log.Info("found taxonomy" + name); items.AddRange(tax.get_taxonomy_items(oldtype.alias, tax.alias)); foreach (dynamic p in tax.items) { log.Info("removing taxonomy from item " + p.alias); p.taxonomies.Remove(tax); ActiveRecordMediator <_base> .Save(p); } ActiveRecordMediator <taxonomy> .Delete(tax); } taxonomy t = new taxonomy(); name = String.IsNullOrEmpty(newname) ? name : newname; t.name = name; String alias = name.Replace(' ', '_').ToLower(); t.alias = alias; t.taxonomy_type = oldtype; ActiveRecordMediator <taxonomy> .Save(t); log.Info("created taxonomy with new name"); foreach (_base p in items) { log.Info("appling taxonomy " + oldtype.alias); PropertyInfo propInfo = p.GetType().GetProperty(oldtype.alias); propInfo.SetValue(p, alias, new object[] { }); //postingService.get_taxonomy(p.innovator_company).name p.taxonomies.Add(t); log.Info("adding new taxonomy back to items"); ActiveRecordMediator <_base> .Save(p); } RedirectToAction("taxonomy"); }
/// <summary> </summary> public void update_taxonomy([ARDataBind("taxonomy", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] taxonomy taxonomy, Boolean ajax, String oldtax_alias, String oldtax_type_alias) { ActiveRecordMediator <taxonomy> .Save(taxonomy); dynamic items = new List <_base>(); string name = ""; taxonomy_type type = null; if (!String.IsNullOrWhiteSpace(oldtax_alias) && !String.IsNullOrWhiteSpace(oldtax_type_alias)) { type = taxonomy.taxonomy_type; name = taxonomy.name; ActiveRecordMediator <_base> .Save(taxonomy); //find old ones and clean them up taxonomy tax = ActiveRecordBase <taxonomy> .Find(taxonomy.baseid); try { IList <_base> taxed = tax.get_taxonomy_items(oldtax_type_alias, oldtax_alias); if (taxed.Count() > 0) { items.AddRange(taxed); String alias = taxonomy.alias; foreach (_base p in items) { log.Info("appling taxonomy " + type.alias + " to " + p.baseid + "/" + p.alias); PropertyInfo propInfo = p.GetType().GetProperty(type.alias); propInfo.SetValue(p, alias, new object[] { }); log.Info("adding new taxonomy back to items"); ActiveRecordMediator <_base> .Save(p); } } } catch { } Flash["message"] = "taxonomy has " + items.Count + " items to change from: <b>" + oldtax_type_alias + "/" + oldtax_alias + "</b> TO <b>" + type.alias + "/" + taxonomy.alias + "</b>"; log.Info("taxonomy has " + items.Count + " items to change to " + oldtax_type_alias + "/" + oldtax_alias); } if (ajax) { CancelLayout(); Response.ContentType = "application/json; charset=UTF-8"; if (taxonomy.baseid > 0) { RenderText("{\"state\":\"true\",\"baseid\":\"" + taxonomy.baseid + "\",\"name\":\"" + taxonomy.name + "\",\"alias\":\"" + taxonomy.alias + "\"}"); } else { RenderText("{\"state\":\"false\"}"); } return; } RedirectToAction("taxonomy"); }