Exemple #1
0
        private void MovePageRecursively(Models.Site site, string pageFullName, string newParent, SiteDBContext dbContext)
        {
            var oldPage = Get(new Page(site, pageFullName));
            var entity  = PageEntityHelper.ToPageEntity <PageEntity>(oldPage);

            if (!string.IsNullOrEmpty(newParent))
            {
                var newPage = new Page(new Page(site, newParent), oldPage.Name);
                entity.FullName   = newPage.FullName;
                entity.ParentPage = newPage.Parent.FullName;
            }
            else
            {
                entity.FullName   = oldPage.Name;
                entity.ParentPage = "";
            }

            dbContext.Pages.Add(entity);

            foreach (var item in ChildPages(oldPage))
            {
                MovePageRecursively(site, item.FullName, entity.FullName, dbContext);
            }

            var oldEntity = dbContext.Pages
                            .Where(it => it.SiteName == oldPage.Site.FullName && it.FullName == oldPage.FullName)
                            .FirstOrDefault();

            if (oldEntity != null)
            {
                dbContext.Pages.Remove(oldEntity);
            }
        }
Exemple #2
0
        public Models.Page GetDraft(Models.Page page)
        {
            var entity = _dbContext.PageDrafts
                         .Where(it => it.SiteName == page.Site.FullName && it.FullName == page.FullName)
                         .FirstOrDefault();

            return(PageEntityHelper.ToPage(entity));
        }
Exemple #3
0
        /// <summary>
        /// 为什么要缓存Page表呢?
        /// 1. 因为在实际使用过程中发现,如果页面数量相对比较多的时候,第一次查找页面的过程中会调用很多次ChildPages,导致请求的效率很低,时间花费很高。
        /// 2. 目前的设计已经是假设页面数量不多的前提了。所以缓该表的数据量是可以接受的。
        /// </summary>
        private List <PageEntity> GetCachedPageList()
        {
            var cacheObject = CacheManagerFactory.DefaultCacheManager.GlobalObjectCache();

            return(cacheObject.GetCache <List <PageEntity> >(cacheKey, () =>
            {
                return _dbContext.Pages.ToArray().Select(it => { it.PageObject = PageEntityHelper.ToPage(it); return it; })
                .ToList();
            }));
        }
Exemple #4
0
        public void SaveAsDraft(Models.Page page)
        {
            var entity = _dbContext.PageDrafts
                         .Where(it => it.SiteName == page.Site.FullName && it.FullName == page.FullName)
                         .FirstOrDefault();

            if (entity != null)
            {
                PageEntityHelper.ToPageEntity(page, entity);
            }
            else
            {
                _dbContext.PageDrafts.Add(PageEntityHelper.ToPageEntity <PageDraftEntity>(page));
            }

            _dbContext.SaveChanges();
        }
Exemple #5
0
        public Models.Page Copy(Models.Site site, string sourcePageFullName, string newPageFullName)
        {
            var page    = Get(new Page(site, sourcePageFullName));
            var newPage = new Page(site, newPageFullName);
            var entity  = PageEntityHelper.ToPageEntity <PageEntity>(page);

            entity.FullName = newPageFullName;
            if (newPage.Parent != null)
            {
                entity.ParentPage = newPage.Parent.FullName;
            }

            _dbContext.Pages.Add(entity);
            _dbContext.SaveChanges();

            ClearCache();

            return(PageEntityHelper.ToPage(entity));
        }
Exemple #6
0
        private void InsertOrUpdate(Models.Page @new, Models.Page old)
        {
            @new.OnSaving();

            var entity = _dbContext.Pages
                         .Where(it => it.SiteName == old.Site.FullName && it.FullName == old.FullName)
                         .FirstOrDefault();

            if (entity != null)
            {
                PageEntityHelper.ToPageEntity(@new, entity);
            }
            else
            {
                _dbContext.Pages.Add(PageEntityHelper.ToPageEntity <PageEntity>(@new));
            }
            _dbContext.SaveChanges();
            ClearCache();
        }
Exemple #7
0
        private void LocalizeWithChildPages(SiteDBContext dbContext, Page page, Site targetSite)
        {
            var entity = dbContext.Pages
                         .Where(it => it.SiteName == targetSite.FullName && it.FullName == page.FullName)
                         .FirstOrDefault();

            if (entity == null)
            {
                page = Get(page);

                entity          = PageEntityHelper.ToPageEntity <PageEntity>(page);
                entity.SiteName = targetSite.FullName;

                dbContext.Pages.Add(entity);

                foreach (var item in ChildPages(page))
                {
                    LocalizeWithChildPages(dbContext, item, targetSite);
                }
            }
        }