コード例 #1
0
ファイル: SidebarController.cs プロジェクト: webitpro/WolfWeb
        public ActionResult AddFlash(string webpage, ImageFile flashThumb, VideoFile flash, int flashOverlay)
        {
            string thumbPath = "";

            if (flashThumb != null)
            {
                flashThumb.ValidateForUpload(true);
                if (ModelState.IsValid)
                {

                    flashThumb.Save("sidebar_flash_thumb", new System.Drawing.Size(Config.Sidebar.Thumbnail.Width, Config.Sidebar.Thumbnail.Height), false);
                    thumbPath = "/" + flashThumb.SavePath;
                    flashThumb.Cleanup();
                }
            }
            else
            {
                ModelState.AddModelError("", "Thumbnail is not recognized");
            }

            string dbPath = "";
            if (flash != null)
            {
                flash.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    if (!System.IO.Path.GetExtension(flash.Name).Equals(".flv"))
                    {
                        ModelState.AddModelError("", "Invalid file type. Expected: .flv");
                    }
                    if (ModelState.IsValid)
                    {
                        flash.Save("sidebar_flash_file" + System.IO.Path.GetExtension(flash.Name));

                        dbPath = "/" + flash.SavePath;
                        flash.Cleanup();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Video File is not recognized");
            }

            if (!string.IsNullOrEmpty(dbPath) && !string.IsNullOrEmpty(thumbPath))
            {
                DBDataContext db = Utils.DB.GetContext();
                WebPage pg = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webpage));
                if (pg != null)
                {
                    pg.Sidebars.Add(new Sidebar() { TypeID = db.Types.Single(x => x.Name.Equals("Video")).ID, Source = dbPath, Thumb = thumbPath, IsOverlay = Convert.ToBoolean(flashOverlay) });
                    try
                    {
                        db.SubmitChanges();
                        return RedirectToAction("Index", "Sidebar", new { controller = "Sidebar", action = "Index", webpage = webpage });
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "An unknown error occurred. Please try again in few minutes.");
                        ErrorHandler.Report.Exception(ex, "Sidebar/AddFlash[POST]");

                    }
                }
                else
                {
                    ModelState.AddModelError("", "Web Page is doesn't exist");

                }
            }
            else
            {
                ModelState.AddModelError("", "There has been an issue with uploading your Video file. Please try again in few minutes.");

            }

                if (System.IO.File.Exists(HttpContext.Server.MapPath(dbPath)))
                {
                    System.IO.File.Delete(HttpContext.Server.MapPath(dbPath));
                }

                if (System.IO.File.Exists(HttpContext.Server.MapPath(thumbPath)))
                {
                    System.IO.File.Delete(HttpContext.Server.MapPath(thumbPath));
                }

            ViewData["Type"] = "Flash";
            ViewData["WebPageID"] = webpage;
            return View("Add");
        }
コード例 #2
0
ファイル: HeaderController.cs プロジェクト: webitpro/WolfWeb
        public ActionResult Add(ImageFile image, VideoFile video, string webPageId)
        {
            string dbImagePath = "";
            string dbVideoPath = "";
            string videoFileName = "";
            string imageFileName = "";

            if (image != null)
            {
                image.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    if (image.Save("header_image", new System.Drawing.Size(Config.Header.Image.Width, Config.Header.Image.Height), false))
                    {
                        dbImagePath = "/" + image.SavePath;
                        imageFileName = image.SavedName;
                        image.Cleanup();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Image File is not recognized");
            }

            if (video != null)
            {
                video.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    if (!System.IO.Path.GetExtension(video.Name).Equals(".swf"))
                    {
                        ModelState.AddModelError("", "Invalid file type. Expected: .swf");
                    }

                    if (ModelState.IsValid)
                    {
                        if (video.Save("header_flash" + System.IO.Path.GetExtension(video.Name)))
                        {
                            dbVideoPath = "/" + video.SavePath;
                            videoFileName = video.SavedName;
                            video.Cleanup();
                        }
                    }

                }
            }
            else
            {
                ModelState.AddModelError("", "Video File is not recognized");
            }

            bool removeFiles = false;

            if(!string.IsNullOrEmpty(dbImagePath) && !string.IsNullOrEmpty(dbVideoPath))
            {
                DBDataContext db = Utils.DB.GetContext();
                WebPage pg = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webPageId));
                if (pg != null)
                {
                    Header h = new Header()
                    {
                        ImagePath = dbImagePath,
                        MoviePath = dbVideoPath
                    };
                    pg.Headers.Add(h);

                    try
                    {
                        db.SubmitChanges();
                        return RedirectToAction("Index", "Header", new { controller = "Header", action = "Index", webpage = webPageId });
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                        ErrorHandler.Report.Exception(ex, "Header/Add");
                        removeFiles = true;
                    }

                }
                else
                {
                    ModelState.AddModelError("", "Web Page does not exist");
                    removeFiles = true;
                }
            }
            else
            {
                ModelState.AddModelError("", "There has been an issue with uploading your Image/Video file. Please try again in few minutes.");
                removeFiles = true;
            }

            if (removeFiles)
            {
                if (System.IO.File.Exists(Url.UploadPath(imageFileName)))
                {
                    System.IO.File.Delete(Url.UploadPath(imageFileName));
                }

                if(System.IO.File.Exists(Url.UploadPath(videoFileName)))
                {
                    System.IO.File.Delete(Url.UploadPath(videoFileName));
                }
            }

            ViewData["Title"] = "Add Header";
            ViewData["Action"] = "Add";
            return View("Manage");
        }