private void addPictureTable(DisplayViewModel display, HttpPostedFileBase fileAbout, HttpPostedFileBase fileWelcome) { if (fileAbout != null) { display.AboutView.Path = "/Content/Images/About/"; display.AboutView.FileName = fileAbout.FileName; fileAbout.SaveAs(HttpContext.Server.MapPath(display.AboutView.Path + display.AboutView.FileName)); } if (fileWelcome != null) { display.WelcomeView.Path = "/Content/Images/Welcome/"; display.WelcomeView.FileName = fileWelcome.FileName; fileWelcome.SaveAs(HttpContext.Server.MapPath(display.WelcomeView.Path + display.WelcomeView.FileName)); } }
private void addOrUpdateDisplay(DisplayViewModel display, HttpPostedFileBase fileAbout , HttpPostedFileBase fileWelcome , string origineFileAbout , string origineFileWelcome , string aboutID , string welcomeID) { /***** Welcome Page Dispay ****/ int idAbout = Int32.Parse(aboutID); var origineAboutDisplay = db.DisplayAbout.Where(x => x.ID == idAbout).Single(); origineAboutDisplay.Name = display.AboutView.Name; origineAboutDisplay.HeadZone1 = display.AboutView.HeadZone1; origineAboutDisplay.HeadZone2 = display.AboutView.HeadZone2; origineAboutDisplay.HeadZone3 = display.AboutView.HeadZone3; origineAboutDisplay.BodyZone1 = display.AboutView.BodyZone1; origineAboutDisplay.BodyZone2 = display.AboutView.BodyZone2; origineAboutDisplay.BodyZone3 = display.AboutView.BodyZone3; origineAboutDisplay.BodyZone4 = display.AboutView.BodyZone4; origineAboutDisplay.BodyZone5 = display.AboutView.BodyZone5; display.AboutView = origineAboutDisplay; if (fileAbout != null) { display.AboutView.Path = "/Content/Images/About/"; string[] savedFiles = System.IO.Directory.GetFiles(Server.MapPath("~" + display.AboutView.Path)); var origineFileWithPath = Server.MapPath("~" + display.AboutView.Path) + origineFileAbout; foreach (var f in savedFiles) { if (origineFileWithPath.Equals(f)) System.IO.File.Delete(f); } display.AboutView.FileName = fileAbout.FileName; fileAbout.SaveAs(HttpContext.Server.MapPath(display.AboutView.Path + display.AboutView.FileName)); } /***** Welcome Page Dispay ****/ int idWelcome = Int32.Parse(welcomeID); var origineWelcometDisplay = db.DisplayWelcome.Where(x => x.ID == idWelcome).Single(); origineWelcometDisplay.Name = display.WelcomeView.Name; origineWelcometDisplay.Zone1 = display.WelcomeView.Zone1; origineWelcometDisplay.Zone2 = display.WelcomeView.Zone2; origineWelcometDisplay.Zone3 = display.WelcomeView.Zone3; display.WelcomeView = origineWelcometDisplay; if (fileWelcome != null) { display.WelcomeView.Path = "/Content/Images/Welcome/"; string[] savedFiles = System.IO.Directory.GetFiles(Server.MapPath("~" + display.WelcomeView.Path)); var origineFileWithPath = Server.MapPath("~" + display.WelcomeView.Path) + origineFileWelcome; foreach (var f in savedFiles) { if (origineFileWithPath.Equals(f)) System.IO.File.Delete(f); } display.WelcomeView.FileName = fileWelcome.FileName; fileWelcome.SaveAs(HttpContext.Server.MapPath(display.WelcomeView.Path + display.WelcomeView.FileName)); } }