Ejemplo n.º 1
0
        private static void WriteMessage(Message mes, SqlConnection connection)
        {
            string cmdString = "SELECT A.USERNAME FROM DialogueUser A INNER JOIN AccountSettings B ON A.USERNAME = B.USERNAME WHERE A.ROOM_ID = @id AND B.MAIL_MESSAGES_ENABLED = 1";

            SqlDataAdapter da = new SqlDataAdapter(cmdString, connection);

            da.SelectCommand.Parameters.AddWithValue("@id", mes.RoomId);

            DataSet set = new DataSet();

            da.Fill(set);

            List <string> users = new List <string>();

            foreach (DataRow row in set.Tables[0].Rows)
            {
                string user = row["USERNAME"].ToString();

                users.Add(user);
            }


            foreach (string user in users)
            {
                if (!NotificationHub.IsOnline(user))
                {
                    Dictionary <string, string> toPass = new Dictionary <string, string>();

                    toPass.Add("username", user);
                    toPass.Add("dialogue_id", mes.RoomId.ToString());

                    MailManager.SendMessage(toPass, MailType.MESSAGE);
                }
            }
        }