Example #1
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);
        }
Example #2
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;
        }