File tree 1 file changed +35
-1
lines changed
1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
- using AdventureData . Models ;
1
+ using AdventureData . Models ;
2
2
using Microsoft . Extensions . Configuration ;
3
3
using System ;
4
4
using System . Collections . Generic ;
5
5
using System . Data ;
6
6
using System . Data . SqlClient ;
7
7
8
+
8
9
namespace AdventureData . DAL
9
10
{
10
11
public class DepartmentDAL
11
12
{
12
13
private readonly IConfiguration _configuration ;
14
+ private readonly string _connectionString ;
13
15
public DepartmentDAL ( IConfiguration configuration )
14
16
{
15
17
this . _configuration = configuration ;
18
+ this . _connectionString = this . _configuration . GetConnectionString ( "Default" ) ;
19
+ }
20
+
21
+ public List < department > GetAllDepartments ( )
22
+ {
23
+ var lstDepartments = new List < department > ( ) ;
24
+ try
25
+ {
26
+ using ( SqlConnection con = new SqlConnection ( _connectionString ) )
27
+ {
28
+ SqlCommand cmd = new SqlCommand ( "SELECT * FROM [HumanResources].[Department]" , con ) ;
29
+ cmd . CommandType = CommandType . Text ;
30
+ con . Open ( ) ;
31
+ SqlDataReader rdr = cmd . ExecuteReader ( ) ;
32
+ while ( rdr . Read ( ) )
33
+ {
34
+ lstDepartments . Add ( new department
35
+ {
36
+ DepartmentID = rdr . GetInt16 ( "DepartmentID" ) ,
37
+ Name = rdr . GetString ( "Name" ) ,
38
+ GroupName = rdr . GetString ( "GroupName" ) ,
39
+ ModifiedDate = rdr . GetDateTime ( "ModifiedDate" )
40
+ } ) ;
41
+ }
42
+ }
43
+ }
44
+ catch ( Exception ex )
45
+ {
46
+ throw ex ;
47
+ }
48
+ return lstDepartments ;
16
49
}
17
50
}
18
51
}
52
+
You can’t perform that action at this time.
0 commit comments