コード例 #1
0
ファイル: DataLayer.cs プロジェクト: jmrgn/AsyncTesting
        public async Task<Employee> GetEmployeeById(int id)
        {
            Employee employee = null;
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"select  e.id as employeeId, p.id as personId, p.Name, e.EmployeeNumber, p.Description from Employees as e inner join 
                                            People as p on e.PersonId = p.id where p.id=@id";

                    await connection.OpenAsync();

                    command.Parameters.Add(new SqlParameter("@id", id));

                    var reader = await command.ExecuteReaderAsync();
                    while (await reader.ReadAsync())
                    {
                        employee = new Employee()
                        {
                            Id = reader.Get<int>("employeeId"),
                            EmployeeNumber = reader.ReadString("EmployeeNumber"),
                            Person = new Person()
                            {
                                Id = reader.Get<int>("personId"), 
                                Description = reader.ReadString("Description"),
                                Name = reader.ReadString("Name") 
                            }
                        };
                    }
                    reader.Close();
                }
                connection.Close();
            }

            return employee;
        }
コード例 #2
0
ファイル: DataLayer.cs プロジェクト: jmrgn/AsyncTesting
        /// <summary>
        /// EVERYOOOOOOOOONE!
        /// https://www.youtube.com/watch?v=MrTsuvykUZk
        /// </summary>
        /// <returns></returns>
        public async Task<List<Employee>> GetEveryone()
        {
            var everyone = new List<Employee>();
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"select  e.id as employeeId, p.id as personId, p.Name, e.EmployeeNumber, p.Description from Employees as e inner join 
                                            People as p on e.PersonId = p.id";

                    await connection.OpenAsync();
                    var reader = await command.ExecuteReaderAsync();
                    while (await reader.ReadAsync())
                    {
                        var employee = new Employee()
                        {
                            Id = reader.Get<int>("employeeId"),
                            EmployeeNumber = reader.ReadString("EmployeeNumber"),
                            Person = new Person()
                            {
                                Id = reader.Get<int>("personId"),
                                Description = reader.ReadString("Description"),
                                Name = reader.ReadString("Name")
                            }
                        };
                        everyone.Add(employee);
                    }
                    reader.Close();
                }
                connection.Close();
            }
          return everyone;
        }
コード例 #3
0
 public Employee GetStubEmployee()
 {
     var stubbedEmployee = new Employee();
     stubbedEmployee.Id = 1;
     stubbedEmployee.EmployeeNumber = "12345";
     stubbedEmployee.Person = new Person()
     {
         Name = "Test Name",
         Id = 1,
         Description = "A Test Description"
     };
     return stubbedEmployee; 
 }