Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 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);
        }
Esempio n. 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;
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
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);
            }
        }