//tämän metodin pitää palauttaa message view + tuo viewBagissa ViewBag.NickName:n public IActionResult Index(LoginDetails log) { try { AcademyChatContext db = new AcademyChatContext(); //var hashedPw = log.Password.GetHashCode(); //hashia ei käytetty loginiin vielä koska db:n hash ei ole sama kuin GetHashCode() Person user; if (ModelState.IsValid) { //hakee rivin db:stä jossa nickname ja password on samat kuin käyttäjän syöttämät ja palauttaa null jos ei matchaa user = (from u in db.Person where u.NickName == log.Name && u.Password == log.Password select u).FirstOrDefault(); if (user != null) { ViewBag.NickName = user.NickName; HttpContext.Session.SetString("Nickname", user.NickName); return(RedirectToAction("Index", "Message")); } } return(Content("username of password incorrect")); } catch (Exception e) { Console.WriteLine(e); return(Content("login error")); } }
public IActionResult Read() { AcademyChatContext acc = new AcademyChatContext(); var m = (from b in acc.Message select b).ToList().First(); return(View(m)); }
public IActionResult Create(Message m) { AcademyChatContext acc = new AcademyChatContext(); acc.Message.Add(m); acc.SaveChanges(); return(View()); }
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(); }