Ejemplo n.º 1
0
        public chatModel getContactsByAdminid(int adminId)
        {
            chatModel           _item   = new chatModel();
            List <chatitem>     item    = new List <Models.chatitem>();
            List <msgItem>      msgItem = new List <Models.msgItem>();
            Global              _global = new Database.Global();
            CRMClassDataContext _idc    = new Database.CRMClassDataContext(_global.con);

            try
            {
                int selected = 0;
                var contacts = _idc.tblcontacts.Where(a => a.AdminId == adminId && a.IsActive == true).OrderByDescending(a => a.ContactId).ToList();
                foreach (var i in contacts)
                {
                    chatitem tem = new chatitem();
                    tem.id    = i.ContactId;
                    tem.image = string.IsNullOrEmpty(i.ImagePath) ? "/assets/images/icon/staff.png" : i.ImagePath;
                    tem.name  = i.Name;
                    selected  = selected == 0 ? i.ContactId : selected;
                    item.Add(tem);
                }
                _item.selectedId = selected;
                _item.chatList   = item;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                _idc.Dispose();
            }
            return(_item);
        }
Ejemplo n.º 2
0
 public ActionResult Chat(chatModel modelVal)
 {
     if (ModelState.IsValid)
     {
         /*
          * Start session using email *
          * grab current time and date, join with email to make unique filename *
          * create chat log file *
          * create first line in chat, indicating user has entered chat *
          * return as partial view *
          *
          */
         Session["email"] = modelVal.email;
         DateTime date       = DateTime.Now;
         string   fileName   = date.ToString() + Session["email"].ToString();
         string   fileString = fileName.Replace(" ", "").Replace("@", "_").Replace("/", "_").Replace(":", "_");
         Session["log"] = fileString;
         string filePath = Server.MapPath("~/chatLogs/" + fileString + ".txt");
         objChat.makeChat(Session["email"].ToString(), fileString, date, filePath);
         string firstLine = date.ToString("yyyy-MM-dd hh:mm:ss tt") + " <em><b>(" + Session["email"].ToString() + ")</b> " + " has entered chat.</em><br />";
         objChat.writeChat(firstLine, filePath);
         return(PartialView());
     }
     else
     {
         /*
          * If validation fails, return to index
          * */
         return(Index());
     }
 }
        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));
        }
Ejemplo n.º 4
0
        public chatModel getChatByContactId(int contactId, int adminId, int maxId)
        {
            chatModel       _item   = new chatModel();
            List <chatitem> item    = new List <Models.chatitem>();
            List <msgItem>  msgItem = new List <Models.msgItem>();
            Global          _global = new Database.Global();

            try
            {
                string         image     = "/assets/images/icon/staff.png";
                SqlParameter[] sqlParams = new SqlParameter[] {
                    new SqlParameter("@ContactId", contactId),
                    new SqlParameter("@adminId", adminId),
                    new SqlParameter("@maxId", maxId)
                };
                bool isAdmin      = false;
                var  dt           = SqlHelper.ExecuteDataset(_global.con, System.Data.CommandType.StoredProcedure, "GetChatById2", sqlParams).Tables[0];
                var  contactImage = "";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    msgItem tem = new msgItem();
                    isAdmin = Convert.ToBoolean(dt.Rows[i]["IsRead"].ToString());

                    tem.userId    = contactId;
                    contactImage  = string.IsNullOrEmpty(dt.Rows[i]["AdminImage"].ToString()) ? "/assets/images/icon/staff.png" : dt.Rows[i]["AdminImage"].ToString();
                    tem.sender    = Convert.ToInt16(dt.Rows[i]["sender"].ToString());
                    tem.message   = dt.Rows[i]["Body"].ToString();
                    tem.messageId = Convert.ToInt16(dt.Rows[i]["MsgId"].ToString());
                    tem.Image     = isAdmin ? contactImage : string.IsNullOrEmpty(dt.Rows[i]["ImagePath"].ToString()) ? image : dt.Rows[i]["ImagePath"].ToString();
                    tem.Name      = isAdmin ? dt.Rows[i]["AdminName"].ToString() : dt.Rows[i]["Name"].ToString();
                    tem.Time      = Convert.ToDateTime(dt.Rows[i]["CreatedDate"].ToString()).ToString("hh:mm tt");
                    msgItem.Add(tem);
                }
                _item.msgItem = msgItem;
                _item.xid     = contactId;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                _global.con.Dispose();
            }
            return(_item);
        }
Ejemplo n.º 5
0
        public chatModel getChatBychatId(int chatid, int adminId)
        {
            chatModel           _item   = new chatModel();
            List <chatitem>     item    = new List <Models.chatitem>();
            List <msgItem>      msgItem = new List <Models.msgItem>();
            Global              _global = new Database.Global();
            CRMClassDataContext _idc    = new Database.CRMClassDataContext(_global.con);

            try
            {
                var contacts     = _idc.tbllogins.Where(a => a.UserId == adminId && a.IsActive == "y").FirstOrDefault();
                var contactImage = string.IsNullOrEmpty(contacts.Image) ? "/assets/images/icon/staff.png" : contacts.Image;
                var query        =
                    from post in _idc.tblinboxes.Where(a => a.MsgId == chatid)
                    join meta in _idc.tblcontacts on post.userId equals meta.ContactId
                    select new { Post = post, Meta = meta };
                string image = "/assets/images/icon/staff.png";
                foreach (var i in query)
                {
                    msgItem tem = new msgItem();
                    _item.xid     = i.Post.userId.Value;
                    tem.userId    = i.Post.userId.Value;
                    tem.sender    = i.Post.sender.Value;
                    tem.message   = i.Post.Body;
                    tem.messageId = i.Post.MsgId;
                    tem.Image     = i.Post.sender != i.Meta.ContactId ? contactImage : string.IsNullOrEmpty(i.Meta.ImagePath) ? image : i.Meta.ImagePath;
                    tem.Name      = i.Post.sender != i.Meta.ContactId ? contacts.FirstName : i.Meta.Name;
                    tem.Time      = i.Post.CreatedDate.Value.ToString("hh:mm tt");
                    msgItem.Add(tem);
                }
                _item.msgItem = msgItem;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                _idc.Dispose();
            }
            return(_item);
        }