Exemple #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);
        }
Exemple #2
0
        public string DeleteUser(string email)
        {
            User user = (User)HttpContext.Current.Session["user"];

            if (user.Status == 2)
            {
                ContentManagementSystem.DeleteUser(email);
            }
            return("OK");
        }
Exemple #3
0
        public string UpdateUser(string first, string last, string email, string code, bool approved, int status, string price)
        {
            User user = (User)HttpContext.Current.Session["user"];

            if (user == null)
            {
                return("unauthorised user");
            }
            if (user.Status == 2)
            {
                try
                {
                    ContentManagementSystem.UpdateUser(first, last, email, code, approved, status, price);
                }
                catch (Exception exception)
                {
                    return(exception.Message);
                }
            }
            return("OK");
        }
Exemple #4
0
        public string Register(string email, string password, string first, string last)
        {
            User user = ContentManagementSystem.FindUser(email, password);

            if (user != null)
            {
                return("user already exists.");
            }
            else
            {
                if (ContentManagementSystem.AddUser(first, last, email, password))
                {
                    try                                              // to subscribe them to mail chimp
                    {
                        MailChimp.ListSubscribe(email, first, last); // try to subscribe them
                    }
                    catch
                    {
                        //
                    }

                    try  // to send out emails that they have subscribed
                    {
                        Email.TellAdministratorAboutNewUser(first, last, email);
                    }
                    catch
                    {
                        //
                    }

                    return("OK");
                }
                else
                {
                    return("unable to register user.");
                }
            }
        }
Exemple #5
0
        public string Authenticate(string email, string password)
        {
            User user = ContentManagementSystem.FindUser(email, password);

            if (user != null)
            {
                if (user.Approved)
                {
                    HttpContext.Current.Session["user"] = user;
                    return("OK");
                }
                else
                {
                    HttpContext.Current.Session["authenticated"] = false;
                    return("not yet approved.");
                }
            }
            else
            {
                HttpContext.Current.Session["authenticated"] = false;
                return("unknown user.");
            }
        }
Exemple #6
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);
            }
        }