public string UpdateEmployee(EMPLOYEE Emp) { if (Emp != null) { using (EmployeeConnection Obj = new EmployeeConnection()) { var Emp_ = Obj.Entry(Emp); EMPLOYEE EmpObj = Obj.EMPLOYEEs.Where(x => x.Emp_Id == Emp.Emp_Id).FirstOrDefault(); EmpObj.Emp_Age = Emp.Emp_Age; EmpObj.Emp_City = Emp.Emp_City; EmpObj.Emp_Name = Emp.Emp_Name; Obj.SaveChanges(); return("Employee Updated Successfully"); } } else { return("Employee Not Updated! Try Again"); } }
public string DeleteEmployee(EMPLOYEE Emp) { if (Emp != null) { using (EmployeeConnection Obj = new EmployeeConnection()) { var Emp_ = Obj.Entry(Emp); if (Emp_.State == System.Data.EntityState.Detached) { Obj.EMPLOYEEs.Attach(Emp); Obj.EMPLOYEEs.Remove(Emp); } Obj.SaveChanges(); return("Employee Deleted Successfully"); } } else { return("Employee Not Deleted! Try Again"); } }