60 lines
No EOL
1.6 KiB
C#
60 lines
No EOL
1.6 KiB
C#
using SurveyLib.Core.Models;
|
|
using SurveyLib.Core.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SurveyLib.Infrastructure.EFCore.Data;
|
|
|
|
namespace SurveyLib.Infrastructure.EFCore.Repositories;
|
|
|
|
public class AnswerRepository : IAnswerRepository
|
|
{
|
|
private readonly SurveyDbContext _context;
|
|
|
|
public AnswerRepository(SurveyDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<Answer?> GetByIdAsync(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<IEnumerable<Answer>> GetAllAsync()
|
|
{
|
|
return await _context.Answers.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(Answer entity)
|
|
{
|
|
await _context.Answers.AddAsync(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task UpdateAsync(Answer entity)
|
|
{
|
|
_context.Answers.Update(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task DeleteAsync(int questionId, int completionId)
|
|
{
|
|
await _context.Answers.Where(a => a.QuestionId == questionId && a.CompletionId == completionId)
|
|
.ExecuteDeleteAsync();
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<Answer>> GetAnswersByCompletionIdAsync(int completionId)
|
|
{
|
|
return await _context.Answers.Where(a => a.CompletionId == completionId).ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<Answer>> GetAnswersByQuestionIdAsync(int questionId)
|
|
{
|
|
return await _context.Answers.Where(a => a.QuestionId == questionId).ToListAsync();
|
|
}
|
|
} |