public ActionResult ModifPagePublique(string nomPage) { if (nomPage != null) { nomPage = nomPage.ToLower(); GetContenu_Result contentResult = db.GetContenu(nomPage.ToLower()).FirstOrDefault(); if (contentResult != null) { PublicContentModel model = new PublicContentModel(); model.nomPage = contentResult.PAGE; model.titre = contentResult.TITRE; model.titreTrad = contentResult.TITRE_TRAD; model.contenu = Message.BrToNewline(contentResult.CONTENU); model.contenuTrad = Message.BrToNewline(contentResult.CONTENU_TRAD); model.fileName = contentResult.URLIMAGE; return(View(model)); } } return(RedirectToAction("Index")); }
public ActionResult ModifPagePublique(PublicContentModel model) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(Request.Form["modifierPage"])) { if (model.nomPage != null && (model.nomPage.Equals("accueil") || model.nomPage.Equals("about") || model.nomPage.Equals("contact"))) { db.ModifierContenu(model.nomPage, model.titre, model.titreTrad, model.contenu, model.contenuTrad, model.fileName); db.SaveChanges(); if (model.nomPage.Equals("about")) { return(RedirectToAction("APropos", "Public")); } else if (model.nomPage.Equals("contact")) { return(RedirectToAction("NousJoindre", "Public")); } else { return(RedirectToAction("Home", "Public")); } } } else if (!string.IsNullOrEmpty(Request.Form["modifierImage"])) { if (model.File != null) { HttpPostedFileBase fichier = model.File; int MaxContentLength = 1024 * 1024 * 2; //2 MB string[] AllowedFileExtensions = new string[] { ".jpg", ".jpeg" }; if (!AllowedFileExtensions.Contains(fichier.FileName.Substring(fichier.FileName.LastIndexOf('.')))) { ModelState.AddModelError("", Resources.Messages.FileType + string.Join(", ", AllowedFileExtensions)); } else if (fichier.ContentLength > MaxContentLength) { ModelState.AddModelError("", Resources.Messages.FileTooLarge + (MaxContentLength / 1024).ToString() + "MB"); } else { var fileName = Path.GetFileName(fichier.FileName); var path = Path.Combine(Server.MapPath("~/Content/images/photos"), fileName); fichier.SaveAs(path); model.fileName = fileName; } } else { model.fileName = null; } return(View(model)); } } return(View(model)); }