completed QuestionRepository.cs

small readability fixes for SurveyRepository.cs
This commit is contained in:
Вячеслав 2025-03-14 23:15:33 +05:00
parent 960a6ce191
commit 62facb3423
2 changed files with 23 additions and 16 deletions

View file

@ -1,3 +1,4 @@
using Microsoft.EntityFrameworkCore;
using SurveyLib.Core.Models;
using SurveyLib.Core.Repositories;
using SurveyLib.Infrastructure.EFCore.Data;
@ -13,38 +14,42 @@ public class QuestionRepository : IQuestionRepository
_context = context;
}
public Task<QuestionBase?> GetByIdAsync(int id)
public async Task<QuestionBase?> GetByIdAsync(int id)
{
throw new NotImplementedException();
return await _context.Questions.FirstOrDefaultAsync(q => q.Id == id);
}
public Task<IEnumerable<QuestionBase>> GetAllAsync()
public async Task<IEnumerable<QuestionBase>> GetAllAsync()
{
throw new NotImplementedException();
return await _context.Questions.ToListAsync();
}
public Task AddAsync(QuestionBase entity)
public async Task AddAsync(QuestionBase entity)
{
throw new NotImplementedException();
await _context.Questions.AddAsync(entity);
await _context.SaveChangesAsync();
}
public Task UpdateAsync(QuestionBase entity)
public async Task UpdateAsync(QuestionBase entity)
{
throw new NotImplementedException();
_context.Questions.Update(entity);
await _context.SaveChangesAsync();
}
public Task DeleteAsync(QuestionBase entity)
public async Task DeleteAsync(QuestionBase entity)
{
throw new NotImplementedException();
_context.Questions.Remove(entity);
await _context.SaveChangesAsync();
}
public Task<QuestionBase?> GetWithAnswersAsync(int questionId)
public async Task<QuestionBase?> GetWithAnswersAsync(int questionId)
{
throw new NotImplementedException();
return await _context.Questions.Include(q => q.Answers)
.FirstOrDefaultAsync(q => q.Id == questionId);
}
public Task<IEnumerable<QuestionBase>> GetBySurveyIdAsync(int surveyId)
public async Task<IEnumerable<QuestionBase>> GetBySurveyIdAsync(int surveyId)
{
throw new NotImplementedException();
return await _context.Questions.Where(q => q.SurveyId == surveyId).ToListAsync();
}
}