surveylib/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs

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 QuestionRepository : IQuestionRepository
{
private readonly SurveyDbContext _context;
public QuestionRepository(SurveyDbContext context)
{
_context = context;
}
public async Task<QuestionBase?> GetByIdAsync(int id)
{
return await _context.Questions.FindAsync(id);
}
public async Task<IEnumerable<QuestionBase>> GetAllAsync()
{
return await _context.Questions.ToListAsync();
}
public async Task AddAsync(QuestionBase entity)
{
await _context.Questions.AddAsync(entity);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(QuestionBase entity)
{
_context.Questions.Update(entity);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(QuestionBase entity)
{
_context.Questions.Remove(entity);
await _context.SaveChangesAsync();
}
}