public async Task <LikingDto> DislikeAsync(string id)
        {
            var likeRecord = await _likeRecordRepository.FindAsync(id);

            if (likeRecord == null)
            {
                likeRecord = new LikeRecord(id)
                {
                    DislikeCount = 1
                };

                await _likeRecordRepository.InsertAsync(likeRecord);
            }
            else
            {
                likeRecord.DislikeCount++;
                await _likeRecordRepository.UpdateAsync(likeRecord);
            }

            return(new LikingDto
            {
                LikeCount = likeRecord.LikeCount,
                DislikeCount = likeRecord.DislikeCount
            });
        }
Example #2
0
        public User AddRecord(LikeRecordModel model)
        {
            User owner = null;

            _likeRecordRepository.UseTransaction(() =>
            {
                var record = new LikeRecord(UserId, model.QuestionId, model.AnswerId);
                _likeRecordRepository.Add(record);
                _likeRecordRepository.SaveChanges();

                // Add reputation value to answer owner
                owner = _questionRepository.GetAnswerOwner(model.AnswerId);
                if (owner == null)
                {
                    throw new DefinedException(GetLocalizedResource(ErrorDefinitions.User.UserNotFound));
                }

                owner.UserScores.IncreaseReputation((int)ReputationTypeDefinition.Liked,
                                                    new LikedReputationRule().IncreasingValue, model.QuestionId); // use questionId here to add log, then the log will be '您关于XX问题的回答获得了好评'
                _userRepository.SaveChanges();
            });

            return(owner);
        }