added basic services
This commit is contained in:
parent
3e570decd7
commit
6e8d6cebdd
6 changed files with 100 additions and 12 deletions
43
SurveyLib.Infrastructure.EFCore/Services/QuestionService.cs
Normal file
43
SurveyLib.Infrastructure.EFCore/Services/QuestionService.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Repositories;
|
||||
using SurveyLib.Core.Services;
|
||||
|
||||
namespace SurveyLib.Infrastructure.EFCore.Services;
|
||||
|
||||
public class QuestionService : IQuestionService
|
||||
{
|
||||
private readonly IQuestionRepository _questionRepository;
|
||||
|
||||
public QuestionService(IQuestionRepository questionRepository)
|
||||
{
|
||||
_questionRepository = questionRepository;
|
||||
}
|
||||
|
||||
public async Task AddQuestionAsync(QuestionBase question)
|
||||
{
|
||||
await _questionRepository.AddAsync(question);
|
||||
}
|
||||
|
||||
public async Task UpdateQuestionAsync(QuestionBase question)
|
||||
{
|
||||
await _questionRepository.UpdateAsync(question);
|
||||
}
|
||||
|
||||
public async Task DeleteQuestionAsync(int id)
|
||||
{
|
||||
var question = await GetQuestionByIdAsync(id);
|
||||
|
||||
await _questionRepository.DeleteAsync(question);
|
||||
}
|
||||
|
||||
public async Task<QuestionBase> GetQuestionByIdAsync(int id)
|
||||
{
|
||||
var question = await _questionRepository.GetByIdAsync(id) ?? throw new NullReferenceException();
|
||||
return question;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<QuestionBase>> GetQuestionsBySurveyIdAsync(int surveyId)
|
||||
{
|
||||
return await _questionRepository.GetQuestionsBySurveyId(surveyId);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue