-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDatabaseModel.cs
88 lines (85 loc) · 2.82 KB
/
TestDatabaseModel.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using EntityFrameworkTest;
using System.Collections.Generic;
using System.Linq;
public class CrudEmployee
{
public List<Employee> getEmployees()
{
using (var context = new TestDataBaseEntities())
{
var eList = context.Employees.ToList<Employee>();
return eList;
}
}
public void displayEmployees()
{
using(var context = new TestDataBaseEntities())
{
var eList = context.Employees.ToList<Employee>();
foreach (var employee in eList)
{
System.Console.WriteLine(employee.empNo + "\t"+employee.empName+"\t"+employee.dsgn);
}
}
}
public void findEmployees(Employee e)
{
using (var context = new TestDataBaseEntities())
{
List<Employee> eList = (from employee in context.Employees where employee.empName == e.empName select employee).ToList<Employee>();
//var tet = from emp in context.Employees select emp;
}
}
public void addEmployee(Employee employee)
{
using (var context = new TestDataBaseEntities())
{
var eList = context.Employees.ToList<Employee>();
context.Employees.Add(employee);
context.SaveChanges();
}
}
public void updateEmployee(Employee employee)
{
using(var context = new TestDataBaseEntities())
{
var emp = context.Employees.Find(employee.empNo);
if(emp != null)
{
emp.empName = employee.empName;
emp.salary = employee.salary;
emp.mgrEmpNo = employee.mgrEmpNo;
emp.dob = employee.dob;
emp.doj = employee.doj;
emp.dptCode = employee.dptCode;
context.SaveChanges();
}else
System.Console.WriteLine("No such employee found.");
}
}
public void deleteEmployee(Employee employee)
{
using (var context = new TestDataBaseEntities())
{
var emp = context.Employees.Find(employee.empNo);
if(emp == null)
{
System.Console.WriteLine("Object not found.");
}
else
{
System.Console.WriteLine(emp.empName);
context.Employees.Remove(emp);
context.SaveChanges();
}
}
}
}