public async Task <IActionResult> Put(int id, UpdateMessageVM model) { var message = await _messagesService.UpdateAsync(id, model); if (message != null) { await _hub.Clients.All.SendAsync("UpdateOne", message); } return(Ok()); }
public async Task <MessageVM> UpdateAsync(int id, UpdateMessageVM model) { var message = await _db.Messages.FirstOrDefaultAsync(x => x.Id == id); if (message != null) { message.Text = model.Text; message.UpdatedAt = DateTime.Now; await _db.SaveChangesAsync(); return(new MessageVM { Id = message.Id, Text = message.Text, UserName = message.UserName, UserId = message.UserId, UpdatedAt = message.UpdatedAt, IsDeleted = message.IsDeleted }); } return(null); }