completed QuestionRepository.cs
small readability fixes for SurveyRepository.cs
This commit is contained in:
parent
960a6ce191
commit
62facb3423
2 changed files with 23 additions and 16 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using SurveyLib.Core.Models;
|
using SurveyLib.Core.Models;
|
||||||
using SurveyLib.Core.Repositories;
|
using SurveyLib.Core.Repositories;
|
||||||
using SurveyLib.Infrastructure.EFCore.Data;
|
using SurveyLib.Infrastructure.EFCore.Data;
|
||||||
|
|
@ -13,38 +14,42 @@ public class QuestionRepository : IQuestionRepository
|
||||||
_context = context;
|
_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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,12 +44,14 @@ public class SurveyRepository : ISurveyRepository
|
||||||
|
|
||||||
public async Task<Survey?> GetWithQuestionsAsync(int surveyId)
|
public async Task<Survey?> GetWithQuestionsAsync(int surveyId)
|
||||||
{
|
{
|
||||||
return await _context.Surveys.Include(survey => survey.Questions).FirstOrDefaultAsync(s => s.Id == surveyId);
|
return await _context.Surveys.Include(survey => survey.Questions)
|
||||||
|
.FirstOrDefaultAsync(s => s.Id == surveyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Survey?> GetWithCompletionsAsync(int surveyId)
|
public async Task<Survey?> GetWithCompletionsAsync(int surveyId)
|
||||||
{
|
{
|
||||||
return await _context.Surveys.Include(survey => survey.Completions).FirstOrDefaultAsync(s => s.Id == surveyId);
|
return await _context.Surveys.Include(survey => survey.Completions)
|
||||||
|
.FirstOrDefaultAsync(s => s.Id == surveyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Survey>> FindByTitleAsync(string title)
|
public async Task<IEnumerable<Survey>> FindByTitleAsync(string title)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue