public async Task <IActionResult> GetMessageUser(int userid, [FromQuery] MessageParamsDto query) { try { if (userid != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } query.UserID = userid; var messages = await _datingrepo.GetMessagesForUser(query); var result = _mapper.Map <IEnumerable <MessageReturnDto> >(messages); Response.AddPaginationHeader(messages.TotalCount, messages.TotalPages, messages.PageSize, messages.CurrentPage); return(Ok(result)); } catch (Exception ex) { throw new Exception("Error while fetching user messages"); } }
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 messageFromRepo = await _repo.GetMessagesForUser(messageParams); var messages = _mapper.Map <IEnumerable <MessageReturnDto> >(messageFromRepo); Response.AddPagation(messageFromRepo.CurrPage, messageFromRepo.PageSizes, messageFromRepo.TotalCount, messageFromRepo.totalPage); return(Ok(messages)); }