public void FixOrphanPages(Guid siteID) { List <SiteMapOrder> lstContent = CannedQueries.GetAllContentList(db, siteID).Select(ct => new SiteMapOrder(ct)).ToList(); List <Guid> lstIDs = lstContent.Select(x => x.Root_ContentID).ToList(); lstContent.RemoveAll(x => x.Parent_ContentID == null); lstContent.RemoveAll(x => lstIDs.Contains(x.Parent_ContentID.Value)); lstIDs = lstContent.Select(x => x.Root_ContentID).ToList(); IQueryable <carrot_Content> querySite = (from c in db.carrot_Contents where c.IsLatestVersion == true && c.Parent_ContentID != null && lstIDs.Contains(c.Root_ContentID) select c); db.carrot_Contents.BatchUpdate(querySite, p => new carrot_Content { Parent_ContentID = null }); IQueryable <carrot_Content> querySite2 = (from c in db.carrot_Contents join rc in db.carrot_RootContents on c.Root_ContentID equals rc.Root_ContentID where c.IsLatestVersion == true && c.Parent_ContentID != null && rc.SiteID == siteID && rc.ContentTypeID == ContentPageType.GetIDByType(ContentPageType.PageType.BlogEntry) select c); db.carrot_Contents.BatchUpdate(querySite2, p => new carrot_Content { Parent_ContentID = null }); db.SubmitChanges(); }
public void RemoveVersions(List <Guid> lstDel) { IQueryable <carrot_WidgetData> oldW = (from w in db.carrot_WidgetDatas orderby w.EditDate descending where lstDel.Contains(w.WidgetDataID) && w.IsLatestVersion != true select w); db.carrot_WidgetDatas.BatchDelete(oldW); db.SubmitChanges(); }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.GetDataContext()) { bool bNew = false; carrot_UserData usr = CompiledQueries.cqFindUserTblByID(_db, this.UserId); if (usr == null) { usr = new carrot_UserData(); usr.UserId = this.UserId; bNew = true; } usr.UserNickName = this.UserNickName; usr.FirstName = this.FirstName; usr.LastName = this.LastName; usr.UserBio = this.UserBio; if (bNew) { _db.carrot_UserDatas.InsertOnSubmit(usr); } _db.SubmitChanges(); this.UserId = usr.UserId; } }
public void Save() { bool bNew = false; carrot_TrackbackQueue s = CompiledQueries.cqGetTrackbackTblByID(db, this.TrackbackQueueID); if (s == null) { s = new carrot_TrackbackQueue(); s.TrackbackQueueID = Guid.NewGuid(); s.Root_ContentID = this.Root_ContentID; s.CreateDate = DateTime.UtcNow; s.TrackBackURL = this.TrackBackURL.Trim(); bNew = true; } s.ModifiedDate = DateTime.UtcNow; s.TrackBackResponse = this.TrackBackResponse; s.TrackedBack = this.TrackedBack; if (bNew) { db.carrot_TrackbackQueues.InsertOnSubmit(s); } this.TrackbackQueueID = s.TrackbackQueueID; db.SubmitChanges(); }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { bool bNew = false; carrot_UserData usr = CompiledQueries.cqFindUserTblByID(_db, this.UserId); if (usr == null) { usr = new carrot_UserData(); usr.UserKey = this.UserKey; usr.UserId = Guid.NewGuid(); bNew = true; } usr.UserNickName = this.UserNickName; usr.FirstName = this.FirstName; usr.LastName = this.LastName; usr.UserBio = this.UserBio; if (bNew) { _db.carrot_UserDatas.InsertOnSubmit(usr); } _db.SubmitChanges(); this.UserId = usr.UserId; //grab fresh copy from DB vw_carrot_UserData rc = CompiledQueries.cqFindUserByID(_db, usr.UserId); LoadUserData(rc); } }
public bool AddToSite(Guid siteID) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_UserSiteMapping map = (from m in _db.carrot_UserSiteMappings where m.UserId == this.UserId && m.SiteID == siteID select m).FirstOrDefault(); if (map == null) { _siteIDs = null; map = new carrot_UserSiteMapping(); map.UserSiteMappingID = Guid.NewGuid(); map.SiteID = siteID; map.UserId = this.UserId; _db.carrot_UserSiteMappings.InsertOnSubmit(map); _db.SubmitChanges(); return(true); } else { return(false); } } }
public static void AddUserToRole(Guid UserId, string roleName) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name.ToLower() == roleName.ToLower() select r).FirstOrDefault(); membership_User user = (from u in _db.membership_Users join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey where ud.UserId == UserId select u).FirstOrDefault(); membership_UserRole usrRole = (from r in _db.membership_Roles join ur in _db.membership_UserRoles on r.Id equals ur.RoleId join u in _db.membership_Users on ur.UserId equals u.Id join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey where r.Name.ToLower() == roleName.ToLower() && ud.UserId == UserId select ur).FirstOrDefault(); if (usrRole == null && role != null && user != null) { usrRole = new membership_UserRole(); usrRole.UserId = user.Id; usrRole.RoleId = role.Id; _db.membership_UserRoles.InsertOnSubmit(usrRole); _db.SubmitChanges(); } } }
public static void SaveSerialized(Guid itemID, string sKey, string sData) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { bool bAdd = false; carrot_SerialCache itm = CompiledQueries.SearchSeriaCache(_db, itemID, sKey); if (itm == null) { bAdd = true; itm = new carrot_SerialCache(); itm.SerialCacheID = Guid.NewGuid(); itm.SiteID = SiteData.CurrentSiteID; itm.ItemID = itemID; itm.EditUserId = SecurityData.CurrentUserGuid; itm.KeyType = sKey; } itm.SerializedData = sData; itm.EditDate = DateTime.UtcNow; if (bAdd) { _db.carrot_SerialCaches.InsertOnSubmit(itm); } _db.SubmitChanges(); } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_TextWidget s = CompiledQueries.cqTextWidgetByID(_db, this.TextWidgetID); if (s == null) { s = new carrot_TextWidget(); s.TextWidgetID = Guid.NewGuid(); s.SiteID = this.SiteID; s.TextWidgetAssembly = this.TextWidgetAssembly; _db.carrot_TextWidgets.InsertOnSubmit(s); } s.ProcessBody = this.ProcessBody; s.ProcessPlainText = this.ProcessPlainText; s.ProcessHTMLText = this.ProcessHTMLText; s.ProcessComment = this.ProcessComment; s.ProcessSnippet = this.ProcessSnippet; _db.SubmitChanges(); this.TextWidgetID = s.TextWidgetID; } }
public static bool AddUserToRole(string userName, string roleName) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name == roleName select r).FirstOrDefault(); membership_User user = (from u in _db.membership_Users where u.UserName == userName select u).FirstOrDefault(); membership_UserRole usrRole = (from r in _db.membership_Roles join ur in _db.membership_UserRoles on r.Id equals ur.RoleId join u in _db.membership_Users on ur.UserId equals u.Id where r.Name == roleName && u.UserName == userName select ur).FirstOrDefault(); if (usrRole == null && role != null && user != null) { usrRole = new membership_UserRole(); usrRole.UserId = user.Id; usrRole.RoleId = role.Id; _db.membership_UserRoles.InsertOnSubmit(usrRole); _db.SubmitChanges(); return(true); } return(false); } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { bool bNew = false; carrot_ContentTag s = CompiledQueries.cqGetContentTagByID(_db, this.ContentTagID); if (s == null || (s != null && s.ContentTagID == Guid.Empty)) { s = new carrot_ContentTag(); s.ContentTagID = Guid.NewGuid(); s.SiteID = this.SiteID; bNew = true; } s.TagSlug = ContentPageHelper.ScrubSlug(this.TagSlug); s.TagText = this.TagText; s.IsPublic = this.IsPublic; if (bNew) { _db.carrot_ContentTags.InsertOnSubmit(s); } _db.SubmitChanges(); this.ContentTagID = s.ContentTagID; } }
public void ResetHeartbeatLock() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_RootContent rc = CompiledQueries.cqGetRootContentTbl(_db, this.SiteID, this.Root_ContentID); rc.EditHeartbeat = DateTime.UtcNow.AddHours(-2); rc.Heartbeat_UserId = null; _db.SubmitChanges(); } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_Site s = CompiledQueries.cqGetSiteByID(_db, this.SiteID); bool bNew = false; if (s == null) { s = new carrot_Site(); if (this.SiteID == Guid.Empty) { this.SiteID = Guid.NewGuid(); } bNew = true; } // if updating the current site then blank out its cache if (CurrentSiteID == this.SiteID) { CurrentSite = null; } s.SiteID = this.SiteID; s.TimeZone = this.TimeZoneIdentifier; FixMeta(); s.MetaKeyword = this.MetaKeyword.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ").Replace(" ", " "); s.MetaDescription = this.MetaDescription.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ").Replace(" ", " "); s.SiteName = this.SiteName; s.SiteTagline = this.SiteTagline; s.SiteTitlebarPattern = this.SiteTitlebarPattern; s.MainURL = this.MainURL; s.BlockIndex = this.BlockIndex; s.SendTrackbacks = this.SendTrackbacks; s.AcceptTrackbacks = this.AcceptTrackbacks; s.Blog_FolderPath = ContentPageHelper.ScrubSlug(this.Blog_FolderPath); s.Blog_CategoryPath = ContentPageHelper.ScrubSlug(this.Blog_CategoryPath); s.Blog_TagPath = ContentPageHelper.ScrubSlug(this.Blog_TagPath); s.Blog_EditorPath = ContentPageHelper.ScrubSlug(this.Blog_EditorPath); s.Blog_DatePath = ContentPageHelper.ScrubSlug(this.Blog_DatePath); s.Blog_Root_ContentID = this.Blog_Root_ContentID; s.Blog_DatePattern = String.IsNullOrEmpty(this.Blog_DatePattern) ? "yyyy/MM/dd" : this.Blog_DatePattern; if (bNew) { _db.carrot_Sites.InsertOnSubmit(s); } _db.SubmitChanges(); } }
public void RecordHeartbeatLock(Guid currentUserID) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_RootContent rc = CompiledQueries.cqGetRootContentTbl(_db, this.SiteID, this.Root_ContentID); rc.Heartbeat_UserId = currentUserID; rc.EditHeartbeat = DateTime.UtcNow; _db.SubmitChanges(); } }
public static void CleanUpSerialData() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { IQueryable <carrot_SerialCache> lst = (from c in _db.carrot_SerialCaches where c.EditDate < DateTime.UtcNow.AddHours(-6) select c); _db.carrot_SerialCaches.BatchDelete(lst); _db.SubmitChanges(); } }
public void Delete() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_ContentComment c = CompiledQueries.cqGetContentCommentsTblByID(_db, this.ContentCommentID); if (c != null) { _db.carrot_ContentComments.DeleteOnSubmit(c); _db.SubmitChanges(); } } }
public void MapUserToSite(Guid siteID, Guid userID) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_UserSiteMapping map = new carrot_UserSiteMapping(); map.UserSiteMappingID = Guid.NewGuid(); map.SiteID = siteID; map.UserId = userID; _db.carrot_UserSiteMappings.InsertOnSubmit(map); _db.SubmitChanges(); } }
public void Delete() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_TextWidget s = CompiledQueries.cqTextWidgetByID(_db, this.TextWidgetID); if (s != null) { _db.carrot_TextWidgets.DeleteOnSubmit(s); _db.SubmitChanges(); } } }
public void SavePageEdit() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { SiteData site = SiteData.GetSiteFromCache(this.SiteID); if (this.Root_ContentID == Guid.Empty) { this.Root_ContentID = Guid.NewGuid(); } if (this.ContentID == Guid.Empty) { this.ContentID = Guid.NewGuid(); } if (this.Parent_ContentID == Guid.Empty) { this.Parent_ContentID = null; } carrot_RootContent rc = CompiledQueries.cqGetRootContentTbl(_db, this.SiteID, this.Root_ContentID); carrot_Content oldC = CompiledQueries.cqGetLatestContentTbl(_db, this.SiteID, this.Root_ContentID); bool bNew = false; if (rc == null) { rc = new carrot_RootContent(); PerformCommonSaveRoot(site, rc); _db.carrot_RootContents.InsertOnSubmit(rc); bNew = true; } carrot_Content c = new carrot_Content(); c.ContentID = Guid.NewGuid(); if (!bNew) { oldC.IsLatestVersion = false; } PerformCommonSave(site, rc, c); _db.carrot_Contents.InsertOnSubmit(c); SaveKeywordsAndTags(_db); _db.SubmitChanges(); SaveTrackbacks(); } }
public void ApplyTemplate() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_Content c = CompiledQueries.cqGetLatestContentTbl(_db, this.SiteID, this.Root_ContentID); if (c != null) { c.TemplateFile = this.TemplateFile; _db.SubmitChanges(); } } }
public void Delete() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_ContentCategory s = CompiledQueries.cqGetContentCategoryByID(_db, this.ContentCategoryID); if (s != null) { IQueryable<carrot_CategoryContentMapping> lst = (from m in _db.carrot_CategoryContentMappings where m.ContentCategoryID == s.ContentCategoryID select m); _db.carrot_CategoryContentMappings.BatchDelete(lst); _db.carrot_ContentCategories.DeleteOnSubmit(s); _db.SubmitChanges(); } } }
public static bool ClearSerialized(Guid itemID, string sKey) { bool bRet = false; using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_SerialCache itm = CompiledQueries.SearchSeriaCache(_db, itemID, sKey); if (itm != null) { _db.carrot_SerialCaches.DeleteOnSubmit(itm); _db.SubmitChanges(); bRet = true; } } return(bRet); }
public void Delete() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.GetDataContext()) { carrot_RootContentSnippet s = CompiledQueries.cqGetSnippetDataTbl(_db, this.SiteID, this.Root_ContentSnippetID); if (s != null) { IQueryable <carrot_ContentSnippet> lst = (from m in _db.carrot_ContentSnippets where m.Root_ContentSnippetID == s.Root_ContentSnippetID select m); _db.carrot_ContentSnippets.BatchDelete(lst); _db.carrot_RootContentSnippets.DeleteOnSubmit(s); _db.SubmitChanges(); } } }
public static void RemoveUserFromRole(string userName, string roleName) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_UserRole usrRole = (from r in _db.membership_Roles join ur in _db.membership_UserRoles on r.Id equals ur.RoleId join u in _db.membership_Users on ur.UserId equals u.Id where r.Name.ToLower() == roleName.ToLower() && u.UserName.ToLower() == userName.ToLower() select ur).FirstOrDefault(); if (usrRole != null) { _db.membership_UserRoles.DeleteOnSubmit(usrRole); _db.SubmitChanges(); } } }
public void DeleteThisVersion() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_RootContentSnippet s = CompiledQueries.cqGetSnippetDataTbl(_db, this.SiteID, this.Root_ContentSnippetID); if (s != null) { IQueryable <carrot_ContentSnippet> lst = (from m in _db.carrot_ContentSnippets where m.ContentSnippetID == this.ContentSnippetID && m.Root_ContentSnippetID == s.Root_ContentSnippetID && m.IsLatestVersion != true select m); _db.carrot_ContentSnippets.BatchDelete(lst); _db.SubmitChanges(); } } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { bool bNew = false; carrot_ContentComment c = CompiledQueries.cqGetContentCommentsTblByID(_db, this.ContentCommentID); if (c == null) { c = new carrot_ContentComment(); c.CreateDate = DateTime.UtcNow; bNew = true; if (this.CreateDate.Year > 1950) { c.CreateDate = SiteData.CurrentSite.ConvertSiteTimeToUTC(this.CreateDate); } } if (this.ContentCommentID == Guid.Empty) { this.ContentCommentID = Guid.NewGuid(); } c.ContentCommentID = this.ContentCommentID; c.Root_ContentID = this.Root_ContentID; c.CommenterIP = this.CommenterIP; c.CommenterName = this.CommenterName; c.CommenterEmail = this.CommenterEmail; c.CommenterURL = this.CommenterURL; c.PostComment = this.PostCommentText; c.IsApproved = this.IsApproved; c.IsSpam = this.IsSpam; if (bNew) { _db.carrot_ContentComments.InsertOnSubmit(c); } _db.SubmitChanges(); this.ContentCommentID = c.ContentCommentID; this.CreateDate = c.CreateDate; } }
public void SavePageAsDraft() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { SiteData site = SiteData.GetSiteFromCache(this.SiteID); if (this.Root_ContentID == Guid.Empty) { this.Root_ContentID = Guid.NewGuid(); } if (this.ContentID == Guid.Empty) { this.ContentID = Guid.NewGuid(); } carrot_RootContent rc = CompiledQueries.cqGetRootContentTbl(_db, this.SiteID, this.Root_ContentID); if (rc == null) { rc = new carrot_RootContent(); PerformCommonSaveRoot(site, rc); _db.carrot_RootContents.InsertOnSubmit(rc); } carrot_Content c = new carrot_Content(); c.ContentID = Guid.NewGuid(); PerformCommonSave(site, rc, c); c.IsLatestVersion = false; // draft, leave existing version latest _db.carrot_Contents.InsertOnSubmit(c); SaveKeywordsAndTags(_db); _db.SubmitChanges(); this.IsLatestVersion = c.IsLatestVersion; SaveTrackbacks(); } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name == this.RoleName || r.Id == this.RoleId select r).FirstOrDefault(); if (role == null) { role = new membership_Role(); role.Id = Guid.NewGuid().ToString().ToLowerInvariant(); _db.membership_Roles.InsertOnSubmit(role); } role.Name = this.RoleName.Trim(); _db.SubmitChanges(); this.RoleName = role.Name; this.RoleId = role.Id; } }
public bool RemoveFromSite(Guid siteID) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { carrot_UserSiteMapping map = (from m in _db.carrot_UserSiteMappings where m.UserId == this.UserId && m.SiteID == siteID select m).FirstOrDefault(); if (map != null) { _siteIDs = null; _db.carrot_UserSiteMappings.DeleteOnSubmit(map); _db.SubmitChanges(); return(true); } else { return(false); } } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.GetDataContext()) { aspnet_Role role = (from l in _db.aspnet_Roles where l.LoweredRoleName == this.RoleName || l.RoleId == this.RoleId select l).FirstOrDefault(); if (role == null) { if (!Roles.RoleExists(this.RoleName) && this.RoleId == Guid.Empty) { Roles.CreateRole(this.RoleName); } } else { role.RoleName = this.RoleName; role.LoweredRoleName = role.RoleName.ToLowerInvariant(); _db.SubmitChanges(); } } }