I’m trying to write my own account registration logic in an Mvc 4 application. I started with a basic template instead of the internet template. At the moment I have a Tenant model with a number of properties. Using code first I’ve created a tenant table in my database (there will be more models and tables added over time – I’m just trying to get one working first).
I’ve created a RegisterTenantModel – similar to the one in the internet template except I’m using email instead of username.
public class TenantRegisterModel
{
[Required]
[Display(Name="Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
In my RegisterTenant method below I want to:
- Allow a user (tenant) to initially sign up only with an email address and password, and only allow them to enter the rest of their tenant related properties once their account has been verified by email, hence the use of the
TenantRegisterModel.
On calling Membership.CreateUser, how do I know that model.Email and model.Password will be added to the Tenant table? Likewise, if I was doing the same scenario as described above for a Landlord, how would I know that the details entered are being added to the Landlord table? Is there a way with Membership.CreateUser I can specify what table to add the user’s details too?
RegisterTenant:
public ActionResult RegisterTenant(TenantRegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register a tenant account
MembershipCreateStatus createStatus;
Membership.CreateUser(model.Email, model.Password);
// ...
}
}
I of course have a context class, which at the moment has public DbSet<LetLord.Models.Tenant> Tenants { get; set; }, so how do I know what table a user’s details are being added if I had multiple DbSets?
How do I know that model.Email and model.Password will be added to the Tenant table?
I added additional properties to the UserProfile model. Then in the
CreateUserAndAccountmethod I dynamically passed the properties in as follows:Likewise, if I was doing the same scenario as described above for a Landlord, how would I know that the details entered are being added to the Landlord table? Is there a way with Membership.CreateUser I can specify what table to add the user’s details too?
I created roles for landlords and tenants, and in
Register, just afterCreateUserAndAccountI checked the value of enumAccountType: