示例#1
0
 private IEnumerable <HtmlBlock> QueryBySite(Site site)
 {
     return(SiteDbContext.CreateDbContext().HtmlBlocks
            .Where(it => it.SiteName == site.FullName)
            .ToArray()
            .Select(it => it.ToHtmlBlock()));
 }
示例#2
0
        public Models.Page GetDraft(Models.Page page)
        {
            var entity = SiteDbContext.CreateDbContext().PageDrafts
                         .Where(it => it.SiteName == page.Site.FullName && it.FullName == page.FullName)
                         .FirstOrDefault();

            return(PageEntityHelper.ToPage(entity));
        }
示例#3
0
        public Models.User Get(Models.User dummy)
        {
            var entity = SiteDbContext.CreateDbContext().SiteUsers
                         .Where(it => it.SiteName == dummy.Site.FullName && it.UserName == dummy.UserName)
                         .FirstOrDefault();

            return(entity == null ? null : SiteUserHelper.ToUser(entity));
        }
示例#4
0
 public IEnumerable <Models.User> All(Models.Site site)
 {
     return(SiteDbContext.CreateDbContext().SiteUsers
            .Where(it => it.SiteName == site.FullName)
            .ToArray()
            .Select(it => SiteUserHelper.ToUser(it))
            .AsQueryable());
 }
示例#5
0
        public Models.HtmlBlock Get(Models.HtmlBlock dummy)
        {
            var entity = SiteDbContext.CreateDbContext().HtmlBlocks
                         .Where(it => it.SiteName == dummy.Site.FullName && it.Name == dummy.Name)
                         .FirstOrDefault();

            return(entity == null ? null : entity.ToHtmlBlock());
        }
示例#6
0
 public IQueryable <ElementCategory> Categories()
 {
     return(SiteDbContext.CreateDbContext().LabelCategories
            .Where(it => it.SiteName == SiteName)
            .Select(it => new ElementCategory()
     {
         Category = it.CategoryName
     }).ToArray().AsQueryable());
 }
示例#7
0
        public void Localize(Models.Page o, Models.Site targetSite)
        {
            var dbContext = SiteDbContext.CreateDbContext();

            LocalizeWithChildPages(dbContext, o, targetSite);
            dbContext.SaveChanges();

            ClearCache();
        }
示例#8
0
        public void Move(Models.Site site, string pageFullName, string newParent)
        {
            var dbContext = SiteDbContext.CreateDbContext();

            MovePageRecursively(site, pageFullName, newParent, dbContext);

            dbContext.SaveChanges();

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

            return(cacheObject.GetCache <List <PageEntity> >(cacheKey, () =>
            {
                return SiteDbContext.CreateDbContext().Pages.ToArray().Select(it => { it.PageObject = PageEntityHelper.ToPage(it); return it; })
                .ToList();
            }));
        }
示例#10
0
 public IQueryable <Element> Elements()
 {
     return(SiteDbContext.CreateDbContext().Labels
            .Where(it => it.SiteName == SiteName)
            .Select(it => new Element()
     {
         Category = it.Category,
         Name = it.Name,
         Value = it.Value
     }).ToArray().AsQueryable());
 }
示例#11
0
        public void Localize(Models.HtmlBlock o, Models.Site targetSite)
        {
            var htmlBlock = Get(o);
            var entity    = new HtmlBlockEntity(htmlBlock);

            entity.SiteName = targetSite.FullName;

            var dbContext = SiteDbContext.CreateDbContext();

            dbContext.HtmlBlocks.Add(entity);
            dbContext.SaveChanges();
        }
示例#12
0
        public void Clear(Site site)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entities  = dbContext.HtmlBlocks
                            .Where(it => it.SiteName == site.FullName);

            foreach (var item in entities)
            {
                dbContext.HtmlBlocks.Remove(item);
            }
            dbContext.SaveChanges();
        }
示例#13
0
 public Element Get(string name, string category, string culture)
 {
     return(SiteDbContext.CreateDbContext().Labels
            .Where(it => it.SiteName == SiteName && it.Name == name && it.Category == (category ?? ""))
            .Select(it => new Element()
     {
         Category = it.Category,
         Name = it.Name,
         Value = it.Value
     })
            .FirstOrDefault());
 }
示例#14
0
        public void Clear()
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entities  = dbContext.Labels
                            .Where(it => it.SiteName == SiteName);

            foreach (var item in entities)
            {
                dbContext.Labels.Remove(item);
            }
            dbContext.SaveChanges();
        }
示例#15
0
        public void RemoveDraft(Models.Page page)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.PageDrafts
                            .Where(it => it.SiteName == page.Site.FullName && it.FullName == page.FullName)
                            .FirstOrDefault();

            if (entity != null)
            {
                dbContext.PageDrafts.Remove(entity);
                dbContext.SaveChanges();
            }
        }
示例#16
0
        public void Remove(Models.HtmlBlock item)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.HtmlBlocks
                            .Where(it => it.SiteName == item.Site.FullName && it.Name == item.Name)
                            .FirstOrDefault();

            if (entity != null)
            {
                dbContext.HtmlBlocks.Remove(entity);
                dbContext.SaveChanges();
            }
        }
示例#17
0
        public bool Remove(Element element)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.Labels
                            .Where(it => it.SiteName == SiteName && it.Name == element.Name && it.Category == (element.Category ?? ""))
                            .FirstOrDefault();

            if (entity != null)
            {
                dbContext.Labels.Remove(entity);
                dbContext.SaveChanges();
            }
            return(true);
        }
示例#18
0
        public void Remove(Models.Page item)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.Pages
                            .Where(it => it.SiteName == item.Site.FullName && it.FullName == item.FullName)
                            .FirstOrDefault();

            if (entity != null)
            {
                RemovePageWithChildPages(dbContext, entity);

                dbContext.SaveChanges();

                ClearCache();
            }
        }
示例#19
0
        public void AddCategory(string category, string culture)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.LabelCategories
                            .Where(it => it.SiteName == SiteName && it.CategoryName == category)
                            .FirstOrDefault();

            if (entity != null)
            {
            }
            else
            {
                entity = new CategoryEntity(SiteName, category);
                dbContext.LabelCategories.Add(entity);
                dbContext.SaveChanges();
            }
        }
示例#20
0
        private void InsertOrUpdate(Models.HtmlBlock @new, Models.HtmlBlock old)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.HtmlBlocks
                            .Where(it => it.SiteName == @new.Site.FullName && it.Name == @new.Name)
                            .FirstOrDefault();

            if (entity != null)
            {
                entity.Body = @new.Body;
            }
            else
            {
                entity = new HtmlBlockEntity(@new);
                dbContext.HtmlBlocks.Add(entity);
            }
            dbContext.SaveChanges();
        }
示例#21
0
        private void InsertOrUpdate(Models.User @new, Models.User old)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.SiteUsers
                            .Where(it => it.SiteName == @new.Site.FullName && it.UserName == @new.UserName)
                            .FirstOrDefault();

            if (entity != null)
            {
                entity = SiteUserHelper.ToEntity(@new, entity);
            }
            else
            {
                entity = entity = SiteUserHelper.ToEntity(@new, entity);
                dbContext.SiteUsers.Add(entity);
            }

            dbContext.SaveChanges();
        }
示例#22
0
        public void SaveAsDraft(Models.Page page)
        {
            var dbContext = SiteDbContext.CreateDbContext();

            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();
        }
示例#23
0
        public bool RemoveCategory(string category, string culture)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.LabelCategories
                            .Where(it => it.SiteName == SiteName && it.CategoryName == category)
                            .FirstOrDefault();

            if (entity != null)
            {
                dbContext.LabelCategories.Remove(entity);
                var labels = dbContext.Labels
                             .Where(it => it.SiteName == SiteName && it.Category == category);
                foreach (var item in labels)
                {
                    dbContext.Labels.Remove(item);
                }
                dbContext.SaveChanges();
            }
            return(true);
        }
示例#24
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;
            }

            var dbContext = SiteDbContext.CreateDbContext();

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

            ClearCache();

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

            var dbContext = SiteDbContext.CreateDbContext();

            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();
        }
示例#26
0
        private void InsertOrUpdateLabel(Element @new, Element old)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entity    = dbContext.Labels
                            .Where(it => it.SiteName == SiteName && it.Name == @new.Name && it.Category == (@new.Category ?? ""))
                            .FirstOrDefault();

            if (entity != null)
            {
                entity.Value = @new.Value;
            }
            else
            {
                if (!string.IsNullOrEmpty(@new.Category))
                {
                    AddCategory(@new.Category, @new.Culture);
                }
                entity = new LabelEntity(SiteName, @new);
                dbContext.Labels.Add(entity);
            }
            dbContext.SaveChanges();
        }
示例#27
0
        public void Clear(Site site)
        {
            var dbContext = SiteDbContext.CreateDbContext();
            var entities  = dbContext.Pages
                            .Where(it => it.SiteName == site.FullName);

            foreach (var item in entities)
            {
                dbContext.Pages.Remove(item);
            }

            var drafts = dbContext.PageDrafts
                         .Where(it => it.SiteName == site.FullName);

            foreach (var item in drafts)
            {
                dbContext.PageDrafts.Remove(item);
            }
            dbContext.SaveChanges();

            ClearCache();
        }