completed SurveyRepository.cs
This commit is contained in:
parent
7d06084dfb
commit
960a6ce191
6 changed files with 27 additions and 21 deletions
|
|
@ -1,8 +1,10 @@
|
|||
using SurveyLib.Core.Models;
|
||||
|
||||
namespace SurveyLib.Core.Repositories;
|
||||
|
||||
public interface IGenericRepository<T> where T : class
|
||||
{
|
||||
Task<T>? GetByIdAsync(int id);
|
||||
Task<T?> GetByIdAsync(int id);
|
||||
Task<IEnumerable<T>> GetAllAsync();
|
||||
Task AddAsync(T entity);
|
||||
Task UpdateAsync(T entity);
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ public interface ISurveyRepository : IGenericRepository<Survey>
|
|||
{
|
||||
Task<Survey?> GetWithQuestionsAsync(int surveyId);
|
||||
Task<Survey?> GetWithCompletionsAsync(int surveyId);
|
||||
Task<Survey?> FindByTitleAsync(string title);
|
||||
Task<IEnumerable<Survey>> FindByTitleAsync(string title);
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ public class AnswerRepository : IAnswerRepository
|
|||
_context = context;
|
||||
}
|
||||
|
||||
public Task<Answer>? GetByIdAsync(int id)
|
||||
public Task<Answer?> GetByIdAsync(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class CompletionRepository : ICompletionRepository
|
|||
_context = context;
|
||||
}
|
||||
|
||||
public Task<Completion>? GetByIdAsync(int id)
|
||||
public Task<Completion?> GetByIdAsync(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class QuestionRepository : IQuestionRepository
|
|||
_context = context;
|
||||
}
|
||||
|
||||
public Task<QuestionBase>? GetByIdAsync(int id)
|
||||
public Task<QuestionBase?> GetByIdAsync(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Repositories;
|
||||
using SurveyLib.Infrastructure.EFCore.Data;
|
||||
|
|
@ -13,43 +14,46 @@ public class SurveyRepository : ISurveyRepository
|
|||
_context = context;
|
||||
}
|
||||
|
||||
public Task<Survey>? GetByIdAsync(int id)
|
||||
public async Task<Survey?> GetByIdAsync(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return await _context.Surveys.FirstOrDefaultAsync(s => s.Id == id);
|
||||
}
|
||||
|
||||
public Task<IEnumerable<Survey>> GetAllAsync()
|
||||
public async Task<IEnumerable<Survey>> GetAllAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return await _context.Surveys.ToListAsync();
|
||||
}
|
||||
|
||||
public Task AddAsync(Survey entity)
|
||||
public async Task AddAsync(Survey entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
await _context.Surveys.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public Task UpdateAsync(Survey entity)
|
||||
public async Task UpdateAsync(Survey entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_context.Surveys.Update(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public Task DeleteAsync(Survey entity)
|
||||
public async Task DeleteAsync(Survey entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_context.Surveys.Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public Task<Survey?> GetWithQuestionsAsync(int surveyId)
|
||||
public async Task<Survey?> GetWithQuestionsAsync(int surveyId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return await _context.Surveys.Include(survey => survey.Questions).FirstOrDefaultAsync(s => s.Id == surveyId);
|
||||
}
|
||||
|
||||
public Task<Survey?> GetWithCompletionsAsync(int surveyId)
|
||||
public async Task<Survey?> GetWithCompletionsAsync(int surveyId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return await _context.Surveys.Include(survey => survey.Completions).FirstOrDefaultAsync(s => s.Id == surveyId);
|
||||
}
|
||||
|
||||
public Task<Survey?> FindByTitleAsync(string title)
|
||||
public async Task<IEnumerable<Survey>> FindByTitleAsync(string title)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return await _context.Surveys.Where(s => s.Title.ToLower().Contains(title.ToLower())).ToListAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue