Skip to content

Commit a2f4011

Browse files
authored
Update DepartmentDAL.cs
1 parent c17aa70 commit a2f4011

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

AdventureData/DAL/DepartmentDAL.cs

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
1-
using AdventureData.Models;
1+
using AdventureData.Models;
22
using Microsoft.Extensions.Configuration;
33
using System;
44
using System.Collections.Generic;
55
using System.Data;
66
using System.Data.SqlClient;
77

8+
89
namespace AdventureData.DAL
910
{
1011
public class DepartmentDAL
1112
{
1213
private readonly IConfiguration _configuration;
14+
private readonly string _connectionString;
1315
public DepartmentDAL(IConfiguration configuration)
1416
{
1517
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;
1649
}
1750
}
1851
}
52+

0 commit comments

Comments
 (0)