public ActionResult AddNewSlideshow(HttpPostedFileBase file, string href, bool isPopupMusicPlayer) { if (Session["Roles"] != null && Session["Roles"].Equals("Admin")) { if (file != null && file.ContentLength > 0) { hypster_tv_DAL.homeSlideshow homeSlide = new hypster_tv_DAL.homeSlideshow(); if (isPopupMusicPlayer == true) { homeSlide.href = "OpenPlayerM('" + href + "');"; } else { homeSlide.href = "window.location='" + href + "';"; } var extension = System.IO.Path.GetExtension(file.FileName); var path = System.IO.Path.Combine(Server.MapPath("~/uploads"), "new_home_slide" + extension); file.SaveAs(path); string image_guid = System.Guid.NewGuid().ToString(); // // resize image // System.IO.FileInfo file_slide = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_home_slide" + extension); file_slide.CopyTo(System.Configuration.ConfigurationManager.AppSettings["homeSlideshowStorage_Path"] + "\\" + image_guid + file_slide.Extension, true); //delete file System.IO.FileInfo del_file = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_home_slide" + extension); del_file.Delete(); hypster_tv_DAL.homeSlideshowManager slideshowManager = new hypster_tv_DAL.homeSlideshowManager(); slideshowManager.IncAllSlides(); homeSlide.isActive = true; homeSlide.SortOrder = 1; homeSlide.ImageSrc = image_guid + file_slide.Extension; hypster_tv_DAL.Hypster_Entities hyDB = new hypster_tv_DAL.Hypster_Entities(); hyDB.homeSlideshows.AddObject(homeSlide); hyDB.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Please add image"); } return(View()); } else { return(RedirectPermanent("/home/")); } }
public ActionResult AddNewSlideshow(HttpPostedFileBase file, string href) { if (file != null && file.ContentLength > 0) { hypster_tv_DAL.homeSlideshow homeSlide = new hypster_tv_DAL.homeSlideshow(); var extension = System.IO.Path.GetExtension(file.FileName); var path = System.IO.Path.Combine(Server.MapPath("~/uploads"), "new_home_slide" + extension); file.SaveAs(path); string image_guid = System.Guid.NewGuid().ToString(); System.IO.FileInfo file_slide = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_home_slide" + extension); file_slide.CopyTo(System.Configuration.ConfigurationManager.AppSettings["homeSlideshowStorage_Path"] + "\\" + image_guid + file_slide.Extension, true); //delete file System.IO.FileInfo del_file = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_home_slide" + extension); del_file.Delete(); hypster_tv_DAL.homeSlideshowManager slideshowManager = new hypster_tv_DAL.homeSlideshowManager(); slideshowManager.IncAllSlides(); homeSlide.href = href; homeSlide.isActive = false; homeSlide.SortOrder = 1; homeSlide.ImageSrc = image_guid + file_slide.Extension; hypster_tv_DAL.Hypster_Entities hyDB = new hypster_tv_DAL.Hypster_Entities(); hyDB.homeSlideshows.AddObject(homeSlide); hyDB.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Please add image"); } return(View()); }