public ActionResult Create([Bind(Include = "Id,Name,Email,Phone,MaritalStatus,State,City,image")] Emp2 emp, HttpPostedFileBase imageFile) { if (ModelState.IsValid) { db.Employees.Add(emp); db.SaveChanges(); if (imageFile != null && imageFile.ContentLength > 0) { var fileName = Path.GetFileName(imageFile.FileName); emp.image = fileName; //db.Employees.Add(emp);//Adding into the database db.SaveChanges(); var path = Path.Combine(Server.MapPath("~/Content/img/")); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } imageFile.SaveAs(path + "/" + fileName); } return(RedirectToAction("Index")); //return RedirectToAction("Index"); } ViewBag.StateList = db.StateList; ViewBag.CityList = db.CityList; return(View(emp)); }
public ActionResult DeleteConfirmed(int id) { Emp2 emp = db.Employees.Find(id); db.Employees.Remove(emp); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create() { Employeecontext db = new Employeecontext(); ViewBag.StateList = db.StateList; var model = new Emp2(); return(View(model)); }
public ActionResult Edit([Bind(Include = "Id,Name,Email,Phone,MaritalStatus,State,City")] Emp2 employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
// GET: Products/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Emp2 employee = db.Employees.Find(id); if (employee == null) { return(HttpNotFound()); } return(View(employee)); }