Exemplo n.º 1
0
        public IEnumerable <DataItem> GetAllByParentID(int?parentID)
        {
            IEnumerable <DataItem> result;

            Dictionary <int?, IEnumerable <DataItem> > dataItemsByParent = CacheController.GetFromCache(CacheController.CacheItemKey.DataItemsByParent) as Dictionary <int?, IEnumerable <DataItem> >;

            if (dataItemsByParent == null)
            {
                dataItemsByParent = new Dictionary <int?, IEnumerable <DataItem> >();
                CacheController.AddToCache(CacheController.CacheItemKey.DataItemsByParent, dataItemsByParent);
            }

            if (dataItemsByParent.ContainsKey(parentID ?? 0))
            {
                result = dataItemsByParent[parentID ?? 0];
            }
            else
            {
                result = Mapper.Map <IEnumerable <DataItem> >(_context.DataItems.Where(d => d.ParentFolderID == parentID));

                dataItemsByParent.Add(parentID ?? 0, result);
            }

            return(result);
        }
Exemplo n.º 2
0
        public IEnumerable <Folder> GetByParentID(int?parentID)
        {
            IEnumerable <Folder> result;

            Dictionary <int?, IEnumerable <Folder> > foldersByParent = CacheController.GetFromCache(CacheController.CacheItemKey.FoldersByParent) as Dictionary <int?, IEnumerable <Folder> >;

            if (foldersByParent == null)
            {
                foldersByParent = new Dictionary <int?, IEnumerable <Folder> >();
                CacheController.AddToCache(CacheController.CacheItemKey.FoldersByParent, foldersByParent);
            }

            if (foldersByParent.ContainsKey(parentID ?? 0))
            {
                result = foldersByParent[parentID ?? 0];
            }
            else
            {
                result = Mapper.Map <IEnumerable <Folder> >(_context.Folders.Include("DataItem").Where(f => f.DataItem.ParentFolderID == parentID));

                foldersByParent.Add(parentID ?? 0, result);
            }

            return(result);
        }