public ActionResult Create([Bind(Include = "Id,DrugAddictionRecoveryVillaName,Description,Latitude,Longitude,Email,Address,FK_Category,Phone,Image,FK_AreaId,Website")] DrugAddictionRecoveryVilla drugAddictionRecoveryVilla, 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(); } } drugAddictionRecoveryVilla.Image = file_name; db.DrugAddictionRecoveryVillas.Add(drugAddictionRecoveryVilla); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FK_AreaId = new SelectList(db.Areas, "Id", "AreaName", drugAddictionRecoveryVilla.FK_AreaId); ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", drugAddictionRecoveryVilla.FK_Category); return(View(drugAddictionRecoveryVilla)); }
public ActionResult DeleteConfirmed(long id) { DrugAddictionRecoveryVilla drugAddictionRecoveryVilla = db.DrugAddictionRecoveryVillas.Find(id); db.DrugAddictionRecoveryVillas.Remove(drugAddictionRecoveryVilla); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: DrugAddictionRecoveryVillas/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DrugAddictionRecoveryVilla drugAddictionRecoveryVilla = db.DrugAddictionRecoveryVillas.Find(id); if (drugAddictionRecoveryVilla == null) { return(HttpNotFound()); } return(View(drugAddictionRecoveryVilla)); }
// GET: DrugAddictionRecoveryVillas/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DrugAddictionRecoveryVilla drugAddictionRecoveryVilla = db.DrugAddictionRecoveryVillas.Find(id); if (drugAddictionRecoveryVilla == null) { return(HttpNotFound()); } ViewBag.FK_AreaId = new SelectList(db.Areas, "Id", "AreaName", drugAddictionRecoveryVilla.FK_AreaId); ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", drugAddictionRecoveryVilla.FK_Category); return(View(drugAddictionRecoveryVilla)); }