예제 #1
0
        public async Task <IActionResult> GiveReviewForUser([FromBody] GiveReviewForUserRequest giveReviewForUserRequest)
        {
            try
            {
                var id   = HttpContext.User.FindFirst(ClaimTypes.Email).Value;
                var user = await _userManager.FindByEmailAsync(id);

                var reviewUser = await _userManager.FindByIdAsync(giveReviewForUserRequest.OwnerId);

                if (user == null)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, "Wrong User"));
                }

                if (reviewUser == null)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, "User does not exist"));
                }

                await _userCommand.GiveUserReviewCommand(giveReviewForUserRequest, user.Id, _userManager);

                return(Ok(new
                {
                    Success = true,
                    Message = "Success fully added review."
                }));
            }
            catch (Exception e)
            {
                _logger.LogError($"error while changing profile for user: {e}");
                return(StatusCode((int)HttpStatusCode.InternalServerError, "error while changing profile for user"));
            }
        }
예제 #2
0
        public async Task GiveUserReviewCommand(GiveReviewForUserRequest request, string userId, UserManager <UserModel> userManager)
        {
            try
            {
                var user = await userManager.FindByIdAsync(request.OwnerId);

                var userReviewOwner = await userManager.FindByIdAsync(userId);

                var review = new UserReview()
                {
                    ReviewDate        = DateTime.Now,
                    ReviewDescription = request.ReviewDescription,
                    UserRefId         = user.Id,
                    ReviewOwnerRefId  = userId,
                    ReviewTitle       = request.ReviewTitle,
                    UpVoteNum         = Convert.ToString(request.UpVotePoints),
                    ReviewUsername    = userReviewOwner.UserName
                };


                await _userRepository.AddUserReview(review);

                user.UpVote += request.UpVotePoints;

                await userManager.UpdateAsync(user);
            }
            catch (Exception ex)
            {
                _logger.LogError($"error while saving user review to database: {ex}");
                throw ex.GetBaseException();
            }
        }