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)); }
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); }
public static Message ToEntity(this UpdateMessageDTO dto) { return(new Message { Id = dto.Id, Content = dto.Content }); }
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(); }
public async Task <IActionResult> Update([FromBody] UpdateMessageDTO dto) { await _handler.Update(dto, HttpContext.RequestAborted); return(Ok()); }