Beispiel #1
0
        public bool InsertNewUser(string uid, string fname, string lname, string uname, string pass, string sex)
        {
            try
            {
                var dbChatAppDemoEntities = new ChatAppDemoEntities();
                var userInfo = new UserInfo
                {
                    UserId    = uid,
                    Firstname = fname,
                    Lastname  = lname,
                    Username  = uname,
                    Password  = pass,
                    Sex       = sex
                };

                dbChatAppDemoEntities.AddToUserInfoes(userInfo);
                dbChatAppDemoEntities.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(false);
        }
Beispiel #2
0
        public void InsertMess(string text, string roomId, string chatUsrId)
        {
            try
            {
                var dbChatAppDemoEntities = new ChatAppDemoEntities();

                var message = new Message {
                    RoomId = roomId, UserId = chatUsrId
                };

                if (text == null || text == "null")
                {
                    message.Text = ConfigurationManager.AppSettings["ChatLoggedInText"] + "" + DateTime.Now;
                }
                else
                {
                    message.Text = text;
                }
                message.Color    = "grey";
                message.ToUserId = "TEST";

                message.TimeEntered = DateTime.Now;
                dbChatAppDemoEntities.AddToMessages(message);
                dbChatAppDemoEntities.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #3
0
        public string GetLoggenInUser(string roomId, string chatUsrId)
        {
            try
            {
                var js = new JavaScriptSerializer();
                var dbChatAppDemoEntities = new ChatAppDemoEntities();

                var user = from u in dbChatAppDemoEntities.LoggedInUseIds
                           where u.UserId == chatUsrId &&
                           u.RoomId == roomId
                           select u;

                if (!user.Any())
                {
                    var loggedInUseIds = new LoggedInUseId
                    {
                        UserId         = chatUsrId,
                        RoomId         = roomId,
                        LoggedInUserId = chatUsrId
                    };

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

                var loggedInUsers = dbChatAppDemoEntities.LoggedInUseIds.Where(logInUser => logInUser.RoomId == roomId);

                var arrSendLogInUid = new string[loggedInUsers.Count(), 2];
                var i = 0;

                foreach (var loggedInUser in loggedInUsers)
                {
                    arrSendLogInUid[i, 0] = loggedInUser.UserId;
                    var sdf = loggedInUser.UserId;

                    var usr = (dbChatAppDemoEntities.UserInfoes.Where(usrInfo => usrInfo.UserId == sdf)
                               .Select(usrInfo => usrInfo.Username));

                    arrSendLogInUid[i, 1] = usr.First();

                    i++;
                }
                return(js.Serialize(arrSendLogInUid));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(null);
        }
Beispiel #4
0
        public string GetLoggenInUser(string roomId, string chatUsrId)
        {
            try
            {
                var js = new JavaScriptSerializer();
                var dbChatAppDemoEntities = new ChatAppDemoEntities();

                var user = from u in dbChatAppDemoEntities.LoggedInUseIds
                           where u.UserId == chatUsrId
                           && u.RoomId == roomId
                           select u;

                if (!user.Any())
                {
                    var loggedInUseIds = new LoggedInUseId
                    {
                        UserId = chatUsrId,
                        RoomId = roomId,
                        LoggedInUserId = chatUsrId
                    };

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

                var loggedInUsers = dbChatAppDemoEntities.LoggedInUseIds.Where(logInUser => logInUser.RoomId == roomId);

                var arrSendLogInUid = new string[loggedInUsers.Count(), 2];
                var i = 0;

                foreach (var loggedInUser in loggedInUsers)
                {
                    arrSendLogInUid[i, 0] = loggedInUser.UserId;
                    var sdf = loggedInUser.UserId;

                    var usr = (dbChatAppDemoEntities.UserInfoes.Where(usrInfo => usrInfo.UserId == sdf)
                        .Select(usrInfo => usrInfo.Username));

                    arrSendLogInUid[i, 1] = usr.First();

                    i++;
                }
                return js.Serialize(arrSendLogInUid);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return null;
        }
Beispiel #5
0
        protected void butSubmit_Click(object sender, EventArgs e)
        {
            var db = new ChatAppDemoEntities();
            var users = db.UserInfoes.Where(u => u.Username == txtUserName.Text
                                                 && u.Password == txtPass.Text);

            if (users.Any())
            {
                Session["ChatUserID"] = users.First().UserId;
                Session["ChatUsername"] = users.First().Username;
                Session["LoggedIn"] = false;
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "child_open();", true);
                Login1_LoggedIn();
            }
            else
            {
                lblLoginError.Visible = true;
            }
        }
Beispiel #6
0
        protected void butSubmit_Click(object sender, EventArgs e)
        {
            var db    = new ChatAppDemoEntities();
            var users = db.UserInfoes.Where(u => u.Username == txtUserName.Text &&
                                            u.Password == txtPass.Text);

            if (users.Any())
            {
                Session["ChatUserID"]   = users.First().UserId;
                Session["ChatUsername"] = users.First().Username;
                Session["LoggedIn"]     = false;
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "child_open();", true);
                Login1_LoggedIn();
            }
            else
            {
                lblLoginError.Visible = true;
            }
        }
Beispiel #7
0
        public void LogoutUser(string roomId, string chatUsrId)
        {
            try
            {
                var    dbChatAppDemoEntities = new ChatAppDemoEntities();
                string chatUserId            = chatUsrId;

                var loggedInUser = (dbChatAppDemoEntities.LoggedInUseIds.Where(lIu => lIu.UserId == chatUserId &&
                                                                               lIu.RoomId == roomId)).First();

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

                InsertMess("Just Logged Out! " + DateTime.Now.ToString(CultureInfo.InvariantCulture), roomId, chatUsrId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #8
0
        public string GetMess(string roomId, string dtCheck)
        {
            try
            {
                DateTime dt = Convert.ToDateTime(dtCheck);
                var      js = new JavaScriptSerializer();
                var      dbChatAppDemoEntities = new ChatAppDemoEntities();

                var mess = (from message in dbChatAppDemoEntities.Messages
                            where message.RoomId == roomId &&
                            message.TimeEntered >= dt
                            orderby message.TimeEntered descending
                            select message).Take(20).OrderBy(messages => messages.TimeEntered);

                if (mess.Count() != 0)
                {
                    var arrMess = new string[mess.Count(), 2];
                    var row     = 0;

                    foreach (var message in mess)
                    {
                        Console.WriteLine(message.TimeEntered);
                        Message message1 = message;
                        var     usr      = (from usrInfo in dbChatAppDemoEntities.UserInfoes
                                            where usrInfo.UserId == message1.UserId
                                            select usrInfo.Username);

                        arrMess[row, 0] = usr.First();
                        arrMess[row, 1] = message.Text;
                        row++;
                    }
                    return(js.Serialize(arrMess));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(null);
        }
Beispiel #9
0
        public string GetMess(string roomId, string dtCheck)
        {
            try
            {
                DateTime dt = Convert.ToDateTime(dtCheck);
                var js = new JavaScriptSerializer();
                var dbChatAppDemoEntities = new ChatAppDemoEntities();

                var mess = (from message in dbChatAppDemoEntities.Messages
                            where message.RoomId == roomId
                            && message.TimeEntered >= dt
                            orderby message.TimeEntered descending
                            select message).Take(20).OrderBy(messages => messages.TimeEntered);

                if (mess.Count() != 0)
                {
                    var arrMess = new string[mess.Count(), 2];
                    var row = 0;

                    foreach (var message in mess)
                    {
                        Console.WriteLine(message.TimeEntered);
                        Message message1 = message;
                        var usr = (from usrInfo in dbChatAppDemoEntities.UserInfoes
                                   where usrInfo.UserId == message1.UserId
                                   select usrInfo.Username);

                        arrMess[row, 0] = usr.First();
                        arrMess[row, 1] = message.Text;
                        row++;
                    }
                    return js.Serialize(arrMess);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return null;
        }
Beispiel #10
0
        public void LogoutUser(string roomId, string chatUsrId)
        {
            try
            {
                var dbChatAppDemoEntities = new ChatAppDemoEntities();
                string chatUserId = chatUsrId;

                var loggedInUser = (dbChatAppDemoEntities.LoggedInUseIds.Where(lIu => lIu.UserId == chatUserId
                                                                                      && lIu.RoomId == roomId)).First();

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

                InsertMess("Just Logged Out! " + DateTime.Now.ToString(CultureInfo.InvariantCulture), roomId, chatUsrId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #11
0
        public bool InsertNewUser(string uid, string fname, string lname, string uname, string pass, string sex)
        {
            try
            {
                var dbChatAppDemoEntities = new ChatAppDemoEntities();
                var userInfo = new UserInfo
                {
                    UserId = uid,
                    Firstname = fname,
                    Lastname = lname,
                    Username = uname,
                    Password = pass,
                    Sex = sex
                };

                dbChatAppDemoEntities.AddToUserInfoes(userInfo);
                dbChatAppDemoEntities.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return false;
        }
Beispiel #12
0
        public void InsertMess(string text, string roomId, string chatUsrId)
        {
            try
            {
                var dbChatAppDemoEntities = new ChatAppDemoEntities();

                var message = new Message { RoomId = roomId, UserId = chatUsrId };

                if (text == null || text == "null")
                {
                    message.Text = ConfigurationManager.AppSettings["ChatLoggedInText"] + "" + DateTime.Now;
                }
                else
                {
                    message.Text = text;
                }
                message.Color = "grey";
                message.ToUserId = "TEST";

                message.TimeEntered = DateTime.Now;
                dbChatAppDemoEntities.AddToMessages(message);
                dbChatAppDemoEntities.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }