public ActionResult Create(ViewModel VN, HttpPostedFileBase ImageeExPrincipale, string[] Outildata, string[] ConseilData, IEnumerable <HttpPostedFileBase> UploadImage, List <string> UploadTitle, IEnumerable <HttpPostedFileBase> UploadDrive, List <string> UploadTitleDrive) { if (ModelState.IsValid) { //Ajouter Expiriment---------------------------------------------- var ImageExprirmentPath = Path.Combine(Server.MapPath("~/Images/ImageExpiriment"), ImageeExPrincipale.FileName); ImageeExPrincipale.SaveAs(ImageExprirmentPath); VN.Expiriment.ApplicationUserId = User.Identity.GetUserId(); VN.Expiriment.DateTime = DateTime.Now; VN.Expiriment.Image = ImageeExPrincipale.FileName; VN.Expiriment.IdFilliere = string.Join(",", VN.Expiriment.SelectedArrayFilliere); db.Expiriments.Add(VN.Expiriment); db.SaveChanges(); //------------------------------Ajouter Outils-------------------------------------- OutilConseilImage.SaveOutil(Outildata, VN.Expiriment.Id); //------------------------------Ajouter Conseil-------------------------------------- OutilConseilImage.SaveConseil(ConseilData, VN.Expiriment.Id); //Ajouter Image---------------------------------------------------------------------- OutilConseilImage.saveImage(UploadImage, UploadTitle, VN.Expiriment.Id); //Ajouter Fichier pour telecharger GoogleDriveFilesRepository.FileUpload(UploadDrive, UploadTitleDrive, VN.Expiriment.Id); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit(ViewModel viewModel, HttpPostedFileBase EditImage, string[] Outildata, string[] ConseilData, List <string> UpdateImage, IEnumerable <HttpPostedFileBase> UploadImage, List <string> UploadTitle) { string oldImage = Path.Combine(Server.MapPath("~/Images/ImageExpiriment"), viewModel.Expiriment.Image); if (EditImage != null) { System.IO.File.Delete(oldImage); var ImageExprirmentPath = Path.Combine(Server.MapPath("~/Images/ImageExpiriment"), EditImage.FileName); EditImage.SaveAs(ImageExprirmentPath); viewModel.Expiriment.Image = EditImage.FileName; } viewModel.Expiriment.IdFilliere = string.Join(",", viewModel.Expiriment.SelectedArrayFilliere); viewModel.Expiriment.DateTime = DateTime.Now; db.Entry(viewModel.Expiriment).State = EntityState.Modified; db.SaveChanges(); // Update Outils -------------------------------------------- var outils = db.Outils.ToList(); outils = outils.Where(s => s.ExpirimentId == viewModel.Expiriment.Id).ToList(); db.Outils.RemoveRange(outils); db.SaveChanges(); OutilConseilImage.SaveOutil(Outildata, viewModel.Expiriment.Id); //Update Conseil------------------------------------------ var Conseil = db.Conseils.ToList(); Conseil = Conseil.Where(s => s.ExpirimentId == viewModel.Expiriment.Id).ToList(); db.Conseils.RemoveRange(Conseil); OutilConseilImage.SaveConseil(ConseilData, viewModel.Expiriment.Id); //Update Groups Image----------------------------------------------------------------------- var list = db.Imageses.Where(s => s.ExpirimentId == viewModel.Expiriment.Id).ToList(); db.Imageses.RemoveRange(list); if (UpdateImage != null) { var GroupsImage = UpdateImage.ToList(); db.SaveChanges(); foreach (var img in GroupsImage) { var images = new Images { Image = img, ExpirimentId = viewModel.Expiriment.Id }; db.Imageses.Add(images); db.SaveChanges(); } } OutilConseilImage.saveImage(UploadImage, UploadTitle, viewModel.Expiriment.Id); //Update Google Drive return(RedirectToAction("Index")); }