Пример #1
0
 public static void Insert(Employee employee)
 {
     using (var context = new SoftUniContext())
     {
         context.Employees.Add(employee);
         context.SaveChanges();
     }
 }
Пример #2
0
 public static void Delete(Employee employee)
 {
     using (var context = new SoftUniContext())
     {
         Employee employeeToDelete = context.Employees.Find(employee.EmployeeID);
         context.Employees.Remove(employeeToDelete);
         context.SaveChanges();
     }
 }
Пример #3
0
 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();
     }
 }
Пример #4
0
        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);
            }
        }