internal static KhartaSource AddUpdateSourceApplication(KhartaSource khartaSource)
        {
            if (khartaSource.Id == 0)
            {
                khartaSource = CreateNewSourceApplication(khartaSource);
            }
            else
            {
                Func <KhartaSource, Source> toSource       = (KhartaSource fromKhartaSource) => ToSource(fromKhartaSource);
                Func <Source, KhartaSource> toKhartaSource = (Source fromSource) => ToKhartaSource(fromSource);
                Source _updateSource = new Source();
                _updateSource = toSource(khartaSource);
                using (KhartaDataModel dbcontext = new KhartaDataModel())
                {
                    try
                    {
                        dbcontext.Entry(_updateSource).State = System.Data.Entity.EntityState.Modified;

                        dbcontext.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex) {
                        //ex contains the message related to the entity was delete or updated external
                        // unit test deletes the record
                        //TODO: handle the condition
                        var exception = ex;
                    }
                }
                khartaSource = GetSourceApplication(_updateSource.Id);
            }

            return(khartaSource);
        }
        internal static Map CreateMap(Map map)
        {
            MapBook mapbook = GetMapBook(map.MapTypeId);

            if (mapbook != null)
            {
                //if(map.MapBook.ApplicationId != null)
                try
                {
                    using (KhartaDataModel dbcontext = new KhartaDataModel())
                    {
                        map = dbcontext.Maps.Add(map);
                        dbcontext.SaveChanges();
                        return(map);
                    }
                }
                catch (Exception ex)
                {
                    string error = ex.InnerException.Message;
                    InternalApi.Utility.CoriaException csEx = new Utility.CoriaException(CSExceptionType.LoggableException, ex.InnerException.Message, null);
                    csEx.Log();

                    return(map);
                }
            }
            else
            {
                return(map);
            }
        }
Пример #3
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);
        }
        internal static CoriaMapBook CreateUpdateMapBook(CoriaMapBook coriaMapBook)
        {
            if (coriaMapBook.Id == 0)
            {
                coriaMapBook = CreateNewMapBookApplication(coriaMapBook);
            }
            else
            {
                Func <CoriaMapBook, MapBook> toMapBook      = (CoriaMapBook fromCoriaMapBook) => ToMapBook(fromCoriaMapBook, new MapBook());
                Func <MapBook, CoriaMapBook> toCoriaMapBook = (MapBook fromMapBook) => ToCoriaMapBook(fromMapBook, new CoriaMapBook());

                using (KhartaDataModel dbcontext = new KhartaDataModel())
                {
                    try
                    {
                        dbcontext.Entry(toMapBook(coriaMapBook)).State = System.Data.Entity.EntityState.Modified;
                        dbcontext.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        //TODO: handle exception and log it

                        var exception = ex;
                    }
                }
                coriaMapBook = GetCoriaMapBookApplication(coriaMapBook.Id);
            }
            return(coriaMapBook);
        }
Пример #5
0
        /// <summary>
        /// A "find", unlike "get", makes a call once to the database,
        /// cache results are kept in the context until saved. If the current
        /// record is needed, use a "get". Composite keys are allowed
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>


        internal static IList <KhartaOntology> findContainer(int id)
        {
            IList <KhartaOntology> kcgContainers = new List <KhartaOntology>();

            using (var dbcontext = new KhartaDataModel())
            {
                var containers = dbcontext.Ontologies.Find(id);
            }
            return(null);
        }
 internal static void Install(string fileName)
 {
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         foreach (string statement in GetStatementsFromSqlBatch(Utility.EmbeddedResources.GetString("te.extension.kharta.Resources.Sql." + fileName)))
         {
             dbcontext.Database.ExecuteSqlCommand(statement);
         }
         dbcontext.SaveChanges();
     }
 }
 internal static void DeleteCoriaMap(Guid id)
 {
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         var result = (from m in dbcontext.Maps
                       where m.MapId.Equals(id)
                       select m).FirstOrDefault();
         Map map = result;
         dbcontext.Maps.Remove(map);
         dbcontext.SaveChanges();
     }
 }
        internal static IList <Map> ReadMaps()
        {
            using (KhartaDataModel dbcontext = new KhartaDataModel())
            {
                IList <Map> maps = new List <Map>();

                maps = (from m in dbcontext.Maps
                        select m).ToList();

                return(maps);
            }
        }
        internal static Map ReadMap(int id)
        {
            using (KhartaDataModel dbcontext = new KhartaDataModel())
            {
                Map map = new Map();

                map = (from m in dbcontext.Maps
                       where m.Id == id
                       select m).FirstOrDefault();
                return(map);
            }
        }
Пример #10
0
        internal static void deleteContainers(List <KhartaOntology> containers)
        {
            IList <Ontology> ontologies = FromContainers(containers);

            using (var dbcontext = new KhartaDataModel())
            {
                // IList<Ontology> ontologies = new List<Ontology>(); // (new { ontology });
                // ontologies.Add(ontology);
                var db = dbcontext.Ontologies.RemoveRange(ontologies);
                dbcontext.SaveChanges();
            }
        }
 internal static void DeleteCoriaMapBookApplication(Guid id)
 {
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         var result = (from m in dbcontext.MapBooks
                       where m.ApplicationId.Equals(id)
                       select m).FirstOrDefault();
         MapBook mapbook = result;
         dbcontext.MapBooks.Remove(mapbook);
         dbcontext.SaveChanges();
     }
 }
 internal static void DeleteSourceApplication(KhartaSource khartaSource)
 {
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         var result = (from s in dbcontext.Sources
                       where s.Id.Equals(khartaSource.Id)
                       select s).FirstOrDefault();
         Source _source = result;
         dbcontext.Sources.Remove(_source);
         dbcontext.SaveChanges();
     }
 }
        private static MapBook GetMapBookByGroupId_MapBookName(int groupId, string mapBookName)
        {
            using (KhartaDataModel dbcontext = new KhartaDataModel())
            {
                MapBook mapbook = (from m in dbcontext.MapBooks
                                   where m.GroupId.Equals(groupId) &&
                                   m.SafeName.Equals(mapBookName)
                                   select m).FirstOrDefault();

                return(mapbook);
            }
        }
        internal static IList <Map> ReadMaps(Guid MapBookId)
        {
            using (KhartaDataModel dbcontext = new KhartaDataModel())
            {
                IList <Map> maps = new List <Map>();

                maps = (from m in dbcontext.Maps
                        where m.MapTypeId == MapBookId
                        select m).ToList();
                return(maps);
            }
        }
Пример #15
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();
     }
 }
        internal static IList <Source> GetGroupSourceApplications(int groupId)
        {
            IList <Source> sources = new List <Source>();

            using (KhartaDataModel dbcontext = new KhartaDataModel())
            {
                sources = (from s in dbcontext.Sources
                           where s.GroupId.Equals(groupId)
                           select s).ToList();
            }
            //IList<Source> sources = new List<Source>();
            return(sources);
        }
 internal static PagedList <MapBook> MapBookPagedList(int groupId, int pageIndex, int pageSize, string sortBy, string sortOrder)
 {
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         int             skip     = pageIndex * pageSize;
         IList <MapBook> mapbooks = new List <MapBook>();
         mapbooks = (from m in dbcontext.MapBooks
                     where m.GroupId.Equals(groupId)
                     orderby m.Id ascending
                     select m).Skip(skip).Take(pageSize).ToList();
         int totalCount = mapbooks.Count();
         return(new PagedList <MapBook>(mapbooks, pageSize, pageIndex, totalCount));
     }
 }
        internal static KhartaSource CreateNewSourceApplication(KhartaSource khartaSource)
        {
            Source _source = new Source();
            Func <KhartaSource, Source> toSource       = (KhartaSource fromKhartaSource) => ToSource(fromKhartaSource);
            Func <Source, KhartaSource> toKhartaSource = (Source fromSource) => ToKhartaSource(fromSource);

            _source = ToSource(khartaSource);
            using (KhartaDataModel dbcontext = new KhartaDataModel()) {
                _source = dbcontext.Sources.Add(_source);
                dbcontext.SaveChanges();
                khartaSource = ToKhartaSource(_source);
            }
            return(khartaSource);
        }
 private static MapBook GetMapBook(Guid id)
 {
     try
     {
         using (KhartaDataModel dbcontext = new KhartaDataModel())
         {
             return((from m in dbcontext.MapBooks
                     where m.ApplicationId.Equals(id)
                     select m).FirstOrDefault());
         }
     }
     catch (Exception)
     {
         //TODO: log exceptions in community
         throw;
     }
 }
        internal static KhartaSource GetSourceApplication(Guid id)
        {
            Source       _source   = new Source();
            KhartaSource _khSource = new KhartaSource();
            Func <Source, KhartaSource> toKhartaSource = (Source fromSource) => ToKhartaSource(fromSource);

            using (KhartaDataModel dbcontext = new KhartaDataModel())
            {
                _source = (from s in dbcontext.Sources
                           where s.ApplicationId.Equals(id)
                           select s).FirstOrDefault();
                if (_source != null)
                {
                    _khSource = ToKhartaSource(_source);
                }
            }
            return(_khSource);
        }
Пример #21
0
        internal static IList <KhartaOntology> getContainers()
        {
            Func <Ontology, KhartaOntology> toContainer = (Ontology fromOntology) => FromOntology(fromOntology);
            IList <KhartaOntology>          containers  = new List <KhartaOntology>();
            IList <Ontology> _ontologies = new List <Ontology>();

            using (var dbcontext = new KhartaDataModel()) {
                var ontologies = from o in dbcontext.Ontologies
                                 select o;
                // _ontologies = new ApiList<Ontology>(ListKhartaOntology().Select(x => new Ontology(_khartaOntology)));

                _ontologies = ontologies.ToList();
            }
            containers = new List <KhartaOntology>(_ontologies.Select(_ontology => toContainer(_ontology)));


            return(containers);
        }
        internal static IList <MapBook> GetMapBooksByGroup(int groupId)
        {
            IList <MapBook> mapbooks = new List <MapBook>();

            try
            {
                using (KhartaDataModel dbcontext = new KhartaDataModel())
                {
                    mapbooks = (from m in dbcontext.MapBooks
                                where m.GroupId.Equals(groupId)
                                select m).ToList();
                    return(mapbooks);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 internal static PagedList <Map> MapPagedList(MapBook mapbook, int pageIndex, int pageSize, string sortBy, string sortOrder)
 {
     if (mapbook == null)
     {
         return(null);
     }
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         int skip = pageIndex * pageSize;
         // PagedList<Map> mapList = new PagedList<Map>();
         IList <Map> mapList = new List <Map>();
         mapList = (from m in dbcontext.Maps
                    where m.MapTypeId.Equals(mapbook.ApplicationId)
                    orderby m.SafeName ascending
                    select m).Skip(skip).Take(pageSize).ToList();
         int totalCount = mapList.Count();
         return(new PagedList <Map>(mapList, pageSize, pageIndex, totalCount));;
     }
 }
Пример #24
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);
        }
Пример #25
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);
        }
 internal static void MapBook_SetEnabled(int userId, Guid applicationId, bool enabled)
 {
     using (KhartaDataModel dbcontext = new KhartaDataModel())
     {
         var mapbook = (from m in dbcontext.MapBooks
                        where m.ApplicationId.Equals(applicationId)
                        select m
                        ).FirstOrDefault();
         mapbook.IsEnabled = enabled;
         try
         {
             dbcontext.Entry(mapbook).State = System.Data.Entity.EntityState.Modified;
             dbcontext.SaveChanges();
         }
         catch (DbUpdateConcurrencyException ex)
         {
             var exception = ex;
             throw;
         }
     }
 }
        internal static CoriaMapBook CreateNewMapBookApplication(CoriaMapBook coriaMapBook)
        {
            Func <CoriaMapBook, MapBook> toMapBook      = (CoriaMapBook fromCoriaMapBook) => ToMapBook(fromCoriaMapBook, new MapBook());
            Func <MapBook, CoriaMapBook> toCoriaMapBook = (MapBook fromMapBook) => ToCoriaMapBook(fromMapBook, new CoriaMapBook());

            try
            {
                using (KhartaDataModel dbcontext = new KhartaDataModel())
                {
                    MapBook mapbook = dbcontext.MapBooks.Add(toMapBook(coriaMapBook));
                    dbcontext.SaveChanges();
                    return(toCoriaMapBook(mapbook));
                }
            }
            catch (Exception ex)
            {
                //TODO: log exception
                var exception = ex;
                throw;
            }
        }
        internal static Map CreateUpdateMap(Map map)
        {
            Func <CoriaMap, Map> toMap      = (CoriaMap fromCoriaMap) => ToMap(fromCoriaMap, new Map());
            Func <Map, CoriaMap> toCoriaMap = (Map fromMap) => ToCoriaMap(fromMap, new CoriaMap());

            if (map.Id == 0)
            {
                try
                {
                    map = CreateMap(map);
                }
                catch (Exception ex)
                {
                    //TODO: log exception
                    var exception = ex;
                    throw;
                }
            }
            else
            {
                using (KhartaDataModel dbcontext = new KhartaDataModel())
                {
                    try
                    {
                        dbcontext.Entry(map).State = System.Data.Entity.EntityState.Modified;
                        dbcontext.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var exception = ex;
                        throw;
                    }
                }
                map = ReadMap(map.Id);
            }
            return(map);
        }
Пример #29
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);
        }