Пример #1
0
        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);
        }
Пример #2
0
 internal static void deleteContainer(KhartaOntology container)
 {
     // Ontology ontology = FromContainer(container);
     using (var dbcontext = new KhartaDataModel()) {
         var result = (from o in dbcontext.Ontologies
                       where o.Id.Equals(container.Id)
                       select o).FirstOrDefault();
         Ontology ontology = result;
         // dbcontext.Ontologies.i.Select(ontology);
         dbcontext.Ontologies.Remove(ontology);
         dbcontext.SaveChanges();
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        internal static KhartaOntology getContainerByGuidType(Guid containerTypeId, Guid containerId)
        {
            Func <Ontology, KhartaOntology> toContainer = (Ontology fromOntology) => FromOntology(fromOntology);
            KhartaOntology container = new KhartaOntology();

            using (var dbcontext = new KhartaDataModel())
            {
                var result = from o in dbcontext.Ontologies
                             where o.ContainerTypeId == containerTypeId && o.ContainerId == containerId
                             select o;
                Ontology ontology = result.FirstOrDefault();
                if (ontology != null)
                {
                    container = toContainer(ontology);
                }
            }

            return(container);
        }
Пример #6
0
        /// <summary>
        /// A "Get" makes fresh call to the database for each record
        /// one  Ontology container is provided at atime
        /// </summary>
        /// <returns></returns>
        internal static KhartaOntology getContainer(int id)
        {
            Func <Ontology, KhartaOntology> toContainer = (Ontology fromOntology) => FromOntology(fromOntology);
            KhartaOntology container = new KhartaOntology();

            using (var dbcontext = new KhartaDataModel())
            {
                var result = from o in dbcontext.Ontologies
                             where o.Id.Equals(id)
                             select o;
                Ontology ontology = result.FirstOrDefault();
                if (ontology != null)
                {
                    container = toContainer(ontology);
                }
            }

            return(container);
        }
Пример #7
0
        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);
        }
Пример #8
0
        private static KhartaOntology ToContainer(Ontology ontology)
        {
            KhartaOntology khartaOntolgy = FromOntology(ontology);

            return(khartaOntolgy);
        }
Пример #9
0
        private static Ontology toOntology(KhartaOntology container)
        {
            Ontology ontology = FromContainer(container);

            return(ontology);
        }