c# - Modifying ASP.NET Indentity Registration to write to two different tables -
i'm trying customize registration project using asp.net identity. registration page have following fields:
username email password country state zip the username, email , password handled default aspnetusers table. know can add columns country, state , zip aspnetusers table. write these fields different table (userprofile) id foreign key.
so when user submits valid registration, 3 fields write default aspnetusers table , 3 values (along id) write custom userprofile table. there way this?
somewhere in controller (most accountcontroller) have register-method called registerviewmodel parameter.
in method, new user gets created following (where model of type registerviewmodel)
var user = new applicationuser() { username = model.email, email = model.email }; identityresult result = await usermanager.createasync(user, model.password); when creation of new user succeeds (result.succeeded true), create new userprofile object user.id, model.country, model.state, model.zip, etc. , store in database (via db-context if use entity framework that).
Comments
Post a Comment