Example #1
0
        public void SavePage(string page, List <Content> contents, List <Image> images)
        {
            Node node = ContentManagementSystem.FindNodeByPage(page);

            if (node == null)
            {
                node      = new Node();
                node.Page = page;
            }


            for (int i = 0; i < contents.Count; i++)
            {
                contents[i].Node = node;
                Content content;
                if (i >= node.Contents.Count)
                {
                    content    = contents[i];
                    content.Id = 0;
                    node.Contents.Add(contents[i]);
                }
                else
                {
                    content          = node.Contents[i];
                    content.Position = contents[i].Position;
                    content.Node     = node;
                    content.Html     = contents[i].Html;
                    content.Id       = contents[i].Id;
                }

                ContentManagementSystem.SaveContent(content);
            }

            // Remove any images that the user has deleted
            for (int i = 0; i < node.Images.Count; i++)
            {
                int id = node.Images[i].Id;
                foreach (Image image in images)
                {
                    if (image.Id == id)
                    {
                        ContentManagementSystem.RemoveImage(image);
                    }
                }
            }


            // Remove any images that the user has deleted
            foreach (Image image in images)
            {
                ContentManagementSystem.SaveImage(image);
            }

            node.Images.Clear();
            node.Images.AddRange(images);
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Authorize();
            if (CurrentNode == null)
            {
                Response.Redirect("/404");
            }

            if (Request.Form.Count == 0)
            {
                return;
            }

            for (int i = 0; i < 2; i++)
            {
                Content content;
                if (i < CurrentNode.Contents.Count)
                {
                    content = CurrentNode.Contents[i];
                }
                else
                {
                    content      = new Content();
                    content.Node = CurrentNode;
                }
                content.Position = i;
                string contentId = Request.Form["contentid" + i].ToString();
                content.Id   = int.Parse(contentId);
                content.Html = Request.Form["contenthtml" + i].ToString();
                Console.WriteLine(content.Html);
                ContentManagementSystem.SaveContent(content);
            }

            // Remove any images that the user has deleted
            int imagesCount = int.Parse(Request.Form["imagescount"].ToString());

            foreach (Image image in CurrentNode.Images)
            {
                bool found = false;

                for (int i = 0; i < imagesCount; i++)
                {
                    int id = int.Parse(Request.Form["imageid" + i].ToString());
                    if (image.Id == id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    ContentManagementSystem.RemoveImage(image);
                }
            }


            // Add in the new images
            node.Images.Clear();
            for (int i = 0; i < imagesCount; i++)
            {
                Image image = new Image();
                image.Node = CurrentNode;
                string imageId = Request.Form["imageid" + i].ToString();
                image.Id  = int.Parse(imageId);
                image.Url = Request.Form["imageurl" + i].ToString();
                ContentManagementSystem.SaveImage(image);

                node.Images.Add(image);
            }
        }