source: src/FinkiChattery/FinkiChattery.Persistence/Repositories/Implementations/VoteRepo.cs@ ad079e5

dev
Last change on this file since ad079e5 was ad079e5, checked in by Стојков Марко <mst@…>, 3 years ago

Vote answer endpoint

  • Property mode set to 100644
File size: 1.3 KB
Line 
1using FinkiChattery.Persistence.Context;
2using FinkiChattery.Persistence.Helpers;
3using FinkiChattery.Persistence.Models;
4using Microsoft.EntityFrameworkCore;
5using System;
6using System.Linq;
7using System.Threading.Tasks;
8
9namespace FinkiChattery.Persistence.Repositories
10{
11 public class VoteRepo : Repository<Vote>, IVoteRepo
12 {
13 public VoteRepo(ApplicationDbContext dbContext) : base(dbContext)
14 {
15 }
16
17 public async Task<Vote> GetVoteForAnswerByStudent(Guid answerUid, long userId)
18 {
19 return await DbSet
20 .Where(x => x.Answer.Uid == answerUid && x.Student.ApplicationUserFk == userId)
21 .FirstOrDefaultAsync();
22 }
23
24 public async Task<bool> StudentHasDownvotedAnswer(Guid answerUid, long userId)
25 {
26 return await DbSet
27 .AsNoTracking()
28 .Where(x => x.Answer.Uid == answerUid && x.VoteType == VoteType.Downvote && x.Student.ApplicationUserFk == userId)
29 .AnyAsync();
30 }
31
32 public async Task<bool> StudentHasUpvotedAnswer(Guid answerUid, long userId)
33 {
34 return await DbSet
35 .AsNoTracking()
36 .Where(x => x.Answer.Uid == answerUid && x.VoteType == VoteType.Upvote && x.Student.ApplicationUserFk == userId)
37 .AnyAsync();
38 }
39 }
40}
Note: See TracBrowser for help on using the repository browser.