public ActionResult Create(DocumentVM DocVM, HttpPostedFileBase Image) { Documents t1 = new Documents(); t1.Name = DocVM.Name + " " + DateTime.Now.ToString(); t1.DateDoc = DateTime.Now; t1.Size = DocVM.Size; t1.FileType = (FileType)DocVM.TypeVm; t1.ImageUrl = Image.FileName; t1.ProjectId = DocVM.ProjectId; t1.FileType = (FileType)DocVM.TypeVm; MyDocService.Add(t1); MyDocService.Commit(); var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName); //ajout de l'image dans un dossier Upload Image.SaveAs(path); // MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**"); // mail.Subject = "documet cree"; // mail.Body = "test document envoiyer"; // mail.IsBodyHtml = true; // SmtpClient smtpClient = new SmtpClient("Smtp.gmail.com", 587); // smtpClient.EnableSsl = true; // smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "123456aze"); // smtpClient.Send(mail); /// https://www.google.com/settings/security/lesssecureapps go to link and alllow return(RedirectToAction("Index")); }
public ActionResult Create(int idProject, HttpPostedFileBase file, DocumentViewModel DVM) { if (!Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } //redirect to nowhere if not admin if (!(User.IsInRole("Team Leader"))) { return(RedirectToAction("Nowhere", "Account")); } Project P = PS.GetById(idProject); Document D = new Document(); D.DocumentId = DVM.DocumentId; D.DocumentName = DVM.DocumentName; D.categorie = (Domain.Entities.Categorie)DVM.categorie; try { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Documents/"), fileName); file.SaveAs(path); DVM.Size = file.ContentLength / 1024; D.Path = "~/Content/Documents/" + fileName; D.Size = DVM.Size; D.DateCreation = DateTime.Now; D.ProjectFK = P.ProjectId; ViewBag.Message = "File Uploaded Successfully!!"; DS.Add(D); DS.Commit(); } } catch { ViewBag.Message = "File upload failed!!"; return(View(DVM)); } return(RedirectToAction("Details", "Project", new { id = idProject })); }
public ActionResult Create(DocumentViewModel DVM, System.Web.HttpPostedFileBase file) { Document D = new Document(); D.DocumentId = DVM.DocumentId; D.DocumentName = DVM.DocumentName; D.Size = DVM.Size; D.categorie = (Domain.Entities.Categorie)DVM.categorie; try { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Documents/"), fileName); file.SaveAs(path); D.Path = "~/Content/Documents/" + fileName; ViewBag.Message = "File Uploaded Successfully!!"; } } catch { ViewBag.Message = "File upload failed!!"; return(View()); } D.DateCreation = DateTime.Now; DS.Add(D); DS.Commit(); if (DVM.categorie == Web.Models.Categorie.Image) { return(View("Index")); } else { return(View("IndexDocument")); } }