public void AddNewLocation(tblLocation location) { using (var context = new EmployeeRecordsEntities()) { context.tblLocations.Add(location); context.SaveChanges(); } }
internal void AddNewSector(tblSector newSector) { using (var context = new EmployeeRecordsEntities()) { context.tblSectors.Add(newSector); context.SaveChanges(); } }
internal void AddNewEmployee(tblEmployee employee) { using (var context = new EmployeeRecordsEntities()) { context.tblEmployees.Add(employee); context.SaveChanges(); } }
internal void DeleteEmployee(int employeeID) { using (var context = new EmployeeRecordsEntities()) { var employeeToRemove = context.tblEmployees.FirstOrDefault(e => e.EmployeeID == employeeID); if (employeeToRemove != null) { context.tblEmployees.Remove(employeeToRemove); context.SaveChanges(); } } }
internal void UpdateEmployee(int employeeID, tblEmployee employee) { using (var context = new EmployeeRecordsEntities()) { if (context.tblEmployees.Any(e => e.EmployeeID == employeeID)) { var employeeToUpdate = context.tblEmployees.First(e => e.EmployeeID == employeeID); employeeToUpdate.GivenName = employee.GivenName; employeeToUpdate.Surname = employee.Surname; employeeToUpdate.Sex = employee.Sex; employeeToUpdate.PersonalNo = employee.PersonalNo; employeeToUpdate.RegistrationNumber = employee.RegistrationNumber; employeeToUpdate.Telephone = employee.Telephone; employeeToUpdate.LocationID = employee.LocationID; employeeToUpdate.Manager = employee.Manager; employeeToUpdate.SectorID = employee.SectorID; context.SaveChanges(); } } }