Skip to content

Instantly share code, notes, and snippets.

@JIOO-phoeNIX
Created January 2, 2021 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JIOO-phoeNIX/f31ef9d7e85b08ebbb2f596a84bdbb50 to your computer and use it in GitHub Desktop.
Save JIOO-phoeNIX/f31ef9d7e85b08ebbb2f596a84bdbb50 to your computer and use it in GitHub Desktop.
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 DepartmentRepository
{
private readonly SampleAppDbContext _sampleAppDbContext;
public DepartmentRepository(SampleAppDbContext sampleAppDbContext)
{
_sampleAppDbContext = sampleAppDbContext;
}
public List<Department> GetAllDepartmentOnly()
{
return _sampleAppDbContext.Department.ToList();
}
public List<Department> GetAllDepartmentsWithEmployee()
{
return _sampleAppDbContext.Department
.Include(d => d.Employees)
.ToList();
}
public async Task<Department> CreateDepartment(Department department)
{
await _sampleAppDbContext.Department.AddAsync(department);
await _sampleAppDbContext.SaveChangesAsync();
return department;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment