public ActionResult addtextfile(groue_detail groue_Detail, int?id, HttpPostedFileBase file) { if (ModelState.IsValid) { try { if (file != null) { var path = Path.Combine(Server.MapPath("~/AppDocuments"), file.FileName); if (file.ContentLength <= 2097152) { file.SaveAs(path); var currentId = User.Identity.GetUserId(); var x = db.Utilisateur.FirstOrDefault(p => p.UserId == currentId); groue_Detail.Fichier = file.FileName; groue_Detail.Groupe_thematiqeID = db.Groupe_thematiqe.FirstOrDefault(p => p.ID == id).ID; groue_Detail.MembreId = x.ID; groue_Detail.datecreation = DateTime.Now; if (groue_Detail.Text.Length <= 350) { db.groue_detail.Add(groue_Detail); db.SaveChanges(); } else { TempData["Message"] = "limite de caractère est 350 character"; } } } } catch (DbEntityValidationException DbExc) { string error = ""; foreach (var er in DbExc.EntityValidationErrors) { foreach (var ve in er.ValidationErrors) { error += " - " + ve.ErrorMessage; } } TempData["Message"] = error; return(RedirectToAction("Consulte", "Groupe", new { id })); } //file.SaveAs(path); return(RedirectToAction("Consulte", "Groupe", new { id })); } return(RedirectToAction("Consulte", "Groupe", new { id })); }
public ActionResult addtextfile(groue_detail groue_Detail, int?id, HttpPostedFileBase file) { if (ModelState.IsValid) { var path = Path.Combine(Server.MapPath("~/AppDocuments"), file.FileName); file.SaveAs(path); var currentId = User.Identity.GetUserId(); var x = db.Utilisateur.FirstOrDefault(p => p.UserId == currentId); groue_Detail.Fichier = file.FileName; groue_Detail.Groupe_thematiqeID = db.Groupe_thematiqe.FirstOrDefault(p => p.ID == id).ID; groue_Detail.MembreId = x.ID; groue_Detail.datecreation = DateTime.Now; db.groue_detail.Add(groue_Detail); db.SaveChanges(); //file.SaveAs(path); return(RedirectToAction("Consulte", "Groupe", new { id })); } return(View()); }