Inheritance: IValidatableObject
		public ActionResult PageAddChild(ContentPageModel model) {
			model.VisitPage = false;

			if (ModelState.IsValid && model.ParentID.HasValue) {
				var pageContents = model.ContentPage;
				pageContents.SiteID = this.SiteID;
				pageContents.ContentType = ContentPageType.PageType.ContentEntry;

				pageContents.SavePageEdit();

				ShowSaved("Page Created");
				model.VisitPage = true;
			}

			Helper.HandleErrorDict(ModelState);
			return View(model);
		}
		public ActionResult DeleteContentPage(ContentPageModel model) {
			using (ContentPageHelper cph = new ContentPageHelper()) {
				cph.RemoveContent(this.SiteID, model.ContentPage.Root_ContentID);
			}

			if (model.ContentPage.ContentType == ContentPageType.PageType.BlogEntry) {
				return RedirectToAction("BlogPostIndex");
			}

			return RedirectToAction("PageIndex");
		}
		public ActionResult PageAddChild(Guid id, bool? saved) {
			//if (saved.HasValue && saved.Value) {
			//	ShowSave();
			//}

			ContentPageModel model = new ContentPageModel();

			var pageContentsParent = pageHelper.FindContentByID(this.SiteID, id);
			var pageContents = new ContentPage(this.SiteID, ContentPageType.PageType.ContentEntry);

			if (pageContentsParent != null && pageContentsParent.ContentType == ContentPageType.PageType.ContentEntry) {
				pageContents.Parent_ContentID = id;
			} else {
				pageContents.Parent_ContentID = Guid.Empty;
			}

			model.SetPage(pageContents);

			model.VisitPage = false;
			model.ParentID = id;

			return View(model);
		}
		public ActionResult BlogPostAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) {
			ContentPageModel model = new ContentPageModel();
			ContentPage pageContents = model.GetPost(id, versionid, importid, mode);
			ViewBag.ContentEditMode = model.Mode;

			if (pageContents.ContentType != ContentPageType.PageType.BlogEntry) {
				return RedirectToAction("PageAddEdit", new { @id = pageContents.Root_ContentID, @mode = model.Mode });
			}

			return View(model);
		}
		public ActionResult BlogPostAddEdit(ContentPageModel model) {
			Helper.ForceValidation(ModelState, model);
			model.Mode = (String.IsNullOrEmpty(model.Mode) || model.Mode.Trim().ToLowerInvariant() != "raw") ? "html" : "raw";
			ViewBag.ContentEditMode = model.Mode;

			if (ModelState.IsValid) {
				var pageContents = model.SavePost();

				if (model.VisitPage) {
					Response.Redirect(pageContents.FileName);
				} else {
					return RedirectToAction("BlogPostAddEdit", new { @id = pageContents.Root_ContentID, @mode = model.Mode });
				}
			}

			Helper.HandleErrorDict(ModelState);
			model.RefreshWidgetList();

			return View(model);
		}
		public ActionResult BlogPostEdit(Guid id) {
			ContentPageModel model = new ContentPageModel();

			cmsHelper.OverrideKey(id);
			ContentPage pageContents = cmsHelper.cmsAdminContent;

			model.SetPage(pageContents);

			ShowSaved();

			return View(model);
		}
		public ActionResult BlogPostEdit(ContentPageModel model) {
			cmsHelper.OverrideKey(model.ContentPage.Root_ContentID);

			ContentPage page = model.ContentPage;

			var pageContents = cmsHelper.cmsAdminContent;

			pageContents.GoLiveDate = page.GoLiveDate;
			pageContents.RetireDate = page.RetireDate;

			pageContents.IsLatestVersion = true;
			pageContents.Thumbnail = page.Thumbnail;

			pageContents.TitleBar = page.TitleBar;
			pageContents.NavMenuText = page.NavMenuText;
			pageContents.PageHead = page.PageHead;

			pageContents.MetaDescription = page.MetaDescription;
			pageContents.MetaKeyword = page.MetaKeyword;

			pageContents.EditDate = SiteData.CurrentSite.Now;
			pageContents.NavOrder = page.NavOrder;

			pageContents.PageActive = page.PageActive;
			pageContents.ShowInSiteNav = page.ShowInSiteNav;
			pageContents.ShowInSiteMap = page.ShowInSiteMap;
			pageContents.BlockIndex = page.BlockIndex;

			pageContents.CreditUserId = page.CreditUserId;

			pageContents.EditUserId = SecurityData.CurrentUserGuid;
			pageContents.Parent_ContentID = null;

			pageContents.ContentCategories = (from l in SiteData.CurrentSite.GetCategoryList()
											  join cr in model.SelectedCategories on l.ContentCategoryID.ToString().ToLowerInvariant() equals cr.ToLowerInvariant()
											  select l).ToList();
			pageContents.ContentTags = (from l in SiteData.CurrentSite.GetTagList()
										join cr in model.SelectedTags on l.ContentTagID.ToString().ToLowerInvariant() equals cr.ToLowerInvariant()
										select l).ToList();

			model.SetPage(pageContents);

			Helper.ForceValidation(ModelState, model);

			if (ModelState.IsValid) {
				cmsHelper.cmsAdminContent = pageContents;
				SetSaved();
				return RedirectToAction("BlogPostEdit", new { @id = model.ContentPage.Root_ContentID });
			}

			Helper.HandleErrorDict(ModelState);

			return View(model);
		}
		public ActionResult PageAddChild(Guid id, bool? saved) {
			//if (saved.HasValue && saved.Value) {
			//	ShowSave();
			//}

			ContentPageModel model = new ContentPageModel();

			var pageContents = new ContentPage(this.SiteID, ContentPageType.PageType.ContentEntry);
			pageContents.Parent_ContentID = id;
			model.SetPage(pageContents);

			model.VisitPage = false;
			model.ParentID = id;

			return View(model);
		}
		public ActionResult PageEdit(ContentPageModel model) {
			cmsHelper.OverrideKey(model.ContentPage.Root_ContentID);

			ContentPage page = model.ContentPage;

			var pageContents = cmsHelper.cmsAdminContent;

			pageContents.GoLiveDate = page.GoLiveDate;
			pageContents.RetireDate = page.RetireDate;

			pageContents.IsLatestVersion = true;
			pageContents.Thumbnail = page.Thumbnail;

			pageContents.TitleBar = page.TitleBar;
			pageContents.NavMenuText = page.NavMenuText;
			pageContents.PageHead = page.PageHead;
			pageContents.PageSlug = null;

			pageContents.MetaDescription = page.MetaDescription;
			pageContents.MetaKeyword = page.MetaKeyword;

			pageContents.EditDate = SiteData.CurrentSite.Now;
			pageContents.NavOrder = page.NavOrder;

			pageContents.PageActive = page.PageActive;
			pageContents.ShowInSiteNav = page.ShowInSiteNav;
			pageContents.ShowInSiteMap = page.ShowInSiteMap;
			pageContents.BlockIndex = page.BlockIndex;

			pageContents.CreditUserId = page.CreditUserId;

			pageContents.EditUserId = SecurityData.CurrentUserGuid;

			model.SetPage(pageContents);

			Helper.ForceValidation(ModelState, model);

			if (ModelState.IsValid) {
				cmsHelper.cmsAdminContent = pageContents;
				SetSaved();
				return RedirectToAction("PageEdit", new { @id = model.ContentPage.Root_ContentID });
			}

			Helper.HandleErrorDict(ModelState);

			return View(model);
		}
		public ActionResult BlogPostAddEdit(ContentPageModel model) {
			Helper.ForceValidation(ModelState, model);

			model.Mode = (String.IsNullOrEmpty(model.Mode) || model.Mode.Trim().ToLower() != "raw") ? "html" : "raw";
			ViewBag.ContentEditMode = model.Mode;

			if (ModelState.IsValid) {
				ContentPage page = model.ContentPage;

				var pageContents = pageHelper.FindContentByID(this.SiteID, page.Root_ContentID);
				if (pageContents == null) {
					pageContents = new ContentPage(this.SiteID, ContentPageType.PageType.BlogEntry);
				}

				pageContents.GoLiveDate = page.GoLiveDate;
				pageContents.RetireDate = page.RetireDate;

				pageContents.IsLatestVersion = true;
				pageContents.Thumbnail = page.Thumbnail;

				pageContents.TemplateFile = page.TemplateFile;

				pageContents.TitleBar = page.TitleBar;
				pageContents.NavMenuText = page.NavMenuText;
				pageContents.PageHead = page.PageHead;
				pageContents.FileName = page.FileName;
				pageContents.PageSlug = page.PageSlug;

				pageContents.MetaDescription = page.MetaDescription;
				pageContents.MetaKeyword = page.MetaKeyword;

				pageContents.EditDate = SiteData.CurrentSite.Now;
				pageContents.NavOrder = SiteData.BlogSortOrderNumber;

				pageContents.PageText = page.PageText;
				pageContents.LeftPageText = page.LeftPageText;
				pageContents.RightPageText = page.RightPageText;

				pageContents.PageActive = page.PageActive;
				pageContents.ShowInSiteNav = false;
				pageContents.ShowInSiteMap = false;
				pageContents.BlockIndex = page.BlockIndex;

				pageContents.Parent_ContentID = page.Parent_ContentID;

				pageContents.CreditUserId = page.CreditUserId;

				pageContents.EditUserId = SecurityData.CurrentUserGuid;

				List<ContentCategory> lstCat = new List<ContentCategory>();
				List<ContentTag> lstTag = new List<ContentTag>();

				//lstCat = (from cr in model.CategoryOptions
				//		  join l in SiteData.CurrentSite.GetCategoryList() on cr.Value equals l.ContentCategoryID.ToString()
				//		  where cr.Selected
				//		  select l).ToList();
				//lstTag = (from cr in model.TagOptions
				//		  join l in SiteData.CurrentSite.GetTagList() on cr.Value equals l.ContentTagID.ToString()
				//		  where cr.Selected
				//		  select l).ToList();

				lstCat = (from l in SiteData.CurrentSite.GetCategoryList()
						  join cr in model.SelectedCategories on l.ContentCategoryID.ToString().ToLower() equals cr.ToLower()
						  select l).ToList();
				lstTag = (from l in SiteData.CurrentSite.GetTagList()
						  join cr in model.SelectedTags on l.ContentTagID.ToString().ToLower() equals cr.ToLower()
						  select l).ToList();

				pageContents.ContentCategories = lstCat;
				pageContents.ContentTags = lstTag;

				pageContents.SavePageEdit();

				if (model.VisitPage) {
					Response.Redirect(pageContents.FileName);
				} else {
					return RedirectToAction("BlogPostAddEdit", new { @id = pageContents.Root_ContentID, @mode = model.Mode });
				}
			}

			Helper.HandleErrorDict(ModelState);

			return View(model);
		}
		public ActionResult BlogPostAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) {
			ContentPageModel model = new ContentPageModel();
			model.ImportID = importid;
			model.VersionID = versionid;
			model.Mode = (String.IsNullOrEmpty(mode) || mode.Trim().ToLower() != "raw") ? "html" : "raw";

			ContentPage pageContents = null;
			ViewBag.ContentEditMode = model.Mode;

			if (!id.HasValue && !versionid.HasValue && !importid.HasValue) {
				if (pageContents == null) {
					pageContents = new ContentPage(this.SiteID, ContentPageType.PageType.BlogEntry);
				}

				pageContents.Root_ContentID = Guid.Empty;
			} else {
				if (importid.HasValue) {
					ContentPageExport cpe = ContentImportExportUtils.GetSerializedContentPageExport(importid.Value);
					if (cpe != null) {
						pageContents = cpe.ThePage;
						pageContents.EditDate = SiteData.CurrentSite.Now;

						var rp = pageHelper.GetLatestContentByURL(this.SiteID, false, pageContents.FileName);
						if (rp != null) {
							pageContents.Root_ContentID = rp.Root_ContentID;
							pageContents.ContentID = rp.ContentID;
						} else {
							pageContents.Root_ContentID = Guid.Empty;
							pageContents.ContentID = Guid.Empty;
						}
						pageContents.Parent_ContentID = null;
						pageContents.NavOrder = SiteData.BlogSortOrderNumber;
					}
				}
				if (versionid.HasValue) {
					pageContents = pageHelper.GetVersion(this.SiteID, versionid.Value);
				}
				if (id.HasValue && pageContents == null) {
					pageContents = pageHelper.FindContentByID(this.SiteID, id.Value);
				}
			}

			model.SetPage(pageContents);

			return View(model);
		}
		public ActionResult PageAddEdit(ContentPageModel model) {
			Helper.ForceValidation(ModelState, model);

			model.Mode = (String.IsNullOrEmpty(model.Mode) || model.Mode.Trim().ToLower() != "raw") ? "html" : "raw";
			ViewBag.ContentEditMode = model.Mode;

			if (ModelState.IsValid) {
				ContentPage page = model.ContentPage;

				var pageContents = pageHelper.FindContentByID(this.SiteID, page.Root_ContentID);
				if (pageContents == null) {
					pageContents = new ContentPage(this.SiteID, ContentPageType.PageType.ContentEntry);
				}

				pageContents.GoLiveDate = page.GoLiveDate;
				pageContents.RetireDate = page.RetireDate;

				pageContents.IsLatestVersion = true;
				pageContents.Thumbnail = page.Thumbnail;

				pageContents.TemplateFile = page.TemplateFile;

				pageContents.TitleBar = page.TitleBar;
				pageContents.NavMenuText = page.NavMenuText;
				pageContents.PageHead = page.PageHead;
				pageContents.FileName = page.FileName;
				pageContents.PageSlug = null;

				pageContents.MetaDescription = page.MetaDescription;
				pageContents.MetaKeyword = page.MetaKeyword;

				pageContents.EditDate = SiteData.CurrentSite.Now;
				pageContents.NavOrder = page.NavOrder;

				pageContents.PageText = page.PageText;
				pageContents.LeftPageText = page.LeftPageText;
				pageContents.RightPageText = page.RightPageText;

				pageContents.PageActive = page.PageActive;
				pageContents.ShowInSiteNav = page.ShowInSiteNav;
				pageContents.ShowInSiteMap = page.ShowInSiteMap;
				pageContents.BlockIndex = page.BlockIndex;

				pageContents.Parent_ContentID = page.Parent_ContentID;

				pageContents.CreditUserId = page.CreditUserId;

				pageContents.EditUserId = SecurityData.CurrentUserGuid;

				pageContents.SavePageEdit();

				if (model.VisitPage) {
					Response.Redirect(pageContents.FileName);
				} else {
					return RedirectToAction("PageAddEdit", new { @id = pageContents.Root_ContentID, @mode = model.Mode });
				}
			}

			Helper.HandleErrorDict(ModelState);

			return View(model);
		}
		public ActionResult BlogPostEdit(Guid id, bool? saved) {
			ContentPageModel model = new ContentPageModel();

			cmsHelper.OverrideKey(id);
			ContentPage pageContents = cmsHelper.cmsAdminContent;

			model.SetPage(pageContents);

			if (saved.HasValue && saved.Value) {
				ShowSave();
			}

			return View(model);
		}
		public ActionResult PageAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) {
			ContentPageModel model = new ContentPageModel();
			model.ImportID = importid;
			model.VersionID = versionid;
			model.Mode = (String.IsNullOrEmpty(mode) || mode.Trim().ToLower() != "raw") ? "html" : "raw";

			ContentPage pageContents = null;
			ViewBag.ContentEditMode = model.Mode;

			if (!id.HasValue && !versionid.HasValue && !importid.HasValue) {
				if (pageContents == null) {
					pageContents = new ContentPage(this.SiteID, ContentPageType.PageType.ContentEntry);
				}

				pageContents.Root_ContentID = Guid.Empty;
			} else {
				if (importid.HasValue) {
					ContentPageExport cpe = ContentImportExportUtils.GetSerializedContentPageExport(importid.Value);
					if (cpe != null) {
						pageContents = cpe.ThePage;
						pageContents.EditDate = SiteData.CurrentSite.Now;
						pageContents.Parent_ContentID = null;
						var rp = pageHelper.GetLatestContentByURL(this.SiteID, false, pageContents.FileName);
						if (rp != null) {
							pageContents.Root_ContentID = rp.Root_ContentID;
							pageContents.ContentID = rp.ContentID;
							pageContents.Parent_ContentID = rp.Parent_ContentID;
							pageContents.NavOrder = rp.NavOrder;
						} else {
							pageContents.Root_ContentID = Guid.Empty;
							pageContents.ContentID = Guid.Empty;
							pageContents.NavOrder = pageHelper.GetSitePageCount(this.SiteID, ContentPageType.PageType.ContentEntry);
						}
					}
				}
				if (versionid.HasValue) {
					pageContents = pageHelper.GetVersion(this.SiteID, versionid.Value);
				}
				if (id.HasValue && pageContents == null) {
					pageContents = pageHelper.FindContentByID(this.SiteID, id.Value);
				}
			}

			if (pageContents.ContentType != ContentPageType.PageType.ContentEntry) {
				return RedirectToAction("BlogPostAddEdit", new { @id = pageContents.Root_ContentID, @mode = model.Mode });
			}

			cmsHelper.OverrideKey(pageContents.Root_ContentID);
			cmsHelper.cmsAdminContent = pageContents;
			cmsHelper.cmsAdminWidget = pageContents.GetWidgetList();

			model.SetPage(pageContents);

			return View(model);
		}