added basic services

This commit is contained in:
Вячеслав 2025-04-16 18:04:55 +05:00
parent 3e570decd7
commit 6e8d6cebdd
6 changed files with 100 additions and 12 deletions

View file

@ -0,0 +1,46 @@
using SurveyLib.Core.Models;
using SurveyLib.Core.Repositories;
using SurveyLib.Core.Services;
namespace SurveyLib.Infrastructure.EFCore.Services;
public class SurveyService : ISurveyService
{
private readonly ISurveyRepository _surveyRepository;
public SurveyService(ISurveyRepository surveyRepository)
{
_surveyRepository = surveyRepository;
}
public async Task AddSurveyAsync(Survey survey)
{
await _surveyRepository.AddAsync(survey);
}
public async Task UpdateSurveyAsync(Survey survey)
{
await _surveyRepository.UpdateAsync(survey);
}
public async Task DeleteSurveyAsync(int id)
{
var survey = await _surveyRepository.GetByIdAsync(id);
if (survey == null)
{
throw new NullReferenceException($"Survey with id: {id} was not found");
}
await _surveyRepository.DeleteAsync(survey);
}
public async Task<IEnumerable<Survey>> GetSurveysAsync()
{
return await _surveyRepository.GetAllAsync();
}
public async Task<Survey?> GetSurveyAsync(int id)
{
return await _surveyRepository.GetByIdAsync(id);
}
}