-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnswerRepository.cs
More file actions
68 lines (53 loc) · 1.77 KB
/
AnswerRepository.cs
File metadata and controls
68 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Microsoft.EntityFrameworkCore;
using Questionare.models;
namespace Questionare.Repositories
{
public class AnswerRepository : IAnswerRepository
{
private readonly AppDbContext _context;
public AnswerRepository(AppDbContext context)
{
_context = context;
}
public async Task<IEnumerable<Answer>> GetAllAnswersAsync()
{
return await _context.Answers.ToListAsync();
}
public async Task<Answer> GetAnswerByIdAsync(int id)
{
return await _context.Answers.FindAsync(id);
}
public async Task<Answer> CreateAnswerAsync(Answer answer)
{
await _context.Answers.AddAsync(answer);
await _context.SaveChangesAsync();
return answer;
}
public async Task UpdateAnswerAsync(Option answer)
{
_context.Entry(answer).State = EntityState.Modified;
await _context.SaveChangesAsync();
}
public async Task DeleteAnswerAsync(int id)
{
var answer = await _context.Answers.FindAsync(id);
if (answer != null)
{
answer.IsDeleted = true;
await _context.SaveChangesAsync();
}
}
public async Task<bool> QuestionExists(int questionId)
{
return await _context.Questions.AnyAsync(q => q.QuestionId == questionId);
}
public async Task<bool> OptionExists(int questionId, int optionId)
{
return await _context.Options.AnyAsync(o => o.OptionId == optionId && o.QuestionId == questionId);
}
public Task UpdateAnswerAsync(Answer answer)
{
throw new NotImplementedException();
}
}
}