public ActionResult Edit(Exercises exercises, HttpPostedFileBase Pic) { if (ModelState.IsValid) { string fileName = null; if (Pic != null) { fileName = Path.GetFileName(Pic.FileName); string extensionImage = getFileExtension(fileName); fileName = Guid.NewGuid() + "." + extensionImage; var path = Path.Combine(Server.MapPath("~/Content/Images/ExerciseGifs"), fileName); //var path = Path.Combine("https://disk.yandex.ru/d/DXlvv0vSsvgswQ?w=1", fileName); Pic.SaveAs(path); exercises.PicturePath = fileName; } else { using (SmartWorkouts_newEntities bd = new SmartWorkouts_newEntities()) { exercises.PicturePath = bd.Exercises.Where(p => p.ID_Exercise == exercises.ID_Exercise).FirstOrDefault().PicturePath; } } db.Entry(exercises).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Premium_Work_Number = new SelectList(db.Premium_Works, "Number_Premium_Work", "Name_Premium_Work", exercises.Premium_Work_Number); ViewBag.Type_Exercise = new SelectList(db.Types_Workout, "Number_Type", "Name_Type", exercises.Type_Exercise); return(View(exercises)); }
public ActionResult Edit(Premium_Works premium_Works, HttpPostedFileBase Pic) { if (ModelState.IsValid) { string fileName = null; if (Pic != null) { fileName = Path.GetFileName(Pic.FileName); string extensionImage = getFileExtension(fileName); fileName = Guid.NewGuid() + "." + extensionImage; var path = Path.Combine(Server.MapPath("~/Content/Images/PremiumWorks"), fileName); //var path = Path.Combine("https://disk.yandex.ru/d/DXlvv0vSsvgswQ?w=1", fileName); Pic.SaveAs(path); premium_Works.PicturePath = fileName; } else { using (SmartWorkouts_newEntities bd = new SmartWorkouts_newEntities()) { premium_Works.PicturePath = bd.Premium_Works.Where(p => p.Number_Premium_Work == premium_Works.Number_Premium_Work).FirstOrDefault().PicturePath; } } db.Entry(premium_Works).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(premium_Works)); }