internal static KhartaOntology addUpdateContainer(KhartaOntology container) { Func <KhartaOntology, Ontology> toOntology = (KhartaOntology fromContainer) => FromContainer(fromContainer); Ontology _ontology = toOntology(container); //Ontology _ontology = (Ontology) container;// new Ontology() ;//(Ontology) container; int id = container.Id; // KhartaOntology container = new KhartaOntology(); Type ct = container.GetType(); Type ot = _ontology.GetType(); IList <PropertyInfo> cprop = new List <PropertyInfo>(ct.GetProperties()); IList <PropertyInfo> oprop = new List <PropertyInfo>(ot.GetProperties()); //KhartaOntology container = new KhartaOntology(); if (id == 0) { try { using (var dbcontext = new KhartaDataModel()) { _ontology = dbcontext.Ontologies.Add(_ontology); dbcontext.SaveChanges(); foreach (PropertyInfo op in oprop) { var value = op.GetValue(_ontology, null); op.SetValue(container, value, null); } } return(container); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } else { using (var dbcontext = new KhartaDataModel()) { var containers = from o in dbcontext.Ontologies where o.Id.Equals(_ontology.Id) select o; var currentContainer = containers.FirstOrDefault(); foreach (PropertyInfo op in oprop) { if (op.CanWrite) { var value = op.GetValue(_ontology, null); op.SetValue(currentContainer, value, null); } } dbcontext.SaveChanges(); container = ToContainer(currentContainer); } } return(container); }
private static KhartaOntology FromOntology(Ontology ontology) { KhartaOntology container = new KhartaOntology(); if (ontology != null) { Type ot = ontology.GetType(); IList <PropertyInfo> oprop = new List <PropertyInfo>(ot.GetProperties()); foreach (PropertyInfo op in oprop) { var value = op.GetValue(ontology, null); op.SetValue(container, value, null); } } return(container); }
private static Ontology FromContainer(KhartaOntology container) { Ontology ontology = new Ontology(); if (container != null) { //Type ct = container.GetType(); Type ot = ontology.GetType(); // IList<PropertyInfo> cprop = new List<PropertyInfo>(ct.GetProperties()); IList <PropertyInfo> oprop = new List <PropertyInfo>(ot.GetProperties()); foreach (PropertyInfo op in oprop) { var value = op.GetValue(container, null); op.SetValue(ontology, value, null); } } return(ontology); }
internal static KhartaOntology addContainer(KhartaOntology container) { Func <KhartaOntology, Ontology> toOntology = (KhartaOntology fromContainer) => FromContainer(fromContainer); Ontology _ontology = toOntology(container); //KhartaOntology container = new KhartaOntology(); Type ct = container.GetType(); Type ot = _ontology.GetType(); IList <PropertyInfo> cprop = new List <PropertyInfo>(ct.GetProperties()); IList <PropertyInfo> oprop = new List <PropertyInfo>(ot.GetProperties()); using (var dbcontext = new KhartaDataModel()) { _ontology = dbcontext.Ontologies.Add(_ontology); dbcontext.SaveChanges(); foreach (PropertyInfo op in oprop) { var value = op.GetValue(_ontology, null); op.SetValue(container, value, null); } } return(container); }