using Microsoft.EntityFrameworkCore; using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class CompletionRepository : ICompletionRepository { private readonly DataContext _context; public CompletionRepository(DataContext context) { _context = context; } public async Task GetByIdAsync(int id) { return await _context.Completions.FirstOrDefaultAsync(c => c.Id == id); } public async Task> GetAllAsync() { return await _context.Completions.ToListAsync(); } public async Task AddAsync(Completion entity) { await _context.Completions.AddAsync(entity); await _context.SaveChangesAsync(); } public async Task UpdateAsync(Completion entity) { _context.Completions.Update(entity); await _context.SaveChangesAsync(); } public async Task DeleteAsync(Completion entity) { _context.Completions.Remove(entity); await _context.SaveChangesAsync(); } public async Task> GetBySurveyIdAsync(int surveyId) { return await _context.Completions.Where(c => c.SurveyId == surveyId).ToListAsync(); } }