Ejemplo n.º 1
0
        protected void CreateUserButton_Click(object sender, EventArgs e)
        {
            AuthenticationEntitiesDataContext ctx = new AuthenticationEntitiesDataContext();

            //1. Create the Tenant
            Tenant tenant = new Tenant();

            tenant.TenantId = Guid.NewGuid();
            tenant.CompanyName = txtCompanyName.Text;
            tenant.CompanyUrl = txtCompanyUrl.Text;
            tenant.SubscriptionPlan = ddlSubscriptionPlan.SelectedValue;

            ctx.Tenants.InsertOnSubmit(tenant);

            ctx.SubmitChanges();

            //2. Create the User
            // We use the email twice because we're letting users login using their email
            MembershipUser user = Membership.CreateUser(Email.Text, Password.Text, Email.Text);

            //3. Put the user in the new tenant
            UsersInTenant userTenant = new UsersInTenant();

            userTenant.TenantId = tenant.TenantId;
            userTenant.UserId = (Guid)user.ProviderUserKey;

            ctx.UsersInTenants.InsertOnSubmit(userTenant);

            ctx.SubmitChanges();

            // clean up the context
            ctx.Dispose();

            FormsAuthentication.SetAuthCookie(user.UserName, false /* createPersistentCookie */);

            if (String.IsNullOrEmpty(_continueUrl))
            {
                _continueUrl = "~/";
            }
            Response.Redirect(_continueUrl);
        }
 partial void DeleteUsersInTenant(UsersInTenant instance);
 partial void UpdateUsersInTenant(UsersInTenant instance);
 partial void InsertUsersInTenant(UsersInTenant instance);
 private void detach_UsersInTenants(UsersInTenant entity)
 {
     this.SendPropertyChanging();
     entity.Tenant = null;
 }
 private void attach_UsersInTenants(UsersInTenant entity)
 {
     this.SendPropertyChanging();
     entity.Tenant = this;
 }
 partial void DeleteUsersInTenant(UsersInTenant instance);
 partial void UpdateUsersInTenant(UsersInTenant instance);
 partial void InsertUsersInTenant(UsersInTenant instance);
		private void detach_UsersInTenants(UsersInTenant entity)
		{
			this.SendPropertyChanging();
			entity.Tenant = null;
		}
		private void attach_UsersInTenants(UsersInTenant entity)
		{
			this.SendPropertyChanging();
			entity.Tenant = this;
		}