Пример #1
0
        public void DeleteLike(int userId, int postId)
        {
            var targetLike = _likesRepository.GetFirstWhere(x => x.UserId == userId && x.PostId == postId);

            if (targetLike == null)
            {
                throw new FlowException("Like not found!");
            }

            _likesRepository.Remove(targetLike);
            _likesRepository.SaveEntities();
        }
Пример #2
0
        public async Task <ApiResponse <LikeResponseDto> > DisLikePost(DisLikeRequestDto disLikeRequest)
        {
            ApiResponse <LikeResponseDto> result = new ApiResponse <LikeResponseDto>();
            var resultMessage = "";

            // To Dislike a PostId previously liked, the Like record saved to Db is
            // Deleted from Db

            try
            {
                Likes like = await GetLikeToDisLike(disLikeRequest.PostId,
                                                    disLikeRequest.ClientReferenceId, disLikeRequest.RequestUsername);

                if (like == null)
                {
                    resultMessage = "Could not fetch Like to Dislike";
                    _logger.LogInformation(resultMessage);
                    throw new AppException(resultMessage);
                }

                _likeRepository.Remove(like);
                await _unitOfWork.CompleteAsync();

                resultMessage = $"Successfully dislike PostId: {disLikeRequest.PostId}";

                result.Message = resultMessage;
                result.Status  = Helpers.ApiReponseStatusCodes.Success;
                result.Data    = null;

                return(result);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, ex.StackTrace);
                _logger.Log(LogLevel.Error, ex.Message);

                throw new AppException(ex.Message);
            }
        }