Created
January 2, 2021 07:16
-
-
Save JIOO-phoeNIX/aa7823d55e832cf505ad3f4956de8bed to your computer and use it in GitHub Desktop.
This file contains 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
using GraphQLSampleApp.DataAccess.Entity; | |
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace GraphQLSampleApp.DataAccess.DAO | |
{ | |
public class EmployeeRepository | |
{ | |
private readonly SampleAppDbContext _sampleAppDbContext; | |
public EmployeeRepository(SampleAppDbContext sampleAppDbContext) | |
{ | |
_sampleAppDbContext = sampleAppDbContext; | |
} | |
public List<Employee> GetEmployees() | |
{ | |
return _sampleAppDbContext.Employee.ToList(); | |
} | |
public Employee GetEmployeeById(int id) | |
{ | |
var employee = _sampleAppDbContext.Employee | |
.Include(e => e.Department) | |
.Where(e => e.EmployeeId == id) | |
.FirstOrDefault(); | |
if (employee != null) | |
return employee; | |
return null; | |
} | |
public List<Employee> GetEmployeesWithDepartment() | |
{ | |
return _sampleAppDbContext.Employee | |
.Include(e => e.Department) | |
.ToList(); | |
} | |
public async Task<Employee> CreateEmployee(Employee employee) | |
{ | |
await _sampleAppDbContext.Employee.AddAsync(employee); | |
await _sampleAppDbContext.SaveChangesAsync(); | |
return employee; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment