/* /// <summary> * /// Get ictPage objects for a list control * /// </summary> * /// <returns>Generic list of custom ictPage objects</returns> * public List<ListPage> GetListOfAllPages() * { * using (var context = new assignmentEntities()) * { * var pages = from p in context.ict_Page * orderby p.Title * select new ListPage { PageID = p.PageID, Title = p.Title }; * return pages.ToList(); * } * } * */ public void UpdatePageContentByID(int pageID, string Title, string Content) { using (var context = new assignmentEntities()) { ict_Page p = context.ict_Page.Single(h => h.PageID == pageID); p.Title = Title.Trim(); p.Content = Content.Trim(); p.DateCreated = DateTime.Now; p.DateModified = DateTime.Now; // p.URL = context.ict_Page.Single(q => q.ID == pageID).URL; context.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { // First load tasks if (!IsPostBack) { // Initialize the manager object manager = new AssignmentManager(); // Fetch the page ict_Page page = manager.GetPageByID(pageID); // Configure the page content editor and the user interface if (page != null) { litContent.Text = page.Content; editor.Text = litContent.Text; tbTitle.Text = page.Title; ViewState["PageTitle"] = page.Title; } else { litContent.Text = ""; editor.Text = litContent.Text; tbTitle.Text = ""; ViewState["PageTitle"] = ""; } } Page.Title = ViewState["PageTitle"] as string; // Author tasks if (Page.User.IsInRole("Author")) { // Show the editing control strip pnlControl.Visible = true; // Configure the visibility of the buttons to match the view/edit mode btnEdit.Visible = !pnlEdit.Visible; btnView.Visible = btnPageContent.Visible = btnMediaList.Visible = btnMediaUpload.Visible = pnlEdit.Visible; // Update the user interface lblStatus.Text = ""; // The following block will capture the intent of the editor's "save" icon // Clicking the icon in the CKEditor causes a postback // Therefore, we will check here to see if the content and title have changed // If yes, we will save the changes, and update the user interface string editorText = editor.Text; string literalText = litContent.Text; string textboxTitle = tbTitle.Text.Trim(); string viewstateTitle = ViewState["PageTitle"] as string; if ((editorText != literalText) | (textboxTitle != viewstateTitle)) { // Save the changes manager = new AssignmentManager(); manager.UpdatePageContentByID(pageID, textboxTitle, editorText); // Update the user interface Page.Title = textboxTitle; ViewState["PageTitle"] = textboxTitle; litContent.Text = editorText; lblStatus.Text = "Changes have been saved"; } } // Author tasks } // Page_Load
public bool CreateNewEditablePage(string name, string inFolder) { // This version does not permit overwrites // It could, if the UI had a check box to permit overwrite/replace // Then add a parameter to the method to handle and process it // This method depends upon the following: // editablepage.aspx in the ~/author folder // An entity named ictPage, with the properties referenced below // A "new page creator" web form, which calls this method // The web form that calls this method must have the // correctly-configured <location> block in Web.config // Clean up the arguments which were passed in name = name.Trim().ToLower(); // inFolder = inFolder.Trim().ToLower(); _app = System.Web.HttpContext.Current.ApplicationInstance; // Check whether file "name" already exists "inFolder"... // Create new proposed folder string folder = string.Format("{0}/{1}", _app.Server.MapPath("~/"), inFolder); // string folder = Path.Combine(_app.Server.MapPath("~/"), inFolder); // Create new proposed file names string newMarkup = Path.Combine(folder, name + ".aspx"); string newCsharp = Path.Combine(folder, name + ".aspx.cs"); if (File.Exists(newMarkup)) { return(false); } else { // Get references to the editablepage.aspx and .cs // Use the technique that you used in your Lab 3 code // to get access to the http context string markup = _app.Server.MapPath("~/author/editablepage.aspx"); string csharp = _app.Server.MapPath("~/author/editablepage.aspx.cs"); // Copy the editable page template files File.Copy(markup, newMarkup, true); File.Copy(csharp, newCsharp, true); // Open the text of the aspx page StreamReader sr = File.OpenText(newMarkup); string markupText = sr.ReadToEnd(); sr.Close(); // Change the CodeFile attribute in the Page directive to the new file name markupText = markupText.Replace("editablepage.aspx", name + ".aspx"); StreamWriter sw = File.CreateText(newMarkup); sw.Write(markupText); sw.Close(); // Create a new ictPage content item ict_Page page = null; using (var context = new assignmentEntities()) { page = new ict_Page(); page.DateCreated = DateTime.Now; page.DateModified = DateTime.Now; page.Title = "New page - " + name; page.Content = string.Format("<h3>New page - {0}</h3><p>New Page</p>", name); context.ict_Page.AddObject(page); context.SaveChanges(); } // Open the text of the C# code file sr = null; sr = File.OpenText(newCsharp); string csharpText = sr.ReadToEnd(); sr.Close(); // Change the placeholder "pageID" value csharpText = csharpText.Replace("pageID = 0", "pageID = " + page.PageID.ToString()); sw = null; sw = File.CreateText(newCsharp); sw.Write(csharpText); sw.Close(); return(true); } }
public bool CreateNewEditablePage(string name, string inFolder) { // This version does not permit overwrites // It could, if the UI had a check box to permit overwrite/replace // Then add a parameter to the method to handle and process it // This method depends upon the following: // editablepage.aspx in the ~/author folder // An entity named ictPage, with the properties referenced below // A "new page creator" web form, which calls this method // The web form that calls this method must have the // correctly-configured <location> block in Web.config // Clean up the arguments which were passed in name = name.Trim().ToLower(); // inFolder = inFolder.Trim().ToLower(); _app = System.Web.HttpContext.Current.ApplicationInstance; // Check whether file "name" already exists "inFolder"... // Create new proposed folder string folder = string.Format("{0}/{1}", _app.Server.MapPath("~/"), inFolder); // string folder = Path.Combine(_app.Server.MapPath("~/"), inFolder); // Create new proposed file names string newMarkup = Path.Combine(folder, name + ".aspx"); string newCsharp = Path.Combine(folder, name + ".aspx.cs"); if (File.Exists(newMarkup)) { return false; } else { // Get references to the editablepage.aspx and .cs // Use the technique that you used in your Lab 3 code // to get access to the http context string markup = _app.Server.MapPath("~/author/editablepage.aspx"); string csharp = _app.Server.MapPath("~/author/editablepage.aspx.cs"); // Copy the editable page template files File.Copy(markup, newMarkup, true); File.Copy(csharp, newCsharp, true); // Open the text of the aspx page StreamReader sr = File.OpenText(newMarkup); string markupText = sr.ReadToEnd(); sr.Close(); // Change the CodeFile attribute in the Page directive to the new file name markupText = markupText.Replace("editablepage.aspx", name + ".aspx"); StreamWriter sw = File.CreateText(newMarkup); sw.Write(markupText); sw.Close(); // Create a new ictPage content item ict_Page page = null; using (var context = new assignmentEntities()) { page = new ict_Page(); page.DateCreated = DateTime.Now; page.DateModified = DateTime.Now; page.Title = "New page - " + name; page.Content = string.Format("<h3>New page - {0}</h3><p>New Page</p>", name); context.ict_Page.AddObject(page); context.SaveChanges(); } // Open the text of the C# code file sr = null; sr = File.OpenText(newCsharp); string csharpText = sr.ReadToEnd(); sr.Close(); // Change the placeholder "pageID" value csharpText = csharpText.Replace("pageID = 0", "pageID = " + page.PageID.ToString()); sw = null; sw = File.CreateText(newCsharp); sw.Write(csharpText); sw.Close(); return true; } }