Example #1
0
        private async Task UpdateRating(UpdatingOperation updatingInfo,
                                        VoteChangeViewModel voteChange)
        {
            var votesAmountToAdd = GetVotesAmountToAdd(voteChange);

            await Collection.UpdateOneAsync(updatingInfo.Filter,
                                            UpdateBuilder.Inc(updatingInfo.ModelHierarchy + "." + nameof(IVotable.Rating).ToLower(),
                                                              votesAmountToAdd),
                                            updatingInfo.Options);
        }
Example #2
0
        private async Task UpdateUserInVotersLists(UpdatingOperation updatingInfo,
                                                   VoteChangeViewModel voteChange)
        {
            await Collection.UpdateOneAsync(updatingInfo.Filter,
                                            UpdateBuilder.Pull(updatingInfo.ModelHierarchy + "." + nameof(IVotable.Upvoters).ToLower(), UserId),
                                            updatingInfo.Options);

            await Collection.UpdateOneAsync(updatingInfo.Filter,
                                            UpdateBuilder.Pull(updatingInfo.ModelHierarchy + "." + nameof(IVotable.Downvoters).ToLower(), UserId),
                                            updatingInfo.Options);

            if (voteChange.NewDirection != voteChange.PreviousDirection)
            {
                await Collection.UpdateOneAsync(updatingInfo.Filter,
                                                UpdateBuilder.AddToSet(updatingInfo.ModelHierarchy + "." + GetVotersListName(voteChange.NewDirection).ToLower(), UserId),
                                                updatingInfo.Options);
            }
        }
Example #3
0
 private int GetVotesAmountToAdd(VoteChangeViewModel voteChange)
 {
     return(voteChange.NewDirection == voteChange.PreviousDirection
             ? (int)voteChange.NewDirection * -1
             : voteChange.NewDirection - voteChange.PreviousDirection);
 }