I am writing mvc 4 website C # .net 4.5
I want to create a new company object and register a new user who is associated with this company.
My account model:
[Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string EmailAddress { get; set; } public string PhoneNumber { get; set; } public bool MarketingEmailOptin { get; set; } public bool isDisabled { get; set; } public virtual Company CompanyICanEdit { get; set; } }
If I call the following, it adds the user a penalty, but is null for the CompanyICanEdit field:
WebSecurity.CreateUserAndAccount(addCompanyViewModel.User.UserName, addCompanyViewModel.User.Password, propertyValues: new { FirstName = addCompanyViewModel.User.FirstName, LastName = addCompanyViewModel.User.LastName, EmailAddress = addCompanyViewModel.User.EmailAddress, PhoneNumber = addCompanyViewModel.User.PhoneNumber, MarketingEmailOptin = addCompanyViewModel.User.MarketingEmailOptin, isDisabled = false });
which I would expect, since I do not assign it.
I tried to add (mycompany is a company object):
WebSecurity.CreateUserAndAccount(addCompanyViewModel.User.UserName, addCompanyViewModel.User.Password, propertyValues: new { FirstName = addCompanyViewModel.User.FirstName, LastName = addCompanyViewModel.User.LastName, EmailAddress = addCompanyViewModel.User.EmailAddress, PhoneNumber = addCompanyViewModel.User.PhoneNumber, MarketingEmailOptin = addCompanyViewModel.User.MarketingEmailOptin, isDisabled = false, CompanyICanEdit = mycompany });
But I get an error that does not match the type.
How do I switch to user registration, so that CompanyICanEdit contains my CompanyId value?
Any help would be appreciated. thanks