-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetEmployees.cs
45 lines (39 loc) · 1.27 KB
/
GetEmployees.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace SampleWebAPI.Models.DBRepository
{
using SampleWebAPI;
using System.Collections.Generic;
using System.Linq;
public class GetEmployees : IGetEmployees
{
IList<EmployeeModel> emp = null;
public IList<EmployeeModel> getAllEmployees()
{
using (var ctx = new SampleDBEntities())
{
emp = ctx.Employees.Select(s => new EmployeeModel()
{
id = s.ID,
name = s.Name,
department = s.Department,
salary = s.Salary
}).ToList<EmployeeModel>();
}
return emp;
}
public IList<EmployeeModel> getEmployeeById(int id)
{
IList<EmployeeModel> emp = null;
using (var ctx = new SampleDBEntities())
{
emp = ctx.Employees.Where(x => x.ID == id).Select(s => new EmployeeModel()
{
id = s.ID,
name = s.Name,
department = s.Department,
salary = s.Salary
}).ToList<EmployeeModel>();
}
return emp;
}
}
}