Exemplo n.º 1
0
        public ActionResult Create(Show show)
        {
            if (ModelState.IsValid)
            {
                context.Shows.Add(show);
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "Show added!";

                return(RedirectToAction("Index"));
            }

            return(View(show));
        }
Exemplo n.º 2
0
        public ActionResult Create(MailSettings mailsettings)
        {
            if (ModelState.IsValid)
            {
                context.MailSettings.Add(mailsettings);
                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.º 3
0
        public ActionResult Create(Blog blog)
        {
            blog.Date = DateTime.Now;

            if (ModelState.IsValid)
            {
                context.Blogs.Add(blog);
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "Blog post created successfully!";

                return(RedirectToAction("Edit", new { id = blog.BlogId }));
            }

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

                // display a friendly success message
                TempData["StatusMessage"] = "The changes were saved successfully!";
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
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.º 6
0
        public ActionResult Create(Page page, HttpPostedFileBase socialImage)
        {
            if (ModelState.IsValid)
            {
                page.LastUpdated = DateTime.Now;

                // perfor some basic verification that it is an int
                int subPageId = Convert.ToInt32(page.SubPageToPageId);

                // set the order by counting the current pages
                // also need to check if it's a main page or a sub page
                if (subPageId == 0)
                {
                    // update the order for the remaining pages
                    // this is because the order is not correct otherwise
                    var pages = context.Pages.Where(a => a.SubPageToPageId == 0).OrderBy(a => a.Order).ToList();
                    for (int i = 0; i < pages.Count; i++)
                    {
                        pages[i].Order = i + 1;
                    }

                    context.SaveChanges();

                    page.Order = context.Pages.Where(a => a.SubPageToPageId == 0).ToList().Count + 1;
                }
                else
                {
                    // update the order for the remaining pages
                    // this is because the order is not correct otherwise
                    var pages = context.Pages.Where(a => a.SubPageToPageId == subPageId).OrderBy(a => a.Order).ToList();
                    for (int i = 0; i < pages.Count; i++)
                    {
                        pages[i].Order = i + 1;
                    }

                    context.SaveChanges();

                    page.Order = context.Pages.Where(a => a.SubPageToPageId == subPageId).ToList().Count + 1;
                }

                // 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.");
                        }

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

                context.Pages.Add(page);
                context.SaveChanges();

                // display a friendly success message
                TempData["StatusMessage"] = "Page created 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"));
                }

                // the user added a blank page, therefore we redirect back to the edit page
                return(RedirectToAction("Edit", new { id = page.PageId }));
            }

            return(View(page));
        }
Exemplo n.º 7
0
        public ActionResult ImageUpload(IEnumerable <HttpPostedFileBase> files)
        {
            TempData["ErrorMessage"] = "";
            // allowed file extensions
            string[] fileExt = { ".png", ".jpg", ".gif", ".jpeg" };

            foreach (var fileBase in files)
            {
                // make sure the image exists
                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("Image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                        }

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

                        // fix bug that iPad/iPhone names all the files "image.jpg"
                        var userAgent = HttpContext.Request.UserAgent.ToLower();
                        if (userAgent.Contains("iphone;") || userAgent.Contains("ipad;"))
                        {
                            fileName = String.Format("{0}{1}", CustomHelpers.GeneratePassword(6), Path.GetExtension(fileBase.FileName.ToLower()));
                        }

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

                        // instantiate object
                        var image = new CircuitBentCMS.Models.Image();
                        image.ImageUrl        = fileName;
                        image.Title           = "";
                        image.Photographer    = "";
                        image.PhotographerUrl = "";

                        // find out how many images there are and get the image order
                        image.Order = context.Images.ToList().Count + 1;

                        context.Images.Add(image);
                        context.SaveChanges();

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

                        // if the image is larger than 0,5 mb, shrink it
                        if (fileBase.ContentLength > 500000)
                        {
                            ImageBuilder.Current.Build(Path.Combine(path, fileName), Path.Combine(path, fileName), new ResizeSettings("maxwidth=1600&maxheight=1600&crop=auto"));
                        }

                        // get the size of the thumbnails from ImageGallerySettings table
                        var imageGallerySettings = context.ImageGallerySettings.FirstOrDefault();
                        ImageBuilder.Current.Build(Path.Combine(path, fileName), Path.Combine(path, "thumb_" + fileName), new ResizeSettings(String.Format("width={0}&height={1}&crop=auto", imageGallerySettings.ThumbnailWidth, imageGallerySettings.ThumbnailHeight)));
                    }
                    catch (Exception e)
                    {
                        TempData["ErrorMessage"] = e.Message;
                    }
                }
            }

            TempData["StatusMessage"]   = "Images uploaded successfully!<br><br>If you want to supply additional information (like title, photographer etc) about the image, just edit it.";
            TempData["MessageDuration"] = 5000;

            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
        public ActionResult Create(StoreItem storeItem, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                // update the counter
                storeItem.Order = context.StoreItems.ToList().Count + 1;

                // add the store item
                context.StoreItems.Add(storeItem);
                context.SaveChanges();

                // 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=250&maxheight=250&crop=auto"));
                        }
                        catch (Exception e)
                        {
                            TempData["ErrorMessage"] = e.Message;
                        }
                    }
                }

                // save the context
                context.SaveChanges();

                TempData["StatusMessage"] = "Store item added successfully!";

                return(RedirectToAction("Index"));
            }

            return(View(storeItem));
        }
Exemplo n.º 9
0
        public ActionResult FileUpload(IEnumerable <HttpPostedFileBase> files)
        {
            // allowed file extensions
            string[] fileExt = { ".png", ".jpg",  ".gif", ".jpeg", ".zip", ".rar", ".flac",   ".pdf",
                                 ".doc", ".docx", ".psd", ".eps",  ".ai",  ".wav", ".tar.gz", ".odt",
                                 ".txt", ".rtf",  ".mp3", ".ogg",  ".mov", ".mkv", ".mpeg",   ".mpeg2", ".html" };
            string[] imageExt = { ".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"
                        var userAgent = HttpContext.Request.UserAgent.ToLower();
                        if (userAgent.Contains("iphone;") || userAgent.Contains("ipad;"))
                        {
                            fileName = String.Format("{0}{1}", CustomHelpers.GeneratePassword(6), Path.GetExtension(fileBase.FileName.ToLower()));
                        }

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

                        // instantiate object
                        var file = new CircuitBentCMS.Models.File();
                        file.FileName      = fileName;
                        file.FileExtension = Path.GetExtension(fileBase.FileName);
                        file.LastUpdated   = DateTime.Now;

                        context.Files.Add(file);
                        context.SaveChanges();

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

                        // check if it's an image, in that case save a thumbnail
                        if (Array.IndexOf(imageExt, Path.GetExtension(fileBase.FileName.ToLower())) > -1)
                        {
                            // if the image is larger than 0,5 mb, shrink it
                            if (fileBase.ContentLength > 500000)
                            {
                                ImageBuilder.Current.Build(Path.Combine(path, fileName), Path.Combine(path, fileName), new ResizeSettings("maxwidth=1600&maxheight=1600&crop=auto"));
                            }
                            // creat thumbnail
                            ImageBuilder.Current.Build(Path.Combine(path, fileName), Path.Combine(path, "thumb_" + fileName), new ResizeSettings("maxwidth=120&maxheight=120&crop=auto"));
                        }
                    }
                    catch (Exception e)
                    {
                        TempData["ErrorMessage"] = e.Message;
                    }
                }
            }

            // if the upload happened from the popup window, redirect to the view withouth an alternative layout
            if (String.IsNullOrEmpty(Request.Form["UsePopupLayout"]))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("InsertFile"));
            }
        }
Exemplo n.º 10
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"));
        }
Exemplo n.º 11
0
        public ActionResult ImageUpload(IEnumerable <HttpPostedFileBase> files)
        {
            // allowed file extensions
            string[] fileExt        = { ".png", ".jpg", ".gif", ".jpeg" };
            var      imageSliderId  = Convert.ToInt32(Request.Form["ImageSliderId"]);
            var      addSliderTitle = Request.Form["AddSliderTitle"];

            // check if the user have selected an existing slider, or wants to create a new
            try
            {
                if (!String.IsNullOrEmpty(addSliderTitle))
                {
                    // make sure that there isn't already a slider with the same name
                    var checkIfSliderExists = context.ImageSliders.SingleOrDefault(a => a.Title == addSliderTitle);
                    if (checkIfSliderExists != null)
                    {
                        throw new Exception("There already exists an image slider with that name. Please select another name.");
                    }

                    // add new image slider to db
                    ImageSlider imageSlider = new ImageSlider
                    {
                        Title = addSliderTitle
                    };
                    context.ImageSliders.Add(imageSlider);
                    context.SaveChanges();

                    // set the image slider id to the newly created
                    imageSliderId = imageSlider.ImageSliderId;
                }
            }
            catch (Exception e)
            {
                TempData["ErrorMessage"] = e.Message;

                return(RedirectToAction("Index"));
            }

            foreach (var fileBase in files)
            {
                // check if the image is valid
                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("Image was in an unsupported format. Only images (JPEG, GIF, PNG) allowed.");
                        }

                        // make sure that the image slider has a correct value
                        if (imageSliderId == 0)
                        {
                            throw new Exception("You have to either select an existing image slider, or create a new one.");
                        }

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

                        // fix bug that iPad/iPhone names all the files "image.jpg"
                        var userAgent = HttpContext.Request.UserAgent.ToLower();
                        if (userAgent.Contains("iphone;") || userAgent.Contains("ipad;"))
                        {
                            fileName = String.Format("{0}{1}", CustomHelpers.GeneratePassword(6), Path.GetExtension(fileBase.FileName.ToLower()));
                        }

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

                        // instantiate object
                        var image = new CircuitBentCMS.Models.ImageSliderImage();
                        image.ImageUrl      = fileName;
                        image.LinkUrl       = "";
                        image.Title         = "";
                        image.ImageSliderId = imageSliderId;

                        // find out how many images there are and get the image order
                        image.Order = context.ImageSliderImages
                                      .Where(a => a.ImageSliderId == imageSliderId)
                                      .ToList().Count + 1;

                        context.ImageSliderImages.Add(image);
                        context.SaveChanges();

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

                        // if the image is larger than 0,5 mb, shrink it
                        if (fileBase.ContentLength > 500000)
                        {
                            ImageBuilder.Current.Build(Path.Combine(path, fileName), Path.Combine(path, fileName), new ResizeSettings("maxwidth=1600&maxheight=1600&crop=auto"));
                        }

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

            return(RedirectToAction("Index"));
        }