Exemplo n.º 1
0
        public ActionResult Edit(StoreItem storeItem, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                // allowed file extensions
                string[] fileExt = { ".png", ".jpg", ".gif", ".jpeg" };

                foreach (var fileBase in files)
                {
                    // save the background image
                    if (fileBase != null && fileBase.ContentLength > 0)
                    {
                        try
                        {
                            // make sure that the file extension is among the allowed
                            if (Array.IndexOf(fileExt, Path.GetExtension(fileBase.FileName.ToLower())) < 0)
                            {
                                throw new Exception(String.Format("File extension not allowed. Only these files are allowed:<br><br>{0}", string.Join(", ", fileExt)));
                            }

                            var fileName = Path.GetFileName(fileBase.FileName);

                            // fix bug that iPad/iPhone names all the files "image.jpg"
                            if (fileName == "image.jpg")
                            {
                                fileName = String.Format("{0}{1}", CustomHelpers.GeneratePassword(6), Path.GetExtension(fileBase.FileName.ToLower()));
                            }

                            var path = Server.MapPath("~/Images/Store/");

                            // instantiate object
                            var image = new CircuitBentCMS.Models.StoreItemImage();
                            image.ImageUrl    = fileName;
                            image.StoreItemId = storeItem.StoreItemId;

                            context.StoreItemImages.Add(image);

                            fileBase.SaveAs(Path.Combine(path, fileName));

                            ImageBuilder.Current.Build(Path.Combine(path, fileName), Path.Combine(path, "thumb_" + fileName), new ResizeSettings("maxwidth=240&maxheight=240&crop=auto"));
                        }
                        catch (Exception e)
                        {
                            TempData["ErrorMessage"] = e.Message;
                        }
                    }
                }

                context.Entry(storeItem).State = EntityState.Modified;
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "The changes were saved successfully!";

                return(RedirectToAction("Edit", new { id = storeItem.StoreItemId }));
            }
            return(View(storeItem));
        }
Exemplo n.º 2
0
        public ActionResult Edit(Show show)
        {
            if (ModelState.IsValid)
            {
                context.Entry(show).State = EntityState.Modified;
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "The changes were saved successfully!";

                return(RedirectToAction("Index"));
            }
            return(View(show));
        }
Exemplo n.º 3
0
        public ActionResult Edit(ImageSliderImage image)
        {
            if (ModelState.IsValid)
            {
                context.Entry(image).State = EntityState.Modified;
                context.SaveChanges();

                TempData["StatusMessage"] = "Changes saved successfully!";

                return(RedirectToAction("Index"));
            }

            return(View(image));
        }
Exemplo n.º 4
0
        public ActionResult Edit(Blog blog)
        {
            if (ModelState.IsValid)
            {
                context.Entry(blog).State = EntityState.Modified;
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "The changes were saved successfully!";

                return(RedirectToAction("Edit", new { id = blog.BlogId }));
            }
            return(View(blog));
        }
Exemplo n.º 5
0
        public ActionResult Edit(MailSettings mailsettings)
        {
            if (ModelState.IsValid)
            {
                context.Entry(mailsettings).State = EntityState.Modified;
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"]   = "The changes were saved successfully!<br /><br />If you have changed the e-mail settings it is highly recommended to try the contact form to make sure it works.";
                TempData["MessageDuration"] = 6000;

                return(RedirectToAction("Index"));
            }
            return(View(mailsettings));
        }
Exemplo n.º 6
0
        public ActionResult Edit(HttpPostedFileBase Favicon)
        {
            var siteSettings = context.SiteSettings.FirstOrDefault();

            siteSettings.Title           = Request.Form["Title"];
            siteSettings.MetaDescription = Request.Form["MetaDescription"];
            siteSettings.FooterText      = Request.Form["FooterText"];
            siteSettings.GoogleAnalytics = Request.Form["GoogleAnalytics"];

            context.Entry(siteSettings).State = EntityState.Modified;
            context.SaveChanges();

            // display a friendly success message
            TempData["StatusMessage"] = "The changes were saved successfully!";

            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public ActionResult Edit(Page page, HttpPostedFileBase socialImage)
        {
            var path = Server.MapPath("~/Images/PageImages");

            if (ModelState.IsValid)
            {
                page.LastUpdated = DateTime.Now;

                // allowed file extensions
                string[] fileExt = { ".png", ".jpg", ".gif", ".jpeg" };

                // save the social media image
                if (socialImage != null && socialImage.ContentLength > 0)
                {
                    try
                    {
                        // make sure that the file extension is among the allowed
                        if (Array.IndexOf(fileExt, Path.GetExtension(socialImage.FileName.ToLower())) < 0)
                        {
                            throw new Exception("Social media image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                        }

                        // delete the current image
                        if (!String.IsNullOrEmpty(page.SocialMediaImage))
                        {
                            if (System.IO.File.Exists(Path.Combine(path, page.SocialMediaImage)))
                            {
                                System.IO.File.Delete(Path.Combine(path, page.SocialMediaImage));
                            }
                        }


                        page.SocialMediaImage = CustomHelpers.RemoveSwedishChars(socialImage.FileName);
                        socialImage.SaveAs(Path.Combine(Server.MapPath("~/Images/PageImages"), CustomHelpers.RemoveSwedishChars(socialImage.FileName)));
                    }
                    catch (Exception e)
                    {
                        TempData["ErrorMessage"] = e.Message;
                    }
                }

                // update the page
                context.Entry(page).State = EntityState.Modified;
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "The changes were saved successfully!";

                // if the user added a special page, redirect back to index
                // this is because there isn't really much to continue editing except the title
                if (!String.IsNullOrEmpty(page.CustomPage))
                {
                    return(RedirectToAction("Index"));
                }

                // redirect to the same edit page in case the user wants to make more changes
                if (!String.IsNullOrEmpty(Request.QueryString["scripts"]))
                {
                    return(RedirectToAction("Edit", new { id = page.PageId, scripts = "true" }));
                }

                return(RedirectToAction("Edit", new { id = page.PageId }));
            }


            // ModelState not valid
            return(View(page));
        }
Exemplo n.º 8
0
        public ActionResult Edit(HttpPostedFileBase BackgroundImage, HttpPostedFileBase HeaderImage, HttpPostedFileBase FooterImage, HttpPostedFileBase MobileImage, HttpPostedFileBase Favicon)
        {
            // allowed file extensions
            string[] fileExt = { ".png", ".jpg", ".gif", ".jpeg", ".ico" };

            // get the site settings
            var siteSettings = context.SiteSettings.FirstOrDefault();

            // populate from form values
            siteSettings.BackgroundColor = Request.Form["background-color"];
            siteSettings.ContainerColor  = Request.Form["container-color"];
            siteSettings.ContainerWidth  = Convert.ToInt32(Request.Form["container-width"]);

            // set container opacity, and check that the values are between 0 - 100
            int containerOpacity = Convert.ToInt32(Request.Form["ContainerOpacity"]);

            if (containerOpacity > 100)
            {
                siteSettings.ContainerOpacity = 100;
            }
            else if (containerOpacity < 0)
            {
                siteSettings.ContainerOpacity = 0;
            }
            else
            {
                siteSettings.ContainerOpacity = containerOpacity;
            }

            siteSettings.HeadingColor = Request.Form["heading-color"];
            siteSettings.TextColor    = Request.Form["text-color"];
            siteSettings.LinkColor    = Request.Form["link-color"];

            siteSettings.HeadingFont = Request.Form["heading-font"];
            siteSettings.HeadingSize = Request.Form["heading-size"];
            siteSettings.TextFont    = Request.Form["text-font"];
            siteSettings.TextSize    = Request.Form["text-size"];

            //siteSettings.BackgroundImageFullScreen = false;

            if (String.IsNullOrEmpty(Request.Form["BackgroundImageFullScreen"]))
            {
                siteSettings.BackgroundImageFullScreen = false;
            }
            else
            {
                siteSettings.BackgroundImageFullScreen = true;
            }


            // save the background image
            if (BackgroundImage != null && BackgroundImage.ContentLength > 0)
            {
                try
                {
                    // make sure that the file extension is among the allowed
                    if (Array.IndexOf(fileExt, Path.GetExtension(BackgroundImage.FileName.ToLower())) < 0)
                    {
                        throw new Exception("Background image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                    }

                    // delete the existing background image
                    DeleteImage("background");

                    var path = Path.Combine(Server.MapPath("~/Images/PageSettings"), BackgroundImage.FileName);
                    siteSettings.BackgroundImage = BackgroundImage.FileName;
                    BackgroundImage.SaveAs(path);
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = e.Message;
                }
            }

            // save the header image
            if (HeaderImage != null && HeaderImage.ContentLength > 0)
            {
                try
                {
                    // make sure that the file extension is among the allowed
                    if (Array.IndexOf(fileExt, Path.GetExtension(HeaderImage.FileName.ToLower())) < 0)
                    {
                        throw new Exception("Header image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                    }

                    // delete the existing header image
                    DeleteImage("header");

                    var path = Path.Combine(Server.MapPath("~/Images/PageSettings"), HeaderImage.FileName);
                    siteSettings.HeaderImage = HeaderImage.FileName;
                    HeaderImage.SaveAs(path);
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = e.Message;
                }
            }

            // save the footer image
            if (FooterImage != null && FooterImage.ContentLength > 0)
            {
                try
                {
                    // make sure that the file extension is among the allowed
                    if (Array.IndexOf(fileExt, Path.GetExtension(FooterImage.FileName.ToLower())) < 0)
                    {
                        throw new Exception("Footer image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                    }

                    // delete the existing footer image
                    DeleteImage("footer");

                    var path = Path.Combine(Server.MapPath("~/Images/PageSettings"), FooterImage.FileName);
                    siteSettings.FooterImage = FooterImage.FileName;
                    FooterImage.SaveAs(path);
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = e.Message;
                }
            }

            // save the mobile image
            if (MobileImage != null && MobileImage.ContentLength > 0)
            {
                try
                {
                    // make sure that the file extension is among the allowed
                    if (Array.IndexOf(fileExt, Path.GetExtension(MobileImage.FileName.ToLower())) < 0)
                    {
                        throw new Exception("Mobile image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                    }

                    // delete the existing footer image
                    DeleteImage("mobile");

                    var path = Path.Combine(Server.MapPath("~/Images/PageSettings"), MobileImage.FileName);
                    siteSettings.MobileImage = MobileImage.FileName;
                    MobileImage.SaveAs(path);
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = e.Message;
                }
            }

            // save the favicon image
            if (Favicon != null && Favicon.ContentLength > 0)
            {
                try
                {
                    // make sure that the file extension is among the allowed
                    if (Array.IndexOf(fileExt, Path.GetExtension(Favicon.FileName.ToLower())) < 0)
                    {
                        throw new Exception("Favicon was in an unsupported format. Only images (JPEG, GIF, PNG, ICO) allowed.");
                    }

                    // delete the existing footer image
                    DeleteImage("favicon");

                    var path = Path.Combine(Server.MapPath("~/Images/PageSettings"), Favicon.FileName);
                    siteSettings.Favicon = Favicon.FileName;
                    Favicon.SaveAs(path);
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = e.Message;
                }
            }

            context.Entry(siteSettings).State = EntityState.Modified;
            context.SaveChanges();

            TempData["StatusMessage"] = "Changes saved successfully!";

            return(RedirectToAction("Index"));
        }