44 lines
No EOL
1.1 KiB
C#
44 lines
No EOL
1.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SurveyLib.Core.Models;
|
|
using SurveyLib.Core.Repositories;
|
|
using SurveyLib.Infrastructure.EFCore.Data;
|
|
|
|
namespace SurveyLib.Infrastructure.EFCore.Repositories;
|
|
|
|
public class SurveyRepository : ISurveyRepository
|
|
{
|
|
private readonly SurveyDbContext _context;
|
|
|
|
public SurveyRepository(SurveyDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<Survey?> GetByIdAsync(int id)
|
|
{
|
|
return await _context.Surveys.FindAsync(id);
|
|
}
|
|
|
|
public async Task<IEnumerable<Survey>> GetAllAsync()
|
|
{
|
|
return await _context.Surveys.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(Survey entity)
|
|
{
|
|
await _context.Surveys.AddAsync(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task UpdateAsync(Survey entity)
|
|
{
|
|
_context.Surveys.Update(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(Survey entity)
|
|
{
|
|
_context.Surveys.Remove(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
} |