49 lines
No EOL
1.4 KiB
C#
49 lines
No EOL
1.4 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 SurveyDbContext _context;
|
|
|
|
public CompletionRepository(SurveyDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<Completion?> GetByIdAsync(int id)
|
|
{
|
|
return await _context.Completions.Include(c => c.Answers).FirstOrDefaultAsync(c => c.Id == 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(int id)
|
|
{
|
|
await _context.Completions.Where(c => c.Id == id).ExecuteDeleteAsync();
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<Completion>> GetCompletionsBySurveyIdAsync(int surveyId)
|
|
{
|
|
return await _context.Completions.Where(c => c.SurveyId == surveyId).ToListAsync();
|
|
}
|
|
} |