Monday, 15 February 2010

c# - WebSecurity.CreateUserAndAccount propertyValues -



c# - WebSecurity.CreateUserAndAccount propertyValues -

i'm writing mvc 4 c# .net 4.5 website

i want create new company object , register new user linked company.

my business relationship model is:

[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 phone call next adds user fine has null 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 expect not assigning anything.

i have tried adding (mycompany 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 error saying can't match type.

how go registering user companyicanedit contains companyid value of mycompany?

any help appreciated. thanks

never worked out how in 1 go, got round next in end if has same problem.

// // post: /businessmanager/managecompanies/add [httppost] public actionresult add(addcompanyviewmodel addcompanyviewmodel) { if (modelstate.isvalid) { // create company , effort register user seek { 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 }); db.companies.add(addcompanyviewmodel.company); var newuser = db.userprofiles.firstordefault(u => u.username == addcompanyviewmodel.user.username); if (newuser != null) { newuser.companyicanedit = addcompanyviewmodel.company; db.entry(newuser).state = entitystate.modified; db.savechanges(); homecoming redirecttoaction("index"); } else { modelstate.addmodelerror("", "new user wasn't added"); } } grab (membershipcreateuserexception e) { modelstate.addmodelerror("", mywebsite.controllers.accountcontroller.errorcodetostring(e.statuscode)); } } homecoming view(addcompanyviewmodel); }

c# asp.net-mvc-4 entity-framework-5

No comments:

Post a Comment