private void SaveUser()
        {
            // get owner
            UserInfo owner = PanelSecurity.SelectedUser;

            if (Page.IsValid)
            {
                // gather data from form
                UserInfo user = new UserInfo();
                user.UserId   = PanelRequest.PeerID;
                user.RoleId   = owner.RoleId;
                user.StatusId = owner.StatusId;
                user.OwnerId  = owner.UserId;
                user.IsDemo   = owner.IsDemo;
                user.IsPeer   = true;

                // account info
                user.FirstName      = Server.HtmlEncode(txtFirstName.Text);
                user.LastName       = Server.HtmlEncode(txtLastName.Text);
                user.Email          = txtEmail.Text;
                user.SecondaryEmail = txtSecondaryEmail.Text;
                user.HtmlMail       = ddlMailFormat.SelectedIndex == 1;
                user.Username       = txtUsername.Text;
                user.Password       = userPassword.Password;
                user.IsDemo         = chkDemo.Checked;

                // contact info
                user.CompanyName      = contact.CompanyName;
                user.Address          = contact.Address;
                user.City             = contact.City;
                user.Country          = contact.Country;
                user.State            = contact.State;
                user.Zip              = contact.Zip;
                user.PrimaryPhone     = contact.PrimaryPhone;
                user.SecondaryPhone   = contact.SecondaryPhone;
                user.Fax              = contact.Fax;
                user.InstantMessenger = contact.MessengerId;

                if (PanelRequest.PeerID == 0)
                {
                    // add a new peer
                    List <string> log = new List <string>();

                    try
                    {
                        //int userId = UsersHelper.AddUser(log, PortalId, user);
                        int userId = PortalUtils.AddUserAccount(log, user, false);

                        if (userId < 0)
                        {
                            ShowResultMessage(userId);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage("PEER_ADD_PEER", ex);
                        return;
                    }

                    // show lof records if any
                    if (log.Count > 0)
                    {
                        blLog.Items.Clear();
                        foreach (string error in log)
                        {
                            blLog.Items.Add(error);
                        }

                        return;
                    }
                }
                else
                {
                    // update existing user
                    try
                    {
                        //int result = UsersHelper.UpdateUser(PortalId, user);
                        int result = PortalUtils.UpdateUserAccount(user);

                        if (result < 0)
                        {
                            ShowResultMessage(result);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage("PEER_UPDATE_PEER", ex);
                        return;
                    }
                }

                // return back to the list
                RedirectBack();
            }
        }
        private void SaveUser()
        {
            if (!Page.IsValid)
            {
                return;
            }

            // gather data from form
            UserInfo user = new UserInfo();

            user.UserId   = 0;
            user.Role     = (UserRole)Enum.Parse(typeof(UserRole), role.SelectedValue);
            user.StatusId = Int32.Parse(status.SelectedValue);
            user.OwnerId  = PanelSecurity.SelectedUserId;
            user.IsDemo   = chkDemo.Checked;
            user.IsPeer   = false;
            //
            if (chkEcommerceEnbl.Visible)
            {
                user.EcommerceEnabled = chkEcommerceEnbl.Checked;
            }

            // account info
            user.FirstName      = txtFirstName.Text;
            user.LastName       = txtLastName.Text;
            user.Email          = txtEmail.Text;
            user.SecondaryEmail = txtSecondaryEmail.Text;
            user.HtmlMail       = ddlMailFormat.SelectedIndex == 1;
            user.Username       = txtUsername.Text.Trim();
            user.Password       = userPassword.Password;

            // contact info
            user.CompanyName      = contact.CompanyName;
            user.Address          = contact.Address;
            user.City             = contact.City;
            user.Country          = contact.Country;
            user.State            = contact.State;
            user.Zip              = contact.Zip;
            user.PrimaryPhone     = contact.PrimaryPhone;
            user.SecondaryPhone   = contact.SecondaryPhone;
            user.Fax              = contact.Fax;
            user.InstantMessenger = contact.MessengerId;


            // add a new user
            List <string> log = new List <string>();

            try
            {
                //int userId = UsersHelper.AddUser(log, PortalId, user);
                int userId = PortalUtils.AddUserAccount(log, user, chkAccountLetter.Checked);

                if (userId == BusinessErrorCodes.ERROR_INVALID_USER_NAME)
                {
                    ShowResultMessage(BusinessErrorCodes.ERROR_INVALID_USER_NAME);
                    return;
                }

                if (userId < 0)
                {
                    ShowResultMessage(userId);
                    return;
                }

                // show log records if any
                if (log.Count > 0)
                {
                    blLog.Items.Clear();
                    foreach (string error in log)
                    {
                        blLog.Items.Add(error);
                    }

                    return;
                }

                // go to user home
                Response.Redirect(PortalUtils.GetUserHomePageUrl(userId));
            }
            catch (Exception ex)
            {
                ShowErrorMessage("USER_ADD_USER", ex);
                return;
            }
        }