Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
 partial void DeleteHeader(Header instance);
Exemplo n.º 3
0
 partial void UpdateHeader(Header instance);
Exemplo n.º 4
0
 partial void InsertHeader(Header instance);
Exemplo n.º 5
0
		private void detach_Headers(Header entity)
		{
			this.SendPropertyChanging();
			entity.WebPage = null;
		}
Exemplo n.º 6
0
		private void attach_Headers(Header entity)
		{
			this.SendPropertyChanging();
			entity.WebPage = this;
		}