public string GetAllMessages(string username, string chatUser)
        {
            JSonResult result = new JSonResult();
            result.Status = false;

            List<GetMessages> allMessages = new List<GetMessages>();
            Chat chat = new Chat();
            Users user = new Users();

            Guid guid;
            user.GetUserGuid(username, out guid);
            Guid chatUserGuid;
            user.GetUserGuid(chatUser, out chatUserGuid);
            DataSet ds = chat.GetAllMessages(guid, chatUserGuid);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                GetMessages message = new GetMessages();
                message.FromUser = dr["FromUser"].ToString();
                message.Message = dr["Comment"].ToString();
                message.Time = dr["ChatingTime"].ToString();

                allMessages.Add(message);
            }

            result.Status = true;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonresult = serializer.Serialize(allMessages);

            return jsonresult;
        }
Exemplo n.º 2
0
        public bool CreateNewUser(string username, string password)
        {
            bool isUserExists = CheckUserExist(username);
            if (!isUserExists)
            {
                Guid guid = Guid.NewGuid();
                string sqlQuery1 = "INSERT INTO Users (UserId, UserName, LUserName, LastActivityDate) VALUES" +
                    "('{0}','" + username + "','" + username.ToLower() + "'" + ",GETDATE())";
                string sqlQuery2 = "INSERT INTO Membership (UserId, Password, CreateDate) VALUES" +
                    "('{0}','" + password + "', GETDATE())";

                SQLExecuteBase obj = DataAccessService.Instance.SQLExecuteBase;
                SqlConnection sqlConn = obj.CreateConnection(DataAccessService.Instance.SQLAccess.ConnectionString);

                int rowsAffected = (int)obj.ExecuteNonQuery(sqlConn, String.Format(sqlQuery1, guid));

                if (rowsAffected != 0)
                {
                    int passwordCreatedCount = (int)obj.ExecuteNonQuery(sqlConn, String.Format(sqlQuery2, guid));

                    if (passwordCreatedCount != 0)
                    {
                        Chat chat = new Chat();
                        chat.CreateOnlineUsers(guid);
                        return true;
                    }
                }

            }
            return false;
        }
Exemplo n.º 3
0
        public bool CheckUserAndPasswordValid(string username, string password)
        {
            string sqlQuery1 = "SELECT UserId FROM Users WHERE UserName = '******'";
            string sqlQuery2 = "SELECT Count(*) FROM Membership WHERE UserId = '{0}' and Password = '******'";

            SQLExecuteBase obj = DataAccessService.Instance.SQLExecuteBase;
            SqlConnection sqlConn = obj.CreateConnection(DataAccessService.Instance.SQLAccess.ConnectionString);

            object guidobj = obj.ExecuteScalar(sqlConn, sqlQuery1);
            if (guidobj != null)
            {
                Guid guid;
                Guid.TryParse(guidobj.ToString(), out guid);
                if (guid != Guid.Empty)
                {
                    int count = (int)obj.ExecuteScalar(sqlConn, String.Format(sqlQuery2, guid));

                    if (count > 0)
                    {
                        Chat chat = new Chat();
                        chat.CreateOnlineUsers(guid);
                        return true;
                    }
                }
            }
            return false;
        }
        public string SendMessage(string fromUser, string toUser, string message)
        {
            JSonResult result = new JSonResult();
            result.Status = false;

            Users obj = new Users();
            Guid fromUserId, toUserId;
            obj.GetUserGuid(toUser, out toUserId);
            obj.GetUserGuid(fromUser, out fromUserId);

            Chat chat = new Chat();
            result.Status = chat.SendMessage(fromUserId, toUserId, message);

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonresult = serializer.Serialize(result.Status);

            return jsonresult;
        }
        public string GetAllOnlineUsers()
        {
            JSonResult result = new JSonResult();
            result.Status = false;

            List<OnlineUser> onlineUsers = new List<OnlineUser>();
            Chat chat = new Chat();

            List<OnlineUser> ou = new List<OnlineUser>();

            DataSet allUsersDataset = chat.GetAllOnlineUsers();
            foreach (DataRow dr in allUsersDataset.Tables[0].Rows)
            {
                onlineUsers.Add (new OnlineUser(dr[0].ToString(), dr[1].ToString()));
                ou.Add(new OnlineUser(dr[0].ToString(), dr[1].ToString()));
            }

            result.Status = true;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonresult = serializer.Serialize(ou);

            return jsonresult;
        }
Exemplo n.º 6
0
        public bool GetUserGuid(string username, out Guid guid)
        {
            string sqlQuery1 = "SELECT UserId FROM Users WHERE UserName = '******'";

            SQLExecuteBase obj = DataAccessService.Instance.SQLExecuteBase;
            SqlConnection sqlConn = obj.CreateConnection(DataAccessService.Instance.SQLAccess.ConnectionString);

            Object o = obj.ExecuteScalar(sqlConn, sqlQuery1);
            if (o != null)
            {
                guid = (Guid)o;
                Chat chat = new Chat();
                chat.CreateOnlineUsers(guid);
                return true;
            }

            guid = new Guid();
            return false;
        }