public void DeleteEmployee(int empId) { EmployeeEntity empContext = new EmployeeEntity(); var emp = empContext.EmployeeDetails.Where(x => x.EmpID == empId).FirstOrDefault(); empContext.Entry(emp).State = System.Data.Entity.EntityState.Deleted; empContext.SaveChanges(); }
public ActionResult Edit(Employee employee) { Employee employeeFromDB = db.Employees.Single(emp => emp.EmployeeID == employee.EmployeeID); employeeFromDB.Gender = employee.Gender; employeeFromDB.DepartmentID = employee.DepartmentID; employeeFromDB.City = employee.City; employee.Name = employeeFromDB.Name; employee.Department = employee.DepartmentID != null?employee.Department = db.Departments.Single(dept => dept.DepartmentID == employee.DepartmentID) : null; if (ModelState.IsValid) { db.Entry(employeeFromDB).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "Name", employee.DepartmentID); return(View(employee)); }
public void Update(T obj) { table.Attach(obj); _context.Entry(obj).State = EntityState.Modified; }