Example #1
0
    /*     /// <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();
        }
    }
Example #2
0
    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;
           }
    }
Example #3
0
    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);
        }
    }
Example #4
0
    /*     /// <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();
           }
    }