deletions update
This commit is contained in:
parent
6f8ef78577
commit
7bbcd07c39
10 changed files with 71 additions and 22 deletions
|
|
@ -0,0 +1,49 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Repositories;
|
||||
using SurveyLib.Infrastructure.EFCore.Data;
|
||||
|
||||
namespace SurveyLib.Infrastructure.EFCore.Repositories;
|
||||
|
||||
public class AnswerVariantsRepository : IAnswerVariantsRepository
|
||||
{
|
||||
private readonly SurveyDbContext _context;
|
||||
|
||||
public AnswerVariantsRepository(SurveyDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<AnswerVariant?> GetByIdAsync(int id)
|
||||
{
|
||||
return await _context.AnswerVariants.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AnswerVariant>> GetAllAsync()
|
||||
{
|
||||
return await _context.AnswerVariants.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task AddAsync(AnswerVariant entity)
|
||||
{
|
||||
await _context.AnswerVariants.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(AnswerVariant entity)
|
||||
{
|
||||
_context.AnswerVariants.Update(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
await _context.AnswerVariants.Where(av => av.Id == id).ExecuteDeleteAsync();
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AnswerVariant>> GetAnswerVariantsByQuestionIdAsync(int questionId)
|
||||
{
|
||||
return await _context.AnswerVariants.Where(av => av.QuestionId == questionId).ToListAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue