示例#1
0
        public ChatroomContainerViewModel FetchRooms()
        {
            ChatroomContainerViewModel roomsList = new ChatroomContainerViewModel();
            string SQL = "SELECT * FROM [Chatroom]";
            List <KeyValuePair <object, object> > parameters = new List <KeyValuePair <object, object> >();
            DataTable dt = new BaseMssqlContext().ExecuteQuery(SQL, parameters);

            roomsList.Rooms = new List <ChatroomViewModel>();
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                roomsList.Rooms.Add(DataSetParser.DatasetToChatroom(dt, j));
            }

            foreach (ChatroomViewModel chatView in roomsList.Rooms)
            {
                List <int> members  = new List <int>();
                string     SQLrooms =
                    "SELECT user_id FROM [Chatroom_User] WHERE chatroom_id = @Chatroom_Id AND access_verified = 1";
                List <KeyValuePair <object, object> > param = new List <KeyValuePair <object, object> >();
                param.Add(new KeyValuePair <object, object>("Chatroom_Id", chatView.Id));
                DataTable dataTable = new BaseMssqlContext().ExecuteQuery(SQLrooms, param);
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    members.Add(Convert.ToInt32(dataTable.Rows[i][0]));
                }

                chatView.MemberList = members;
            }

            FillRoomList(roomsList);
            return(roomsList);
        }
        public ChatroomViewModel GetById(long roomId)
        {
            string SQL = "SELECT * FROM [Chatroom] WHERE ID = @Chatroom_ID";
            List <KeyValuePair <object, object> > parameters = new List <KeyValuePair <object, object> >();

            parameters.Add(new KeyValuePair <object, object>("Chatroom_ID", roomId));

            DataTable         dt     = ExecuteQuery(SQL, parameters);
            ChatroomViewModel result = DataSetParser.DatasetToChatroom(dt, 0);

            return(result);
        }