public static void Insert(Employee employee) { using (var context = new SoftUniContext()) { context.Employees.Add(employee); context.SaveChanges(); } }
public static void Delete(Employee employee) { using (var context = new SoftUniContext()) { Employee employeeToDelete = context.Employees.Find(employee.EmployeeID); context.Employees.Remove(employeeToDelete); context.SaveChanges(); } }
public static void Update(Employee employee) { using (var context = new SoftUniContext()) { Employee employeeToUpdate = context.Employees.Find(employee.EmployeeID); employeeToUpdate.FirstName = employee.FirstName; employeeToUpdate.LastName = employee.LastName; employeeToUpdate.MiddleName = employee.MiddleName; employeeToUpdate.DepartmentID = employee.DepartmentID; employeeToUpdate.ManagerID = employee.ManagerID ?? null; employeeToUpdate.JobTitle = employee.JobTitle; employeeToUpdate.HireDate = employee.HireDate; employeeToUpdate.Salary = employee.Salary; employeeToUpdate.AddressID = employee.AddressID ?? null; context.SaveChanges(); } }
public void AddEmployee() { var employee = new Employee() { FirstName = "Test", LastName = "Tester", JobTitle = "Newbee tester", HireDate = DateTime.Now, Salary = 0, DepartmentID = this.department.DepartmentID }; EmployeeDao.Insert(employee); using (var context = new SoftUniContext()) { var retrievedEmployee = context.Employees.FirstOrDefault(x => x.JobTitle == "Newbee tester"); Assert.AreEqual( employee.FirstName + employee.LastName + employee.JobTitle, retrievedEmployee.FirstName + retrievedEmployee.LastName + retrievedEmployee.JobTitle); } }