zos
zos
Explore posts from servers
CC#
Created by zos on 3/29/2025 in #help
How to save signalR chat messages to database
public async Task SendChannelMessage(string channelId, string content, List<IFormFile> attachments = null)
{
var authorId = Context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var result = await messageRepository.CreateChannelMessageAsync(authorId, channelId, content, attachments);

if (!result.Success)
{
await Clients.User(authorId).SendAsync("UploadError", result.Message);
return;
}

await Clients.Group(channelId).SendAsync("ReceiveChannelMessage", content);
}
public async Task SendChannelMessage(string channelId, string content, List<IFormFile> attachments = null)
{
var authorId = Context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var result = await messageRepository.CreateChannelMessageAsync(authorId, channelId, content, attachments);

if (!result.Success)
{
await Clients.User(authorId).SendAsync("UploadError", result.Message);
return;
}

await Clients.Group(channelId).SendAsync("ReceiveChannelMessage", content);
}
the method CreateChannelMessageAsync just add the message to the database, but somehow when I call it from my FE project, it just skip through it. Any help is strongly appreciated!
6 replies