Ejemplo n.º 1
0
        public async Task <IActionResult> GetMessageForUser(int userId,
                                                            [FromQuery] MessageParams messageParams)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            messageParams.UserId = userId;

            var messageFromRepo = await _repo.GetMessageForUser(messageParams);

            var messages = _mapper.Map <IEnumerable <MessageToReturnDTO> >(messageFromRepo);

            Response.AddPagination(messageFromRepo.CurrentPage, messageFromRepo.PageSize,
                                   messageFromRepo.TotalCount, messageFromRepo.TotalPages);

            return(Ok(messages));
        }