public ActionResult Edit([Bind(Include = "CenterStaffId,Name,Description,Path,Code")] CenterStaff centerStaff, HttpPostedFileBase Image) { if (ModelState.IsValid) { int id = centerStaff.CenterStaffId; if (Image != null) { string path1_1 = Path.Combine(Server.MapPath("~/ImagesOfProject/PrePresidentPhotos"), Image.FileName); string Extension1 = Path.GetExtension(path1_1); string path1_2 = Path.Combine(Server.MapPath("~/ImagesOfProject/PrePresidentPhotos"), id + Extension1); Image.SaveAs(path1_2); string Domain = ConfigurationManager.AppSettings["Domain"].ToString(); centerStaff.Path = Domain + "/ImagesOfProject/PrePresidentPhotos/" + id + Extension1; } //string Path1 = Path.Combine(Server.MapPath("~/ImagesOfProject/PrePresidentPhotos"), centerStaff.CenterStaffId + Image.FileName); //Image.SaveAs(Path1); //centerStaff.Path = "~/ImagesOfProject/" + centerStaff.CenterStaffId + Image.FileName; centerStaff.Code = 4; db.Entry(centerStaff).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(centerStaff)); }
public ActionResult DeleteConfirmed(int id) { CenterStaff centerStaff = db.CenterStaffs.Find(id); db.CenterStaffs.Remove(centerStaff); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: PrevPresident/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CenterStaff centerStaff = db.CenterStaffs.Find(id); if (centerStaff == null) { return(HttpNotFound()); } return(View(centerStaff)); }
public ActionResult Create(CenterStaff centerStaff, HttpPostedFileBase Image) { if (ModelState.IsValid) { //get the id of the last row + 1 string ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection con = new SqlConnection(ConnectionString); string Query = "SELECT IDENT_CURRENT('centerStaffs') + IDENT_INCR('centerStaffs')"; SqlCommand cmd = new SqlCommand(Query, con); int id = 0; try { con.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { id = Convert.ToInt32(dr[0]); } dr.Close(); con.Close(); } catch (Exception) { throw; } //save form image string path1_1 = Path.Combine(Server.MapPath("~/ImagesOfProject/PrePresidentPhotos"), Image.FileName); string Extension1 = Path.GetExtension(path1_1); string path1_2 = Path.Combine(Server.MapPath("~/ImagesOfProject/PrePresidentPhotos"), id + Extension1); Image.SaveAs(path1_2); string Domain = ConfigurationManager.AppSettings["Domain"].ToString(); centerStaff.Path = Domain + "/ImagesOfProject/PrePresidentPhotos/" + id + Extension1; centerStaff.Code = 4; db.CenterStaffs.Add(centerStaff); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(centerStaff)); }
public ActionResult Details(int?id) { CenterStaff C = db.CenterStaffs.Find(id); return(View(C)); }