surveylib/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs
2025-04-01 16:29:30 +05:00

49 lines
No EOL
1.3 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 CompletionRepository : ICompletionRepository
{
private readonly DataContext _context;
public CompletionRepository(DataContext context)
{
_context = context;
}
public async Task<Completion?> GetByIdAsync(int id)
{
return await _context.Completions.FindAsync(id);
}
public async Task<IEnumerable<Completion>> 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<IEnumerable<Completion>> GetBySurveyIdAsync(int surveyId)
{
return await _context.Completions.Where(c => c.SurveyId == surveyId).ToListAsync();
}
}