コード例 #1
0
        public async Task <IActionResult> GetMessagesForUser(int userId, [FromQuery] MessageParams messageParams)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            messageParams.UserId = userId;
            var messagesFromRepo = await _repo.GetMessagesForUser(messageParams);

            var messagesToReturn = _mapper.Map <IEnumerable <MessageToReturnDto> >(messagesFromRepo);

            Response.AddPagination(messageParams.PageNumber, messageParams.PageSize, messagesFromRepo.TotalPages, messagesFromRepo.TotalItems);

            return(Ok(messagesToReturn));
        }