Ejemplo n.º 1
0
 public void WriteDepartment(Department department)
 {
     _databaseExecutor.Execute(cmd =>
     {
         cmd.CommandText = "insert into Departments (Id, Name) values ($Id, $Name)";
         AddParameter(cmd, "$Id", department.Id.ToByteArray());
         AddParameter(cmd, "$Name", department.Name);
         cmd.ExecuteNonQuery();
     });
 }
Ejemplo n.º 2
0
 public void WriteEmployee(Employee employee)
 {
     _databaseExecutor.Execute(cmd =>
     {
         cmd.CommandText = "insert into Employees (Id, DepartmentId, FirstName, LastName) values ($Id, $DepartmentId, $FirstName, $LastName)";
         AddParameter(cmd, "$Id", employee.Id.ToByteArray());
         AddParameter(cmd, "$DepartmentId", employee.DepartmentId.ToByteArray());
         AddParameter(cmd, "$FirstName", employee.FirstName);
         AddParameter(cmd, "$LastName", employee.LastName);
         cmd.ExecuteNonQuery();
     });
 }
Ejemplo n.º 3
0
 public Department[] ReadAllDepartments()
 {
     return(_databaseExecutor.Execute(cmd =>
     {
         cmd.CommandText = "select Id, Name from Departments";
         using (var reader = cmd.ExecuteReader())
         {
             var result = new List <Department>();
             while (reader.Read())
             {
                 var dep = new Department()
                 {
                     Id = new Guid((byte[])reader["Id"]),
                     Name = (string)reader["Name"],
                 };
                 result.Add(dep);
             }
             return result.ToArray();
         }
     }));
 }
Ejemplo n.º 4
0
 public Employee[] ReadAllEmployees()
 {
     return(_databaseExecutor.Execute(cmd =>
     {
         cmd.CommandText = "select Id, FirstName, LastName, DepartmentId from Employees";
         using (var reader = cmd.ExecuteReader())
         {
             var result = new List <Employee>();
             while (reader.Read())
             {
                 var emp = new Employee()
                 {
                     Id = new Guid((byte[])reader["Id"]),
                     FirstName = (string)reader["FirstName"],
                     LastName = (string)reader["LastName"],
                     //SupervisorId = new Guid((byte[]) reader["SupervisorId"]),
                     DepartmentId = new Guid((byte[])reader["DepartmentId"]),
                 };
                 result.Add(emp);
             }
             return result.ToArray();
         }
     }));
 }