Ejemplo n.º 1
0
        void AccountGalleriesManage_Save(object sender, EventArgs e)
        {
            long galleryId = 0;
            string title = "";
            string description = "";
            bool edit = false;

            try
            {
                galleryId = long.Parse(core.Http.Form["id"]);
                title = core.Http.Form["title"];
                description = core.Http.Form["description"];
            }
            catch
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission. (0x01)");
                return;
            }

            if (core.Http.Form["mode"] == "edit")
            {
                edit = true;
            }

            string slug = Gallery.GetSlugFromTitle(title, "");

            if (!edit)
            {
                try
                {
                    Gallery parent;
                    if (galleryId > 0)
                    {
                        parent = new Gallery(core, Owner, galleryId);
                    }
                    else
                    {
                        parent = new Gallery(core, Owner);
                    }

                    if (parent.FullPath.Length + slug.Length + 1 < 192)
                    {
                        if (Gallery.Create(core, Owner, parent, title, ref slug, description) != null)
                        {
                            SetRedirectUri(BuildUri("galleries", parent.GalleryId));
                            core.Display.ShowMessage("Gallery Created", "You have successfully created a new gallery.");
                            return;
                        }
                        else
                        {
                            core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission. (0x02)");
                            return;
                        }
                    }
                    else
                    {
                        SetError("The gallery path you have given is too long. Try using a shorter name or less nesting.");
                        //Display.ShowMessage("Gallery Path Too Long", "The gallery path you have given is too long. Try using a shorter name or less nesting.");
                        return;
                    }
                }
                catch (GallerySlugNotUniqueException)
                {
                    SetError("You have tried to create a gallery with the same name of one that already exits. Please give the gallery a unique name.");
                    //Display.ShowMessage("Gallery with same name already exists", "You have tried to create a gallery with the same name of one that already exits. Go back and give the gallery a unique name.");
                    return;
                }
                catch (GallerySlugNotValidException)
                {
                    SetError("The name of the gallery you have created is invalid, please choose another name.");
                    //Display.ShowMessage("Gallery name invalid", "The name of the gallery you have created is invalid, please choose another name.");
                    return;
                }
                catch (Exception ex)
                {
                    core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission. (0x03) " + ex.ToString());
                    return;
                }
            }
            else
            {
                // save edit
                try
                {
                    Gallery gallery = new Gallery(core, Owner, galleryId);

                    try
                    {
                        if (gallery.ParentPath.Length + slug.Length + 1 < 192)
                        {
                            gallery.Update(core, title, slug, description);

                            SetRedirectUri(BuildUri("galleries", gallery.ParentId));
                            core.Display.ShowMessage("Gallery Edit Saved", "You have saved the edits to the gallery.");
                            return;
                        }
                        else
                        {
                            core.Display.ShowMessage("Gallery Path Too Long", "The gallery path you have given is too long. Try using a shorter name or less nesting.");
                            return;
                        }
                    }
                    catch (GallerySlugNotUniqueException)
                    {
                        core.Display.ShowMessage("Gallery with same name already exists", "You have tried to create a gallery with the same name of one that already exits. Go back and give the gallery a unique name.");
                        return;
                    }
                    catch (GallerySlugNotValidException)
                    {
                        core.Display.ShowMessage("Gallery name invalid", "The name of the gallery you have created is invalid, please choose another name.");
                        return;
                    }
                    catch (Exception ex)
                    {
                        core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission. (0x04) " + ex.ToString());
                        return;
                    }
                }
                catch
                {
                    core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission. (0x05)");
                    return;
                }
            }
        }
        void AccountGalleriesPhotoCover_Show(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long pictureId = core.Functions.RequestLong("id", 0);

            if (pictureId == 0)
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission. (0x07)");
                return;
            }

            // check the image exists
            // check the image is owned by the user trying to set it as their display picture
            try
            {
                GalleryItem ugi = new GalleryItem(core, Owner, pictureId);

                string galleryFullPath = ugi.ParentPath;
                int indexOfLastSlash = galleryFullPath.LastIndexOf('/');

                try
                {
                    Gallery gallery = new Gallery(core, Owner, galleryFullPath);

                    gallery.HighlightId = pictureId;
                    gallery.Update();

                    SetRedirectUri(Gallery.BuildGalleryUri(core, Owner, galleryFullPath));
                    core.Display.ShowMessage("Gallery Cover Image Changed", "You have successfully changed the cover image of the gallery.");
                    return;
                }
                catch (InvalidGalleryException)
                {
                    core.Display.ShowMessage("Cannot change gallery cover", "You could not change the gallery cover image to the selected image.");
                    return;
                }
                catch (UnauthorisedToUpdateItemException)
                {
                    core.Display.ShowMessage("Unauthorised", "You are unauthorised to complete this action.");
                    return;
                }
            }
            catch (GalleryItemNotFoundException)
            {
                core.Display.ShowMessage("Cannot change gallery cover", "You could not change the gallery cover image to the selected image.");
                return;
            }
        }