public ActionResult Create([Bind(Include = "id,name,profession,photo,text_about,facebook,intagram,phone,email")] health_staff health_staff, HttpPostedFileBase photo) { if (ModelState.IsValid) { if (photo.ContentType == "image/jpeg" || photo.ContentType == "image/png" || photo.ContentType == "image/gif") { DateTime now = DateTime.Now; string fileName = now.ToString("yyyyMdHms") + Path.GetFileName(photo.FileName); string path = Path.Combine(Server.MapPath("~/Uploads"), fileName); photo.SaveAs(path); health_staff.photo = fileName; db.health_staff.Add(health_staff); db.SaveChanges(); } else { ViewBag.Message = "You can only jpg,png or gif file upload"; return(View()); } } else { ViewBag.Message = "Error"; return(View()); } return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { health_staff health_staff = db.health_staff.Find(id); db.health_staff.Remove(health_staff); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id,name,profession,photo,text_about,instagram,facebook")] health_staff health_staff) { if (ModelState.IsValid) { db.Entry(health_staff).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(health_staff)); }
public ActionResult Create2([Bind(Include = "id,name,profession,photo,text_about,instagram,facebook,phone,email")] health_staff health_staff) { if (ModelState.IsValid) { db.health_staff.Add(health_staff); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(health_staff)); }
public ActionResult DeleteConfirmed(int id) { health_staff health_staff = db.health_staff.Find(id); string fullPath = Request.MapPath("~/Uploads/" + health_staff.photo); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } db.health_staff.Remove(health_staff); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Dr_Profile public ActionResult Index(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dynamic mymodel = new ExpandoObject(); health_staff staff_id = db.health_staff.Find(id); mymodel.staffId = staff_id; mymodel.other_doctors = db.health_staff.Where(h => h.id != id).Take(4).ToList(); return(View(mymodel)); }
// GET: Health_Staff_Crud/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } health_staff health_staff = db.health_staff.Find(id); if (health_staff == null) { return(HttpNotFound()); } return(View(health_staff)); }
public ActionResult Edit([Bind(Include = "id,name,profession,photo,text_about,instagram,facebook,phone,email")] health_staff health_staff, string oldfile) { var gelensekil = HttpContext.Request.Files["photo"]; if (gelensekil.FileName.Length > 0) { if (gelensekil.ContentType == "image/jpeg" || gelensekil.ContentType == "image/png" || gelensekil.ContentType == "image/gif") { DateTime now = DateTime.Now; string fileName = now.ToString("yyyyMdHms") + Path.GetFileName(gelensekil.FileName); string newfile = Path.Combine(Server.MapPath("~/Uploads"), fileName); gelensekil.SaveAs(newfile); health_staff.photo = fileName; string fullPath = Request.MapPath("~/Uploads/" + oldfile); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } else { ViewBag.Message = "You can only jpg,png or gif file upload"; return(View()); } } else { health_staff.photo = oldfile; } if (ModelState.IsValid) { db.Entry(health_staff).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(health_staff)); }