dfgsdfdfgsdfdfgsdfdfgsdf

This commit is contained in:
Alex
2023-05-20 20:28:51 +02:00
parent dc0b504114
commit c5d43489de
18 changed files with 237 additions and 159 deletions

View File

@@ -1,24 +1,9 @@
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
namespace LiveChat.Server.Hubs;
public class ChatHub : Hub
{
private readonly ChattingContext _context;
public override async Task OnConnectedAsync()
{
using (var db = new ChattingContext())
{
var messages = db.Messages.ToList();
messages.ForEach(Console.WriteLine);
// Send the messages to the caller
await Clients.Caller.SendAsync("ReceiveMessages", messages);
}
}
public async Task SendMessage(string user, string message)
{
using (var db = new ChattingContext())
@@ -28,9 +13,7 @@ public class ChatHub : Hub
User = user,
Message = message,
};
Console.WriteLine(messageData);
var dbSave = db.Messages.Add(messageData);
Console.WriteLine(dbSave);
await Clients.All.SendAsync("ReceiveMessage", user, message);
db.SaveChanges();
}