protected void btnSave_Click(object sender, EventArgs e)
    {
        bool canContinue = false;
        try
        {
            double.Parse(TextBoxHeight.Text);
            double.Parse(TextBoxWidth.Text);
            LabelSizeError.Visible = false;
            canContinue = true;
        }
        catch
        {
            LabelSizeError.Visible = true;
        }

        if (canContinue)
        {
            if (int.Parse(DropDownListLanguages.SelectedValue) > 509)
            {
                Account newAccount = CurrentUser.CurrentAccount;
                bool isEditing = !newAccount.IsNew;
                newAccount.Description = TextBoxDescription.Text;
                newAccount.CountryId = int.Parse(DropDownCountry.SelectedValue);
                newAccount.LanguageId = int.Parse(DropDownListLanguages.SelectedValue);
                newAccount.CityId = int.Parse(DropDownListCityList.SelectedValue);
                newAccount.TrackNames = CheckBoxNames.Checked;
                newAccount.TrackPhoneNumbers = CheckBoxPhoneNumbers.Checked;
                newAccount.PrintHeight = double.Parse(TextBoxHeight.Text);
                newAccount.PrintUnit = DropDownListUnit.SelectedValue;
                newAccount.PrintWidth = double.Parse(TextBoxWidth.Text);
                newAccount.IsForeignLanguage = CheckBoxIsForeignLanguage.Checked;
                newAccount.Save();
                CurrentUser.SetAccountCookie(newAccount);
                if (!isEditing)
                {
                    if (AccountUserMap.GetForCurrentUser() == null)
                    {
                        AccountUserMap newMap = new AccountUserMap();
                        newMap.AccountId = newAccount.AccountId;
                        newMap.UserId = CurrentUser.UserName;
                        newMap.Save();

                    }
                    Language defaultLanguage = new Language(509);
                    defaultLanguage.AddLanguageToCurrentAccount();
                    defaultLanguage = new Language(int.Parse(DropDownListLanguages.SelectedValue));
                    defaultLanguage.AddLanguageToCurrentAccount();
                    City selectedCity = new City(int.Parse(this.DropDownListCityList.SelectedValue));
                    selectedCity.AssociateWithCurrentAccount();
                }
                LabelMessage.Text = "Saved.";
                Saved();
                CurrentUser.Refresh();
            }
            else
            {
                LabelMessage.Text = "Please select a valid language";
            }
        }
    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        AccountUserMap newMap = new AccountUserMap();
        newMap.AccountId = CurrentUser.CurrentAccount.AccountId;
        newMap.UserId = CreateUserWizard1.UserName;
        newMap.Save();

        Roles.AddUsersToRole(new string[] { CreateUserWizard1.UserName }, "FreeAccount");
        DataBindUsers();
        TextBox messageBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxPersonalMessage");
        TextBox fullnameBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxFullName");
        Mailer.SendNewUserAccountCreatedForYou(CreateUserWizard1.Email, CreateUserWizard1.UserName, CreateUserWizard1.Password, messageBox.Text, fullnameBox.Text);
    }
 public static AccountUserMap GetForCurrentUser()
 {
     AccountUserMap thisMap = new AccountUserMap();
     CMS.AccountUserMapCollection collection = new CMS.AccountUserMapCollection();
     collection.LoadAndCloseReader(CMS.AccountUserMap.FetchByParameter(CMS.AccountUserMap.Columns.UserId, CurrentUser.UserName));
     if (collection.Count == 1)
     {
         return collection[0];
     }
     else if (collection.Count > 1)
     {
         throw new Exception("There should be only one account per user");
     }
     else return null;
 }
        public void Insert(int AccountId,string UserId,bool IsOwner)
        {
            AccountUserMap item = new AccountUserMap();

            item.AccountId = AccountId;

            item.UserId = UserId;

            item.IsOwner = IsOwner;

            item.Save(UserName);
        }
        public void Update(int AccountUserMapId,int AccountId,string UserId,bool IsOwner)
        {
            AccountUserMap item = new AccountUserMap();

                item.AccountUserMapId = AccountUserMapId;

                item.AccountId = AccountId;

                item.UserId = UserId;

                item.IsOwner = IsOwner;

            item.MarkOld();
            item.Save(UserName);
        }