public ActionResult Create([Bind(Include = "Id,FootballCourtName,Description,Latitude,Longitude,Email,Address,FK_Category,Phone,Image,FK_AreaId,Website")] FootballCourt footballCourt, HttpPostedFileBase img) { if (ModelState.IsValid) { string file_name = ""; if (img != null && img.ContentLength > 0) { try { file_name = Guid.NewGuid() + Path.GetFileName(img.FileName); string path = Path.Combine(Server.MapPath("~/images"), file_name); img.SaveAs(path); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } footballCourt.Image = file_name; db.FootballCourts.Add(footballCourt); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FK_AreaId = new SelectList(db.Areas, "Id", "AreaName", footballCourt.FK_AreaId); ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", footballCourt.FK_Category); return(View(footballCourt)); }
public ActionResult DeleteConfirmed(long id) { FootballCourt footballCourt = db.FootballCourts.Find(id); db.FootballCourts.Remove(footballCourt); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: FootballCourts/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FootballCourt footballCourt = db.FootballCourts.Find(id); if (footballCourt == null) { return(HttpNotFound()); } return(View(footballCourt)); }
// GET: FootballCourts/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FootballCourt footballCourt = db.FootballCourts.Find(id); if (footballCourt == null) { return(HttpNotFound()); } ViewBag.FK_AreaId = new SelectList(db.Areas, "Id", "AreaName", footballCourt.FK_AreaId); ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", footballCourt.FK_Category); return(View(footballCourt)); }