public void RemoveContent(Guid siteID, Guid rootContentID)
{
using (var transaction = new TransactionScope()) {
try {
IQueryable<carrot_Content> queryCont = (from ct in db.carrot_Contents
where ct.Root_ContentID == rootContentID
select ct);
IQueryable<carrot_RootContent> queryRootContent = (from r in db.carrot_RootContents
where r.SiteID == siteID
&& r.Root_ContentID == rootContentID
select r);
IQueryable<carrot_ContentComment> queryComment = (from r in db.carrot_ContentComments
where r.Root_ContentID == rootContentID
select r);
IQueryable<carrot_TrackbackQueue> queryTrack = (from r in db.carrot_TrackbackQueues
where r.Root_ContentID == rootContentID
select r);
IQueryable<carrot_Widget> queryWidget = (from r in db.carrot_Widgets
where r.Root_ContentID == rootContentID
select r);
List<Guid> widgIDs = queryWidget.Select(x => x.Root_WidgetID).Distinct().ToList();
IQueryable<carrot_WidgetData> queryWidgetData = (from r in db.carrot_WidgetDatas
where widgIDs.Contains(r.Root_WidgetID)
select r);
IQueryable<carrot_Content> queryChildPages = (from ct in db.carrot_Contents
join r in db.carrot_RootContents on ct.Root_ContentID equals r.Root_ContentID
where r.SiteID == siteID
&& ct.Parent_ContentID == rootContentID
select ct);
IQueryable<carrot_TagContentMapping> oldContentTags = CannedQueries.GetContentTagMapByContentID(db, rootContentID);
IQueryable<carrot_CategoryContentMapping> oldContentCategories = CannedQueries.GetContentCategoryMapByContentID(db, rootContentID);
db.carrot_Contents.BatchUpdate(queryChildPages, p => new carrot_Content { Parent_ContentID = null });
db.carrot_TagContentMappings.BatchDelete(oldContentTags);
db.carrot_CategoryContentMappings.BatchDelete(oldContentCategories);
db.carrot_WidgetDatas.BatchDelete(queryWidgetData);
db.carrot_Widgets.BatchDelete(queryWidget);
db.carrot_ContentComments.BatchDelete(queryComment);
db.carrot_TrackbackQueues.BatchDelete(queryTrack);
db.carrot_Contents.BatchDelete(queryCont);
db.carrot_RootContents.BatchDelete(queryRootContent);
Guid? newHomeID = (from ct in db.carrot_Contents
join r in db.carrot_RootContents on ct.Root_ContentID equals r.Root_ContentID
orderby ct.NavOrder ascending
where r.SiteID == siteID
&& ct.Root_ContentID != rootContentID
&& ct.IsLatestVersion == true
&& ct.Parent_ContentID == null
&& r.ContentTypeID == ContentPageType.GetIDByType(ContentPageType.PageType.ContentEntry)
select ct.Root_ContentID).FirstOrDefault();
if (newHomeID == null) {
newHomeID = (from ct in db.carrot_Contents
join r in db.carrot_RootContents on ct.Root_ContentID equals r.Root_ContentID
orderby ct.NavOrder ascending
where r.SiteID == siteID
&& ct.Root_ContentID != rootContentID
&& ct.IsLatestVersion == true
&& r.ContentTypeID == ContentPageType.GetIDByType(ContentPageType.PageType.ContentEntry)
select ct.Root_ContentID).FirstOrDefault();
}
if (newHomeID.HasValue) {
IQueryable<carrot_Content> queryContNH = (from ct in db.carrot_Contents
where ct.Root_ContentID == newHomeID.Value
&& ct.IsLatestVersion == true
select ct);
db.carrot_Contents.BatchUpdate(queryContNH, p => new carrot_Content { NavOrder = 0 });
}
db.SubmitChanges();
transaction.Complete();
} catch (Exception ex) {
throw;
}
}
FixBlogNavOrder(siteID);
}