protected void GetArticleOfDay() { content MyArticle = new content(); if (object.Equals(Session["ArticleOfDay"], null)) { List <int> MyList = App_Code.ContentService.GetContentIDList("EN"); int AODCount = MyList.Count(); int AODMax = AODCount; int rand = App_Code.RALTService.GetRandomNumber(0, AODMax); int MyContentID = MyList[rand]; MyArticle = App_Code.ContentService.GetRandomContent(MyContentID, "EN"); Session["ArticleOfDay"] = MyArticle; } else { MyArticle = (content)Session["ArticleOfDay"]; } contentmarkup LatestVersion = new contentmarkup(); LatestVersion = MyArticle.contentmarkups.FirstOrDefault <contentmarkup>(); ArticleImage.ImageUrl = MyArticle.image_url; ArticleTitleLink.Text = MyArticle.title.Replace("-", " "); ArticleImageLink.NavigateUrl = "/" + MyArticle.category + "/" + "EN" + "/" + MyArticle.title; ArticleTitleLink.NavigateUrl = "/" + MyArticle.category + "/" + "EN" + "/" + MyArticle.title; }
protected void AdministratorChangeLanguage() { try { string Content = ContentPlaceHolder.InnerHtml; //Retrieve ContentName from Session string ContentTitle = (string)ViewState["ContentTitle"]; //Get Content Data content MyContent = new content(); MyContent = App_Code.ContentService.GetObjectByTitle(ContentTitle); //Store Selected Language string SelectedLanguage = ddlContentLanguage.SelectedValue; //get Versions of this language if any int NumberOfVersions = App_Code.ContentService.GetMarkupByLanguage(MyContent.content_id, SelectedLanguage).Count(); //Check for versions if (NumberOfVersions > 0) { //Load page for this language Response.Redirect("/" + MyContent.category + "/" + SelectedLanguage + "/" + ContentTitle); } else { //Create this content in the selected language contentmarkup MyMarkup = new contentmarkup(); MyMarkup.content_id = MyContent.content_id; MyMarkup.language = SelectedLanguage; MyMarkup.description = txtContentDescription.Text; MyMarkup.markup = Content.Replace("ContentSection editable", "ContentSection"); App_Code.ContentService.SaveContent(MyMarkup); //Redirect to new language Response.Redirect("/" + MyContent.category + "/" + SelectedLanguage + "/" + ContentTitle); } } catch (Exception ex) { //Error App_Code.NotificationService.SendNotification("LanguageChangeError", ex.Message, "error"); } }
protected void ChangeVersion() { try { int VersionNumber = Convert.ToInt32(ddlContentVersion.SelectedValue); contentmarkup MyPageContent = App_Code.ContentService.GetContentVersionById(VersionNumber); string ContentTitle = (string)ViewState["ContentTitle"]; //Get the Content data from DB content MyContent = new content(); MyContent = App_Code.ContentService.GetObjectByTitle(ContentTitle); BindPage(MyContent, MyPageContent); } catch (Exception ex) { //Loading Content Error App_Code.NotificationService.SendNotification("ContentError", ex.Message, "error"); } }
protected void btnNewContent_Click(object sender, EventArgs e) { //Server Validate Page.Validate("NewContent"); //If valid if (Page.IsValid) { try { //Define new Content content MyContent = new content(); //Retrieve ContentFormData string ContentTitle = txtContentTitle.Text; string ContentCategory = ddlContentCategory.SelectedValue; string contentLanguage = ddlContentLanguage.SelectedValue; string ContentDescription; string ImageURL = txtPictureURL.Text; //Set Description if null if (!string.IsNullOrEmpty(txtContentDescription.Text)) { ContentDescription = txtContentDescription.Text; } else { ContentDescription = "Your Description Here"; } //HTML Content Bubbles //string Header = "<div class=\"ContentSection\"><div class=\"ContentSectionHeader\"><div class=\"ContentSectionHeaderText\">" + ContentTitle + "</div></div><div class=\"ContentSectionContent\"><div class=\"Content\"><div style=\"float:left;\"><div class=\"ContentTitleImage\"><a href=\"/" + ContentCategory + "/"+ contentLanguage +"/" + ContentTitle + "\"><img src=\"/Images/LogoBlack.png\" class=\"center\"></a></div><div class=\"ContentTitletext\"><p>" + ContentDescription + "</p></div></div></div></div></div>"; string Content = "<div class=\"ContentSection\"><div class=\"ContentSectionHeader\"><div class=\"ContentSectionHeaderText\">" + "Header" + "</div></div><div class=\"ContentSectionContent\"><div class=\"Content\"><p>Content Here</p></div></div></div>"; //Get the logged in User if any MembershipUser LoggedInMembershipUser; LoggedInMembershipUser = Membership.GetUser(); //Check if there is a logged in User if (LoggedInMembershipUser != null) { //RALT Data // ToInt32 can throw FormatException or OverflowException. int UserId = -1; //Get the RALT data from membership accountID UserId = Convert.ToInt32(LoggedInMembershipUser.ProviderUserKey.ToString()); user UserData = UserService.GetUserByMemberId(UserId); //Update data MyContent.author_user_id = UserData.user_id; } //Update Data MyContent.title = ContentTitle; MyContent.category = ContentCategory; MyContent.image_url = ImageURL; //Save Content int MyContentID = App_Code.ContentService.SaveObject(MyContent); contentmarkup MyMarkup = new contentmarkup(); MyMarkup.content_id = MyContentID; MyMarkup.language = contentLanguage; MyMarkup.description = ContentDescription; // MyMarkup.header_markup = Header; MyMarkup.markup = Content; App_Code.ContentService.SaveContent(MyMarkup); Response.Redirect("/" + ContentCategory + "/" + contentLanguage + "/" + ContentTitle); } catch (Exception ex) { //Loading Content Error App_Code.NotificationService.SendNotification("ContentSaveError", ex.Message, "error"); } } }
protected void SavePage() { try { //Retrieve ContentName from view state string ContentTitle = (string)ViewState["ContentTitle"]; string Language = (string)ViewState["Language"]; //Get Content Data content MyContent = new content(); MyContent = App_Code.ContentService.GetObjectByTitle(ContentTitle); //Create a new contentmarkup(new version) contentmarkup MyPageContent = new contentmarkup(); //Check if the content is dirty(changed) if (IsDirty()) { List <contentmarkup> PublishedList = App_Code.ContentService.GetPublishedMarkupByLanguage(MyContent.content_id, Language); foreach (contentmarkup m in PublishedList) { m.published = false; App_Code.ContentService.SaveContent(m); } //get all the page data string Content = HFContentReturn.Value; MyPageContent.content_id = MyContent.content_id; MyPageContent.language = Language; MyPageContent.published = chkPublished.Checked; MyPageContent.description = txtContentDescription.Text; //Remove editable fields for storage MyPageContent.markup = Content.Replace("ContentSection editable", "ContentSection"); //Save App_Code.ContentService.SaveContent(MyPageContent); string Currentpath = HttpContext.Current.Request.Url.AbsolutePath; Response.Redirect(Currentpath + "?MSG=SaveSuccess"); ////Update Control Data //HFContentControl.Value = Content; //HFPublishedControl.Value = MyPageContent.published.ToString(); //ContentPlaceHolder.InnerHtml = Content; ////BindVersions //List<contentmarkup> ThisLanguageVersions = App_Code.ContentService.GetMarkupByLanguage(MyContent.content_id, Language); ////GetCurrent Version //contentmarkup CurrentVersion = ThisLanguageVersions.Last<contentmarkup>(); ////BindVersionsDDL //BindVersionControl(ThisLanguageVersions, Convert.ToString(CurrentVersion.contentmarkup_id)); //App_Code.NotificationService.SendNotification("SaveSuccess", "The page was updated successfully!", "success", "3000"); } else { App_Code.NotificationService.SendNotification("SaveRedundent", "There are no changes detected and the page was not saved.", "alert", "3000"); } //Invoke the script to change server controsl to html page data ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "EditorTools", "ToggleEditorTools();", true); } catch (Exception ex) { //Loading Content Error //App_Code.NotificationService.SendNotification("ContentSaveError", ex.Message, "error"); throw ex; } }
protected void Page_Init(object sender, EventArgs e) { //First Time Load if (!Page.IsPostBack) { try { // PrincipalPolicy must be set to WindowsPrincipal to check roles. AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); //Get the ContentName from URL Data (psuedo queryString) string ContentTitle = Page.RouteData.Values["Title"] as string; string Language = Page.RouteData.Values["Language"] as string; //If content variables are correct if (ContentTitle != null && Language != null) { //Set the page Title Page.Header.Title = ContentTitle; //Get the Content data from DB content MyContent = new content(); MyContent = App_Code.ContentService.GetObjectByTitle(ContentTitle); //BindVersions List <contentmarkup> ThisLanguageVersions = App_Code.ContentService.GetMarkupByLanguage(MyContent.content_id, Language); //GetCurrent Version contentmarkup CurrentVersion = ThisLanguageVersions.Last <contentmarkup>(); HFEditor.Value = "false"; //Check for editing roles var AdminRole = User.IsInRole("Administrators"); var EditorRole = User.IsInRole("Editors"); if ((AdminRole) || (EditorRole)) { //BindVersionsDDL BindVersionControl(ThisLanguageVersions, Convert.ToString(CurrentVersion.contentmarkup_id)); //Bind LanguagesDDL BindLanguages(Language); HFEditor.Value = "true"; } //Bind the Page BindPage(MyContent, CurrentVersion); } else { //The content was not found, redirect to error404 Response.Redirect("/Error404"); } } catch (Exception ex) { //Loading Content Error App_Code.NotificationService.SendNotification("ContentError", "We are sorry there was an error loading this page. Please try again, or try another page. Thank you.", "error"); } } }
protected void BindPage(content MyContent, contentmarkup MyPageContent) { if (!object.ReferenceEquals(MyPageContent, null)) { //Get Author Data user MyContentAuthor = new user(); MyContentAuthor = UserService.GetUserById((int)MyContent.author_user_id); string Content = MyPageContent.markup; var AdminRole = User.IsInRole("Administrators"); var EditorRole = User.IsInRole("Editors"); if ((AdminRole) || (EditorRole)) { //Make content editable Content = Content.Replace("class=\"ContentSection\">", "class=\"ContentSection editable\">"); Content = Content.Replace("class=\"ContentSection\" style", "class=\"ContentSection editable\" style"); //Set Control data HFContentControl.Value = Content; //Set Control data //HFContentControl.Value = this.ContentPlaceHolder.InnerHtml; HFPublishedControl.Value = MyPageContent.published.ToString(); HFDescription.Value = MyPageContent.description; //MakeS ortable Content = @" <ul id=""sortable"">" + Content + @"<div id=""final""></div></ul>"; //Show editor tools on page ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "EditorTools", "ToggleEditorTools();", true); } else { //Ensure the page is not editable Content = Content.Replace("ContentSection editable", "ContentSection"); //If the content is not published, redirect to page unavialble if (!MyPageContent.published) { Response.Redirect("/Error404"); } } //Set Page Date HFContentId.Value = MyContent.content_id.ToString(); HFLanguage.Value = MyPageContent.language; HFCategory.Value = MyContent.category; chkPublished.Checked = (Boolean)MyPageContent.published; HFAuthor.Value = MyContentAuthor.first_name + " " + MyContentAuthor.last_name; HFAuthorEmail.Value = "mailto:" + MyContentAuthor.email; HFImageURL.Value = MyContent.image_url; HFNavLink.Value = "/" + MyContent.category + "/" + MyPageContent.language + "/" + MyContent.title; HFPublishDate.Value = MyPageContent.time_stamp.ToLongDateString(); HFTitle.Value = MyContent.title.Replace("-", " "); txtContentDescription.Text = MyPageContent.description; //Envoke Tranfser from ServerControls to HTMLPlaceHolders //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "BindPage", "LoadPage();", true); //LiteralControl ContentPage = new LiteralControl(); // Content = Content.Replace("ContentSection editable", "ContentSection"); this.ContentPlaceHolder.InnerHtml = Content; } }