public async Task HandleAsync(RemarkVoteSubmitted @event)
 {
     await _handler
     .Run(async() =>
     {
         var vote = @event.Positive
                 ? Vote.CreatePositiveVote(@event.UserId, @event.RemarkId)
                 : Vote.CreateNegativeVote(@event.UserId, @event.RemarkId);
         await _remarkStatisticsRepository.AddVoteAsync(vote);
         await _userStatisticsRepository.AddVoteAsync(vote);
     })
     .OnError((ex, logger) => logger.Debug(ex, $"Error while handling {@event.GetType().Name} event"))
     .ExecuteAsync();
 }
コード例 #2
0
 public async Task HandleAsync(RemarkVoteDeleted @event)
 {
     await _handler
     .Run(async() =>
     {
         var votes = await _remarkStatisticsRepository.BrowseVotesAsync(new BrowseRemarkVotes
         {
             Page     = 1,
             Results  = int.MaxValue,
             RemarkId = @event.RemarkId
         });
         if (votes.HasValue)
         {
             var originalVote = votes.Value.Items
                                .LastOrDefault(x => x.UserId == @event.UserId);
             var vote = Vote.CreateDeletedVote(originalVote);
             await _remarkStatisticsRepository.AddVoteAsync(vote);
         }
     })
     .OnError((ex, logger) => logger.Debug(ex,
                                           $"Error while handling {@event.GetType().Name} event in remark statistics"))
     .Next()
     .Run(async() =>
     {
         var votes = await _userStatisticsRepository.BrowseVotesAsync(new BrowseUserVotes
         {
             Page    = 1,
             Results = int.MaxValue,
             UserId  = @event.UserId
         });
         if (votes.HasValue)
         {
             var originalVote = votes.Value.Items
                                .LastOrDefault(x => x.RemarkId == @event.RemarkId);
             var vote = Vote.CreateDeletedVote(originalVote);
             await _userStatisticsRepository.AddVoteAsync(vote);
         }
     })
     .OnError((ex, logger) => logger.Debug(ex,
                                           $"Error while handling {@event.GetType().Name} event in user statistics"))
     .Next()
     .ExecuteAllAsync();
 }