Beispiel #1
0
        private void GetMessage()
        {
            try
            {
                ChatAppDemoEntities dbChatAppDemoEntities = new ChatAppDemoEntities();

                var mess = (from message in dbChatAppDemoEntities.Messages
                            where message.RoomId == lblRoomID.Text &&
                            message.TimeStamp.CompareTo(dtCheck) >= 0
                            orderby message.TimeStamp descending
                            select message).Take(20).OrderBy(messages => messages.TimeStamp);

                dtCheck = DateTime.Now.ToString();

                if (mess != null)
                {
                    foreach (var message in mess)
                    {
                        litMessages.Items.Add(message.UserId + " : " + message.Text);
                    }
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #2
0
        private void InsertMessage(string text)
        {
            try
            {
                Session["LoggedIn"] = true;
                ChatAppDemoEntities dbChatAppDemoEntities = new ChatAppDemoEntities();

                Message message = new Message();
                message.RoomId = lblRoomID.Text;
                message.UserId = Session["ChatUserID"].ToString();

                if (String.IsNullOrEmpty(text))
                {
                    message.Text  = txtMessage.Text.Replace("<", "");
                    message.Color = ddlColor.SelectedValue;
                }
                else
                {
                    message.Text  = text;
                    message.Color = "grey";
                }

                message.ToUserId = "TEST";

                message.TimeStamp = DateTime.Now.ToString();
                dbChatAppDemoEntities.AddToMessages(message);
                dbChatAppDemoEntities.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #3
0
        protected void butLogout_Click(object sender, EventArgs e)
        {
            try
            {
                ChatAppDemoEntities dbChatAppDemoEntities = new ChatAppDemoEntities();
                string chatUserID = Session["ChatUserID"].ToString();

                var loggedInUser = (from lIU in dbChatAppDemoEntities.LoggedInUseIds
                                    where lIU.UserId == chatUserID &&
                                    lIU.RoomId == lblRoomID.Text
                                    select lIU).First();

                dbChatAppDemoEntities.DeleteObject(loggedInUser);
                dbChatAppDemoEntities.SaveChanges();

                litUsers.Items.Remove(loggedInUser.UserId.ToString());

                this.InsertMessage("Just Logged Out! " + DateTime.Now.ToString());
                this.GetMessage();

                Session.RemoveAll();
                Session.Abandon();

                //Response.Redirect("Default.aspx");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #4
0
        private void GetLoggenInUser()
        {
            try
            {
                string chatUserID = Session["ChatUserID"].ToString();

                ChatAppDemoEntities dbChatAppDemoEntities = new ChatAppDemoEntities();
                var gg = lblRoomID.Text;

                var user = (from u in dbChatAppDemoEntities.LoggedInUseIds
                            where u.UserId == chatUserID &&
                            u.RoomId == lblRoomID.Text
                            select u).First();

                if (user == null)
                {
                    LoggedInUseId LoggedInUseIds = new LoggedInUseId();
                    LoggedInUseIds.UserId         = Session["ChatUserID"].ToString();
                    LoggedInUseIds.RoomId         = lblRoomID.Text;
                    LoggedInUseIds.LoggedInUserId = Session["ChatUserID"].ToString();

                    dbChatAppDemoEntities.AddToLoggedInUseIds(LoggedInUseIds);
                    dbChatAppDemoEntities.SaveChanges();
                }

                StringBuilder sb = new StringBuilder();

                var loggedInUsers = from logInUser in dbChatAppDemoEntities.LoggedInUseIds
                                    where logInUser.RoomId == lblRoomID.Text
                                    select logInUser;
                int check = 0;

                foreach (var loggedInUser in loggedInUsers)
                {
                    //sb.Append("<a href='#'>" + loggedInUser.UserId + "</a><br>");
                    for (int i = 0; i < litUsers.Items.Count; i++)
                    {
                        if (litUsers.Items[i].ToString() == loggedInUser.UserId)
                        {
                            check = 1;
                        }
                    }

                    if (check == 0)
                    {
                        litUsers.Items.Add(loggedInUser.UserId);
                    }
                }
                //litUsers.Items.Add(sb.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #5
0
        protected void butSubmit_Click(object sender, EventArgs e)
        {
            ChatAppDemoEntities db = new ChatAppDemoEntities();
            var users = (from u in db.UserInfoes
                         where u.Username == txtUserName.Text &&
                         u.Password == txtPass.Text
                         select u).First();

            if (users != null)
            {
                Session["ChatUserID"]   = users.UserId;
                Session["ChatUsername"] = users.Username;
                Session["LoggedIn"]     = false;
                Login1_LoggedIn();
            }
        }
Beispiel #6
0
        public void RaiseCallbackEvent(string eventArgument)
        {
            _callBackStatus = "failed";

            ChatAppDemoEntities dbChatAppDemoEntities = new ChatAppDemoEntities();

            var loggedInUser = (from lIU in dbChatAppDemoEntities.LoggedInUseIds
                                where lIU.UserId == Session["ChatUserID"].ToString() &&
                                lIU.RoomId == lblRoomID.Text
                                select lIU).SingleOrDefault();

            dbChatAppDemoEntities.DeleteObject(loggedInUser);
            dbChatAppDemoEntities.SaveChanges();

            this.InsertMessage("Just Logged Out! " + DateTime.Now.ToString());

            _callBackStatus = "success";
        }