public ActionResult Create(Picture picture) { if (ModelState.IsValid) { db.Pictures.Add(picture); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PlaceId = new SelectList(db.Places, "Id", "Name", picture.PlaceId); return View(picture); }
public ActionResult Edit(Picture picture) { if (ModelState.IsValid) { db.Entry(picture).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PlaceId = new SelectList(db.Places, "Id", "Name", picture.PlaceId); return View(picture); }
public ActionResult UploadPicture(int? id, IEnumerable<HttpPostedFileBase> upload) { Place place = db.Places.FirstOrDefault(c => c.Id == id); if (upload != null) { foreach (var file in upload) { var fileName = place.Name + "_" + Guid.NewGuid().ToString() + Path.GetFileName(file.FileName); var physicalPath = Path.Combine(Server.MapPath("~/img"), fileName); file.SaveAs(physicalPath); Picture pic = new Picture(); pic.PlaceId = place.Id; pic.Name = "..\\img\\" + fileName; db.Pictures.Add(pic); db.SaveChanges(); } } return Content(""); }