public JsonResult HaalChatOp(int userId1, int userId2) { var sql = new ChatSqlContext(); var chatRepo = new ChatRepository(sql); return(Json(chatRepo.GetChatByUsers(userId1, userId2))); }
//GET : Chat/{AnderegebruikerId} public ActionResult ChatScherm(string id) { if (!AuthRepository.CheckIfUserCanAcces(GebruikerType.All, (Gebruiker)Session["LoggedInUser"])) { return(View("~/Views/Error/AuthError.cshtml")); } try { GebruikerSqlContext gsc = new GebruikerSqlContext(); GebruikerRepository gr = new GebruikerRepository(gsc); var sql = new ChatSqlContext(); var chatRepo = new ChatRepository(sql); Gebruiker loggedInUser = (Gebruiker)Session["LoggedInUser"]; // Gebruiker loggedInUser = gr.GetById(1); ViewBag.LoggedInUser = loggedInUser; ViewBag.Gebruikers = gr.GetAll(); ViewBag.EnableChat = "true"; return(View("~/Views/Chat/Index.cshtml")); } catch (Exception e) { return(RedirectToAction("Index", "Error")); } }
public void TestGetAllChat() { var sql = new ChatSqlContext(); var repo = new ChatRepository(sql); repo.GetAll(); Assert.AreEqual(1, repo.GetAll()[0].Auteur.Id); }
public void TestChatByGebruikerId() { var sql = new ChatSqlContext(); var repo = new ChatRepository(sql); List <Chat> Chatberichten = repo.GetChatByUsers(4, 1); Assert.IsTrue(Chatberichten.Count == 4); Assert.IsTrue(Chatberichten[0].Id == 2); Assert.IsTrue(Chatberichten[3].Id == 5); }
public void TestCreateChat() { var sql = new ChatSqlContext(); var repo = new ChatRepository(sql); var gsql = new GebruikerSqlContext(); var grepo = new GebruikerRepository(gsql); var g1 = grepo.GetById(1); var g2 = grepo.GetById(4); var chat = new Chat(g1, g2, DateTime.Now, "Hallo jongens"); repo.Create(chat); }
public JsonResult SendChatMessage(int autheurId, int ontvangerId, string bericht) { GebruikerSqlContext gsc = new GebruikerSqlContext(); GebruikerRepository gr = new GebruikerRepository(gsc); var sql = new ChatSqlContext(); var chatRepo = new ChatRepository(sql); Gebruiker auteur = gr.GetById(autheurId); Gebruiker ontvanger = gr.GetById(ontvangerId); Chat nieuwBericht = new Chat(auteur, ontvanger, DateTime.Now, bericht); chatRepo.Create(nieuwBericht); return(null); }
//Get: Beheerder/Chat public ActionResult Chat(FormCollection f) { GebruikerSqlContext gsc = new GebruikerSqlContext(); GebruikerRepository gr = new GebruikerRepository(gsc); ChatSqlContext csc = new ChatSqlContext(); ChatRepository cr = new ChatRepository(csc); List <Gebruiker> users = gr.GetAll(); int id1 = Convert.ToInt32(f["user1"]); int id2 = Convert.ToInt32(f["user2"]); if (id1 != 0 && id2 != 0 && (id1 != id2)) { List <Chat> chat = cr.GetChatByUsers(id1, id2); string chatString = ""; if (chat.Count > 0) { for (int i = 0; i < chat.Count; i++) { chatString = chatString + chat[i].Auteur.Naam + " | " + chat[i].Bericht + "\r"; } ViewBag.Chatstring = chatString; } else { ViewBag.Chatstring = "Geen chat gevonden"; } } else { ViewBag.Chatstring = ""; } ViewBag.Users = users; return(View("~/Views/Chat/Beheer.cshtml")); }