예제 #1
0
        protected DbTestsBase()
        {
            _connection = new SqliteConnection(InMemoryConnectionString);
            _connection.Open();
            var options = new DbContextOptionsBuilder <EmployeeContactsContext>()
                          .UseSqlite(_connection)
                          .Options;

            DbContext = new EmployeeContactsContext(options);
            DbContext.Database.EnsureCreated();

            DepartmentManager = new DepartmentManager(DbContext);
            EmployeeManager   = new EmployeeManager(DbContext);
        }
 public DepartmentManager(EmployeeContactsContext context)
 {
     _context = context;
 }
 public EmployeeController(EmployeeContactsContext context)
 {
     _context     = context;
     _employeeMgr = new EmployeeManager(_context);
     _deptMgr     = new DepartmentManager(_context);
 }
예제 #4
0
        private static void EnsureDatabaseIsSeeded(EmployeeContactsContext context)
        {
            if (!context.Departments.Any())
            {
                var hr = new Department
                {
                    Id             = 1,
                    DepartmentName = "Human Resources"
                };

                var finance = new Department
                {
                    Id             = 2,
                    DepartmentName = "Finance"
                };

                context.Departments.Add(hr);
                context.Departments.Add(finance);
                context.SaveChanges();

                var employee1 = new Employee
                {
                    Id           = 1,
                    DepartmentId = hr.Id,
                    FirstName    = "Mike",
                    LastName     = "Jones",
                    Title        = "HR Representitive",
                    Email        = "*****@*****.**",
                    Phone        = "555-123-4567"
                };

                var employee2 = new Employee
                {
                    Id           = 2,
                    DepartmentId = hr.Id,
                    FirstName    = "Jane",
                    LastName     = "Smith",
                    Title        = "HR Manager",
                    Email        = "*****@*****.**",
                    Phone        = "555-123-1111"
                };

                var employee3 = new Employee
                {
                    Id           = 3,
                    DepartmentId = finance.Id,
                    FirstName    = "Hector",
                    LastName     = "Flores",
                    Title        = "CPA",
                    Email        = "*****@*****.**",
                    Phone        = "555-123-2222"
                };

                var employee4 = new Employee
                {
                    Id           = 4,
                    DepartmentId = finance.Id,
                    FirstName    = "Emily",
                    LastName     = "Radnor",
                    Title        = "CPA",
                    Email        = "*****@*****.**",
                    Phone        = "555-123-4444"
                };

                var employee5 = new Employee
                {
                    Id           = 5,
                    DepartmentId = finance.Id,
                    FirstName    = "Sarah",
                    LastName     = "Jackson",
                    Title        = "CPA Intern",
                    Email        = "*****@*****.**",
                    Phone        = "555-123-5555"
                };

                context.Employees.Add(employee1);
                context.Employees.Add(employee2);
                context.Employees.Add(employee3);
                context.Employees.Add(employee4);
                context.Employees.Add(employee5);
                context.SaveChanges();
            }
        }
예제 #5
0
 public EmployeeManager(EmployeeContactsContext context)
 {
     _context = context;
 }