Created
November 13, 2015 12:36
-
-
Save guntidheerajkumar/872625b3e43a708d7d83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IEmployee | |
{ | |
List<EmployeeData> GetAllEmployees(); | |
EmployeeData GetEmployeeById(int EmpId); | |
bool InsertEmployee(EmployeeData emp); | |
bool UpdateEmployee(EmployeeData emp); | |
bool DeleteEmployee(int EmpId); | |
} | |
public class Employee : IEmployee | |
{ | |
private EmployeeContext dbContext = new EmployeeContext(); | |
public List<EmployeeData> GetAllEmployees() | |
{ | |
var data = (from c in dbContext.EmployeeData | |
select c).ToList(); | |
return data; | |
} | |
public EmployeeData GetEmployeeById(int EmpId) | |
{ | |
var data = (from c in dbContext.EmployeeData | |
where c.EmpId == EmpId | |
select c).FirstOrDefault(); | |
return data; | |
} | |
public bool InsertEmployee(EmployeeData emp) | |
{ | |
dbContext.EmployeeData.Add(emp); | |
if (dbContext.SaveChanges() > 0) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
public bool UpdateEmployee(EmployeeData emp) | |
{ | |
var data = (from c in dbContext.EmployeeData where c.EmpId == emp.EmpId select c).FirstOrDefault(); | |
data.EmpName = emp.EmpName; | |
data.DOB = emp.DOB; | |
if (dbContext.SaveChanges() > 0) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
public bool DeleteEmployee(int EmpId) | |
{ | |
var data = (from c in dbContext.EmployeeData where c.EmpId == EmpId select c).FirstOrDefault(); | |
dbContext.EmployeeData.Remove(data); | |
if (dbContext.SaveChanges() > 0) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment