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 GetByIdAsync(int id) { return await _context.Questions.FindAsync(id); } public async Task> 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(); } public async Task> GetQuestionsBySurveyId(int surveyId) { return await _context.Questions.Include(q => q.AnswerVariants).Where(q => q.SurveyId == surveyId).ToListAsync(); } }