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.1 KB
|
Line | |
---|
1 | using FinkiChattery.Common.User;
|
---|
2 | using FinkiChattery.Persistence.UnitOfWork;
|
---|
3 | using FluentValidation.Validators;
|
---|
4 | using System.Threading;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 |
|
---|
7 | namespace FinkiChattery.Commands.Questioning.Validators
|
---|
8 | {
|
---|
9 | public class StudentHasGoodReputationAndCanVoteAndAnswer : AsyncValidatorBase
|
---|
10 | {
|
---|
11 | public StudentHasGoodReputationAndCanVoteAndAnswer(IUnitOfWork unitOfWork, ICurrentUser currentUser)
|
---|
12 | {
|
---|
13 | UnitOfWork = unitOfWork;
|
---|
14 | CurrentUser = currentUser;
|
---|
15 | }
|
---|
16 |
|
---|
17 | public IUnitOfWork UnitOfWork { get; }
|
---|
18 | public ICurrentUser CurrentUser { get; }
|
---|
19 |
|
---|
20 | protected override async Task<bool> IsValidAsync(PropertyValidatorContext context, CancellationToken cancellation)
|
---|
21 | {
|
---|
22 | var student = await UnitOfWork.Students.GetStudent(CurrentUser.Id);
|
---|
23 |
|
---|
24 | if (student.ReportReputation > 100)
|
---|
25 | {
|
---|
26 | return false;
|
---|
27 | }
|
---|
28 |
|
---|
29 | return true;
|
---|
30 | }
|
---|
31 |
|
---|
32 | protected override string GetDefaultMessageTemplate()
|
---|
33 | {
|
---|
34 | return QuestioningErrorCodes.StudentHasBadReputation;
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.