示例#1
0
        public async Task <IActionResult> HandleUserFeedbackAsync([FromBody] UserFeedbackRequest feedback)
        {
            try
            {
                _logger.LogInformation("Trying to post user feedback");
                var currentUserId = GetCurrentUserId();
                await _statisticsBusiness.RegisterUserFeedback(currentUserId, feedback.Rating);

                return(NoContent());
            }
            catch (ShouldAssertException ex)
            {
                _logger.LogWarning(ex, "Bad request while posting feedback");
                return(BadRequest());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An unexpected Error occured while posting user feedback.");
                return(StatusCode(500));
            }
        }
示例#2
0
        public async Task <IActionResult> Post([FromBody] UserFeedbackRequest request)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                _logger.LogInformation($"User with name: {User.Identity.Name} was not found.");
                return(StatusCode((int)HttpStatusCode.NotFound,
                                  new ErrorResponse(ErrorReasons.NotFound, "User was not found.")));
            }

            var feedback = new UserFeedbackEntry
            {
                User    = user,
                Message = request.Message,
                Rating  = request.Rating
            };

            await _repository.Insert(feedback);

            return(StatusCode((int)HttpStatusCode.NoContent));
        }