C
C#•4d ago
zos

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!
5 Replies
daye
daye•4d ago
What happens when you set a breakpoint and step through it? Does it fail in the CreateChannelMessageAsync or before? What's the error?
zos
zosOP•4d ago
nevermind, i fixed it, forgot to restart the project LOL
daye
daye•4d ago
lmao happens, glad you figured it out 😌
canton7
canton7•4d ago
$close
MODiX
MODiX•4d ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?