public string AddEmployee(Employee Emp) { if (Emp != null) { using (SampleDBEntities2 dataContext = new SampleDBEntities2()) { dataContext.Employees.Add(Emp); dataContext.SaveChanges(); return("Employee Updated"); } } else { return("Invalid Employee"); } }
public string DeleteEmployee(Employee Emp) { if (Emp != null) { using (SampleDBEntities2 dataContext = new SampleDBEntities2()) { int no = Convert.ToInt32(Emp.Id); var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault(); dataContext.Employees.Remove(employeeList); dataContext.SaveChanges(); return("Employee Deleted"); } } else { return("Invalid Employee"); } }
public string UpdateEmployee(Employee Emp) { if (Emp != null) { using (SampleDBEntities2 dataContext = new SampleDBEntities2()) { int no = Convert.ToInt32(Emp.Id); var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault(); employeeList.name = Emp.name; // employeeList.Age = Emp.Age; employeeList.email = Emp.email; dataContext.SaveChanges(); return("Employee Updated"); } } else { return("Invalid Employee"); } }