dev
Last change
on this file since fcc3080 was fcc3080, checked in by Стојков Марко <mst@…>, 3 years ago |
Fixed bug when voting an answer
|
-
Property mode
set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | using FinkiChattery.Commands.Questioning;
|
---|
2 | using FinkiChattery.Common.Mediator.Contracs;
|
---|
3 | using FinkiChattery.Persistence.Helpers;
|
---|
4 | using FinkiChattery.Persistence.UnitOfWork;
|
---|
5 | using System.Threading;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace FinkiChattery.Api.ApplicationServices.Questioning.EventHandlers
|
---|
9 | {
|
---|
10 | public class UpdateAnswerVotesEventHandler : IEventHandler<AnswerVotedEvent>
|
---|
11 | {
|
---|
12 | public UpdateAnswerVotesEventHandler(IUnitOfWork unitOfWork)
|
---|
13 | {
|
---|
14 | UnitOfWork = unitOfWork;
|
---|
15 | }
|
---|
16 |
|
---|
17 | public IUnitOfWork UnitOfWork { get; }
|
---|
18 |
|
---|
19 | public async Task Handle(AnswerVotedEvent notification, CancellationToken cancellationToken)
|
---|
20 | {
|
---|
21 | var answer = await UnitOfWork.Answers.GetByUidAsync(notification.AnswerUid);
|
---|
22 |
|
---|
23 | if (answer == null)
|
---|
24 | {
|
---|
25 | return;
|
---|
26 | }
|
---|
27 |
|
---|
28 | switch (notification.VoteType)
|
---|
29 | {
|
---|
30 | case VoteType.Upvote:
|
---|
31 | answer.VotesCount++;
|
---|
32 |
|
---|
33 | if (notification.VoteAlreadyExists)
|
---|
34 | {
|
---|
35 | answer.VotesCount++;
|
---|
36 | }
|
---|
37 | break;
|
---|
38 | case VoteType.Downvote:
|
---|
39 | answer.VotesCount--;
|
---|
40 | if (notification.VoteAlreadyExists)
|
---|
41 | {
|
---|
42 | answer.VotesCount--;
|
---|
43 | }
|
---|
44 | break;
|
---|
45 | }
|
---|
46 |
|
---|
47 | await UnitOfWork.SaveAsync();
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.