diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs index e33eba6..bef9e48 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs @@ -1,3 +1,4 @@ +using Microsoft.EntityFrameworkCore; using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; using SurveyLib.Infrastructure.EFCore.Data; @@ -13,33 +14,36 @@ public class CompletionRepository : ICompletionRepository _context = context; } - public Task GetByIdAsync(int id) + public async Task GetByIdAsync(int id) { - throw new NotImplementedException(); + return await _context.Completions.FirstOrDefaultAsync(c => c.Id == id); } - public Task> GetAllAsync() + public async Task> GetAllAsync() { - throw new NotImplementedException(); + return await _context.Completions.ToListAsync(); } - public Task AddAsync(Completion entity) + public async Task AddAsync(Completion entity) { - throw new NotImplementedException(); + await _context.Completions.AddAsync(entity); + await _context.SaveChangesAsync(); } - public Task UpdateAsync(Completion entity) + public async Task UpdateAsync(Completion entity) { - throw new NotImplementedException(); + _context.Completions.Update(entity); + await _context.SaveChangesAsync(); } - public Task DeleteAsync(Completion entity) + public async Task DeleteAsync(Completion entity) { - throw new NotImplementedException(); + _context.Completions.Remove(entity); + await _context.SaveChangesAsync(); } - public Task> GetBySurveyIdAsync(int surveyId) + public async Task> GetBySurveyIdAsync(int surveyId) { - throw new NotImplementedException(); + return await _context.Completions.Where(c => c.SurveyId == surveyId).ToListAsync(); } } \ No newline at end of file