public IActionResult Create(Message m) { AcademyChatContext acc = new AcademyChatContext(); acc.Message.Add(m); acc.SaveChanges(); return(View()); }
public IActionResult Create(Message m) { m.SendTime = DateTime.Now; db.Message.Add(m); db.SaveChanges(); var msg = (from mes in db.Message where mes.PrivateMessage == false orderby mes.SendTime descending select mes).ToList(); return(View("index", msg)); }
public async Task SendMessage(string user, string message) { //messagen talletus db:hen tähän AcademyChatContext db = new AcademyChatContext(); DateTime tempTime = DateTime.Now; await Clients.All.SendAsync("ReceiveMessage", user, message, tempTime); var sender = (from s in db.Person where s.NickName == user select s).FirstOrDefault(); Message m = new Message(); m.FromPerson = sender; m.Subject = "testisubject"; m.MessageText = message; m.SendTime = tempTime; m.PrivateMessage = false; db.Message.Add(m); db.SaveChanges(); }