public ActionResult loadChat(int conID) { chatModel m = new chatModel(); dbUtils db = new dbUtils(); ArrayList[] data; string sql = "select con_userID,con_contactID,con_starter from CONVERSATIONS where con_id=" + conID; try { data = db.fetch(sql, 3); } catch (Exception) { throw; } string userID = data[0][0].ToString(), contactID = data[1][0].ToString(); int starter = (Int32)data[2][0]; dbUtils db2 = new dbUtils(); ArrayList[] data2; string sql2; if (starter == 1) { sql2 = "select userOneMess,userTwoMess,messDate from [" + userID + "_AND_" + contactID + "]"; } else { sql2 = "select userOneMess,userTwoMess,messDate from [" + contactID + "_AND_" + userID + "]"; } try { data2 = db2.fetch(sql2, 3); } catch (Exception) { throw; } sql = "update CONVERSATIONS set con_notifications = 0 where con_id=" + conID; try { db.Update(sql); } catch (Exception) { throw; } m.userOneMess = data2[0]; m.userTwoMess = data2[1]; m.date = data2[2]; m.starter = starter; m.conID = conID; return(PartialView("chatHistory", m)); }
public MessengerModel getConversations(MessengerModel m) { dbUtils db = new dbUtils(); string sql = "select con_id, con_contactID ,con_notifications,con_starter from CONVERSATIONS where con_userID =" + m.userId; ArrayList[] data = new ArrayList[4]; data = db.fetch(sql, 4); m.consId = data[0]; var con = new SOCIALMEDIA_DBEntities(); foreach (int contactID in data[1]) { m.conversations.Add(con.USERS.Find(contactID)); } m.notifications = data[2]; m.starter = data[3]; return(m); }
public void sendMessage(string m, int conID) { dbUtils db = new dbUtils(); ArrayList[] data; string sql = "select con_userID,con_contactID,con_starter from CONVERSATIONS where con_id=" + conID; data = db.fetch(sql, 3); string userID = data[0][0].ToString(), contactID = data[1][0].ToString(); int starter = (Int32)data[2][0]; dbUtils db2 = new dbUtils(); string sql2, date; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); date = DateTime.Now.ToString(); ArrayList[] param = new ArrayList[2]; param[0] = new ArrayList(); param[1] = new ArrayList(); param[0].Add("@msg"); param[1].Add(m); if (starter == 1) { sql2 = "insert into [" + userID + "_AND_" + contactID + "] (userOneMess,userTwoMess,messDate) values (@msg,'','" + date + "')"; } else { sql2 = "insert into [" + contactID + "_AND_" + userID + "] (userOneMess,userTwoMess,messDate) values ('',@msg,'" + date + "')"; } try { db2.create(sql2, param); } catch (Exception) { } sql = "update CONVERSATIONS set con_notifications = con_notifications + 1 where con_userID=" + contactID + " and con_contactID=" + userID; try { db.Update(sql); } catch (Exception) { throw; } }