54 lines
No EOL
1.5 KiB
C#
54 lines
No EOL
1.5 KiB
C#
using SurveyBackend.Core.Contexts;
|
|
using SurveyBackend.Services.Exceptions;
|
|
using SurveyLib.Core.Models;
|
|
using SurveyLib.Core.Repositories;
|
|
using SurveyLib.Core.Services;
|
|
|
|
namespace SurveyBackend.Services.Services;
|
|
|
|
public class QuestionService : IQuestionService
|
|
{
|
|
private readonly IQuestionRepository _questionRepository;
|
|
|
|
public QuestionService(IQuestionRepository questionRepository, IUserContext userContext)
|
|
{
|
|
_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 _questionRepository.GetByIdAsync(id);
|
|
if (question is null)
|
|
{
|
|
throw new NotFoundException("Question not found");
|
|
}
|
|
|
|
await _questionRepository.DeleteAsync(question);
|
|
}
|
|
|
|
public async Task<QuestionBase> GetQuestionByIdAsync(int id)
|
|
{
|
|
var question = await _questionRepository.GetByIdAsync(id);
|
|
if (question is null)
|
|
{
|
|
throw new NotFoundException("Question not found");
|
|
}
|
|
|
|
return question;
|
|
}
|
|
|
|
public async Task<IEnumerable<QuestionBase>> GetQuestionsBySurveyIdAsync(int surveyId)
|
|
{
|
|
return await _questionRepository.GetQuestionsBySurveyId(surveyId);
|
|
}
|
|
} |