Exemplo n.º 1
0
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            MembershipUser membershipUser = Membership.GetUser(CreateUserWizard1.UserName);

            //Add user to role
            Roles.AddUserToRole(CreateUserWizard1.UserName, "User");

            //Add user to the user table
            Guid aspnetIDGuid = new Guid(membershipUser.ProviderUserKey.ToString());

            TextBox      zipTextBox             = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("zipTextBox");
            TextBox      firstNameTextBox       = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("firstNameTextBox");
            TextBox      lastNameTextBox        = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("lastNameTextBox");
            TextBox      phoneTextBox           = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("phoneTextBox");
            DropDownList homeCourtDropDownList  = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("homeCourtDropDownList");
            DropDownList nTRPDropDownList       = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("nTRPDropDownList");
            DropDownList leagueCityDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("leagueCityDropDownList");
            TextBox      referrerEmailTextBox   = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("referrerEmailTextBox");

            int?userId        = 0;
            int?performanceId = 0;
            int?divisionId    = 0;

            using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
            {
                ISingleResult <SelectLowestDivisionResult> results = dataContext.SelectLowestDivision(Convert.ToInt32(WebConfigurationManager.AppSettings["LeagueCityId"]));
                foreach (SelectLowestDivisionResult result in results)
                {
                    divisionId = result.DivisionId;
                }
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    dataContext.InsertUser(aspnetIDGuid, divisionId.Value, CreateUserWizard1.UserName, zipTextBox.Text, firstNameTextBox.Text, lastNameTextBox.Text, phoneTextBox.Text, Convert.ToInt32(homeCourtDropDownList.Text), Convert.ToDouble(nTRPDropDownList.Text), null, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, null, DateTime.Now, true, false, referrerEmailTextBox.Text, ref userId);
                    dataContext.InsertPerformance(userId.Value, divisionId.Value, ref performanceId);

                    transactionScope.Complete();
                }
            }
        }