public JsonResult History_Chat(string UserID, string msg) { F_History_Chat fhc = new F_History_Chat(); //get history_chat with id=1, because we save it only 1 row with id=1 var row_upd = fhc.GetSingleByCondition(x => x.id_chat_history == 1); row_upd.list_id_User += UserID + "/"; row_upd.list_msg += msg + "/*space*/"; fhc.Update(row_upd); return(Json("Update to database success")); }
public ActionResult Chat_Group() { //if have cookies if (Request.Cookies["usercredentials"] != null) { HttpCookie reqCookie = Request.Cookies["usercredentials"]; // ViewBag.Name = reqCookie["UserID"].ToString(); ViewBag.Name = getNickName(Convert.ToInt32(reqCookie["UserID"].ToString())); ViewBag.UserID = Convert.ToInt32(reqCookie["UserID"].ToString()); } else //if not have cookies { ViewBag.Name = getNickName(Convert.ToInt32(Session["UserID"].ToString())); ViewBag.UserID = Convert.ToInt32(Session["UserID"].ToString()); } //get list user id and list chat to show in group chat F_History_Chat fhc = new F_History_Chat(); var row_upd = fhc.GetSingleByCondition(x => x.id_chat_history == 1); var list_id = row_upd.list_id_User; var list_msg = row_upd.list_msg; //split string to per msg string[] msg_split = list_msg.ToString().Split(new string[] { "/*space*/" }, StringSplitOptions.None); string[] id_split = list_id.ToString().Split('/'); List <History_Chat> list_chat = new List <History_Chat>(); for (int i = 0; i < msg_split.Count() - 1; i++) { History_Chat hc = new History_Chat(); hc.idUser = Convert.ToInt32(id_split[i]); hc.NickName = getNickName(Convert.ToInt32(id_split[i])); hc.msg = msg_split[i]; list_chat.Add(hc); //list_chat.Add(getNickName(Convert.ToInt32(id_split[i]))+": "+ msg_split[i]); } ViewBag.list_chat = list_chat; return(View()); }