sto scrivendo un MVC 4 C# .NET 4.5 sitopropertyValues WebSecurity.CreateUserAndAccount
voglio creare un nuovo oggetto sociale e registrare un nuovo utente che è collegato a tale società.
Il mio modello account è:
[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; }
}
Se chiamo il seguente si aggiunge la multa utente, ma ha nulla per il campo CompanyICanEdit:
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
});
che mi sarei aspettato come io non sono assegnando è tutto
Ho provato ad aggiungere (mycompany è un oggetto società):
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
});
ma ottengo un errore che dice che non può corrispondere al tipo.
Come faccio a registrare l'utente in modo che CompanyICanEdit contenga il valore CompanyId della mia azienda?
Qualsiasi aiuto sarà apprezzato. grazie
Se si aggiunge int CompanyICanEditId {get; impostato; } e [ForeignKey ("CompanyICanEditId")] per la proprietà CompanyICanEdit, quindi è possibile aggiungere CompanyICanEditId = company.Id alle proprietà dell'utente creato – blazkovicz