Ejemplo n.º 1
0
        public async Task <IActionResult> GetMessageThread(int userId, int recipientId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var messagesFromRepo = await _repo.GetMessageThread(userId, recipientId);

            foreach (var message in messagesFromRepo)
            {
                if (message.IsRead == false && message.RecipientId == userId)
                {
                    message.IsRead   = true;
                    message.DateRead = DateTime.Now;
                }
            }
            await _repo.SaveAll();

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

            return(Ok(messageThread));
        }