//*******************************************************
        //
        // The AddUser_Click server event handler is used to add
        // a new user to this security role
        //
        //*******************************************************
        protected void AddUser_Click(Object sender, EventArgs e)
        {
            int userId;
            IAccountFacade facade = new AccountFacade();
            if (((LinkButton) sender).ID == "addNew")
            {
                // add new user to users table
                PortalUser user = new PortalUser();
                user.Name = windowsUserName.Text;
                user.Email = windowsUserName.Text;
                user.Password = "******";
                if ((userId = facade.AddUser(user)) == -1)
                {
                    Message.Text = "Add New Failed!  There is already an entry for <" + "u" + ">" + windowsUserName.Text +
                                   "<" + "/u" + "> in the Users database." + "<" + "br" + ">" +
                                   "Please use Add Existing for this user.";
                }
            }
            else
            {
                //get user id from dropdownlist of existing users
                userId = Int32.Parse(allUsers.SelectedItem.Value);
            }

            if (userId != -1)
            {
                // Add a new userRole to the database
                facade.AddUserRole(roleId, userId);
            }

            // Rebind list
            BindData();
        }
        //*************************************************************************************
        //
        // The Register.aspx page is used to enable clients to register a new unique username
        // and password with the portal system.  The page contains a single server event
        // handler -- RegisterBtn_Click -- that executes in response to the page's Register
        // Button being clicked.
        //
        // The Register.aspx page uses the UsersDB class to manage the actual account creation.
        // Note that the Usernames and passwords are stored within a table in a SQL database.
        //
        //*************************************************************************************
        protected void RegisterBtn_Click(Object sender, EventArgs E)
        {
            // Only attempt a login if all form fields on the page are valid
            if (Page.IsValid == true)
            {
                IAccountFacade facade = new AccountFacade();
                // Add New User to Portal User Database
                PortalUser user=new PortalUser();
                user.Name = Name.Text;
                user.Email = Email.Text;
                user.Password = PortalSecurity.Encrypt(Password.Text);
                if (facade.AddUser(user) > -1)
                {
                    // Set the user's authentication name to the userId
                    FormsAuthentication.SetAuthCookie(Email.Text, false);

                    // Redirect browser back to home page
                    Response.Redirect("~/DesktopDefault.aspx");
                }
                else
                {
                    Message.Text = "Registration Failed!  <" + "u" + ">" + Email.Text + "<" + "/u" +
                                   "> is already registered." + "<" + "br" + ">" +
                                   "Please register using a different email address.";
                }
            }
        }
        public void AddUser()
        {
            //int AddUser(string fullName, string email, string password)
            AccountFacade facade = new AccountFacade();

            PortalUser user = new PortalUser();
            user.Name="user" + DateTime.Now.Ticks;
            user.Email = "e";
            user.Password = "******";

            facade.AddUser(user);
        }
        public int AddUser(PortalUser user)
        {
            // TODO: add access security here..
            // TODO: add argument validation here..

            int retval;
            // Run within the context of a database transaction.
            // The Decorator Design Pattern.
            using (TransactionDecorator transaction = new TransactionDecorator())
            {
                retval = usersDAO.AddUser(user.Name, user.Email, user.Password);
                transaction.Complete();
            }
            return retval;
        }
        public void UpdateUser(PortalUser user)
        {
            // TODO: add access security here..
            // TODO: add argument validation here..

            // Run within the context of a database transaction.
            // The Decorator Design Pattern.
            using (TransactionDecorator transaction = new TransactionDecorator())
            {
                usersDAO.UpdateUser(user.UserID, user.Email, user.Password);
                transaction.Complete();
            }
        }
        public void UpdateUser()
        {
            //void UpdateUser(int userId, string email, string password)
            AccountFacade facade = new AccountFacade();

            PortalUser user= new PortalUser();
            user.UserID=0;
            user.Email = "e";
            user.Password = "******";

            facade.UpdateUser(user);
        }
        //*******************************************************
        //
        // The Page_Load server event handler on this page is used
        // to populate the role information for the page
        //
        //*******************************************************
        protected void Page_Load(Object Sender, EventArgs e)
        {
            // Verify that the current user has access to access this page
            if (PortalSecurity.IsInRoles("Admins") == false)
            {
                Response.Redirect("~/Errors/EditAccessDenied.aspx");
            }

            // Calculate userid
            if (Request.Params["userid"] != null)
            {
                userId = Int32.Parse(Request.Params["userid"]);
            }
            if (Request.Params["username"] != null)
            {
                userName = (String) Request.Params["username"];
            }
            if (Request.Params["tabid"] != null)
            {
                tabId = Int32.Parse(Request.Params["tabid"]);
            }
            if (Request.Params["tabindex"] != null)
            {
                tabIndex = Int32.Parse(Request.Params["tabindex"]);
            }

            // If this is the first visit to the page, bind the role data to the datalist
            if (Page.IsPostBack == false)
            {
                // new user?
                if (userName == "")
                {
                    // make a unique new user record
                    int uid = -1;
                    int i = 0;

                    while (uid == -1)
                    {
                        String friendlyName = "New User created " + DateTime.Now;
                        userName = "******" + i;
                        IAccountFacade facade = new AccountFacade();
                        PortalUser user = new PortalUser();
                        user.Name = friendlyName;
                        user.Email = userName;
                        user.Password = "";
                        uid = facade.AddUser(user);
                        i++;
                    }

                    // redirect to this page with the corrected querystring args
                    Response.Redirect("~/Admin/ManageUsers.aspx?userId=" + uid + "&username="******"&tabindex=" +
                                      tabIndex + "&tabid=" + tabId);
                }

                BindData();
            }
        }
        //*******************************************************
        //
        // The UpdateUser_Click server event handler is used to add
        // the update the user settings
        //
        //*******************************************************
        protected void UpdateUser_Click(Object sender, EventArgs e)
        {
            // update the user record in the database
            IAccountFacade facade = new AccountFacade();
            PortalUser user = new PortalUser();
            user.UserID = userId;
            user.Email = Email.Text;
            user.Password = PortalSecurity.Encrypt(Password.Text);
            facade.UpdateUser(user);

            // redirect to this page with the corrected querystring args
            Response.Redirect("~/Admin/ManageUsers.aspx?userId=" + userId + "&username="******"&tabindex=" +
                              tabIndex + "&tabid=" + tabId);
        }