Exemplo n.º 1
0
        public async Task <ActionResult> UpdateMessage(int id, UpdateMessageDTO updateMessage)
        {
            var updatingUser = _userService.Load(updateMessage.UserId);

            if (updatingUser == null)
            {
                return(NotFound(new { message = Errors.UserNotFound }));
            }

            //Load message
            var message = _messageService.Load(id);

            if (message == null)
            {
                return(NotFound(new { message = Errors.MessageNotFound }));
            }

            if (!string.IsNullOrEmpty(updateMessage.Body))
            {
                message.Body = updateMessage.Body;
            }

            await _messageService.Update(id, message);

            var conversation = _conversationService.Load(message.ConversationId, false, true, false, false);

            var usersToSendUpdatedMessage = conversation.Users.Where(x => x.UserId != updateMessage.UserId).Select(x => x.UserId.ToString()).ToList();

            //Send object to users
            await _chatHub.Clients.Users(usersToSendUpdatedMessage).SendAsync("MessageUpdated", message);

            return(Ok(message));
        }
Exemplo n.º 2
0
        public async Task Update(UpdateMessageDTO dto, CancellationToken cancel)
        {
            var newMessage = await _repository.Update(dto.ToEntity(), cancel);

            await _hubContext.Clients.Group(newMessage.RoomId.ToString())
            .SendAsync("MessageUpdated", newMessage);
        }
Exemplo n.º 3
0
 public static Message ToEntity(this UpdateMessageDTO dto)
 {
     return(new Message
     {
         Id = dto.Id,
         Content = dto.Content
     });
 }
Exemplo n.º 4
0
        public async Task MessageUpdate_HappyPath()
        {
            var dto = new CreateMessageDTO
            {
                Content = "Hello",
                RoomId  = StaticData.PublicRoomId,
                UserId  = StaticData.TestUserId
            };
            var message = await _handler.Create(dto, CancellationToken.None);

            var updateDto = new UpdateMessageDTO
            {
                Id      = message.Id,
                Content = "Hello world!",
            };

            await _handler.Update(updateDto, CancellationToken.None);

            var dataFromDb = await Context.Messages.SingleAsync(x => x.Id == message.Id);

            Assert.AreEqual(dataFromDb.Content, updateDto.Content);

            await DeleteDatabase();
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Update([FromBody] UpdateMessageDTO dto)
        {
            await _handler.Update(dto, HttpContext.RequestAborted);

            return(Ok());
        }