private IEnumerable <HtmlBlock> QueryBySite(Site site) { return(SiteDbContext.CreateDbContext().HtmlBlocks .Where(it => it.SiteName == site.FullName) .ToArray() .Select(it => it.ToHtmlBlock())); }
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)); }
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)); }
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()); }
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()); }
public IQueryable <ElementCategory> Categories() { return(SiteDbContext.CreateDbContext().LabelCategories .Where(it => it.SiteName == SiteName) .Select(it => new ElementCategory() { Category = it.CategoryName }).ToArray().AsQueryable()); }
public void Localize(Models.Page o, Models.Site targetSite) { var dbContext = SiteDbContext.CreateDbContext(); LocalizeWithChildPages(dbContext, o, targetSite); dbContext.SaveChanges(); ClearCache(); }
public void Move(Models.Site site, string pageFullName, string newParent) { var dbContext = SiteDbContext.CreateDbContext(); MovePageRecursively(site, pageFullName, newParent, dbContext); dbContext.SaveChanges(); ClearCache(); }
/// <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(); })); }
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()); }
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(); }
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(); }
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()); }
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(); }
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(); } }
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(); } }
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); }
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(); } }
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(); } }
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(); }
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(); }
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(); }
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); }
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)); }
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(); }
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(); }
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(); }