public ActionResult SaveTaxon(NodeModel taxonModel) { SubjectManager subjectManager = new SubjectManager(); InteractionManager interactionManager = new InteractionManager(); //ToDo Store Image in folder : project/images/ //add a media to plant Taxon taxon = new Taxon(); if (taxonModel.Id > 0) { var x = subjectManager.Get(taxonModel.Id).Self; taxon = x as Taxon; } taxon.Name = taxonModel.Name; taxon.ScientificName = taxonModel.ScientificName; taxon.Rank = taxonModel.TaxonRank; //TODO Generate the Parent based on the ScientificName // a a a = SubSpecies, a a = Species, a = Genus // a a var. a is also a species /* - based on the scientficname create or set the parents * - use maybe some webservices to create missing one * */ //Todo Select the type based on the scientific name //animal.Rank = Utility.GetTaxonRank(animal.ScientificName); if (!taxon.Medias.Where(m => m.ImagePath.Equals(taxonModel.ImagePath)).Any()) { taxon.Medias.Add(new Media() { ImagePath = taxonModel.ImagePath, MIMEType = MimeMapping.GetMimeMapping(taxonModel.ImagePath) }); } if (taxon.Id == 0) { taxon = subjectManager.CreateTaxon(taxon); } else { subjectManager.Update(taxon); } //set parent if (taxonModel.Parent != null && taxonModel.Parent.Id > 0) { var parent = subjectManager.GetAll <Node>().Where(n => n.Id.Equals(taxonModel.Parent.Id)).FirstOrDefault(); taxon.Parent = parent; } else // delete taxon from plant { taxon.Parent = null; } subjectManager.Update(taxon); return(Json(taxon.Id, JsonRequestBehavior.AllowGet)); }