c# - Generating a table from another table - MVC5 -


i'm new mvc5 , .net. using asp application user , have additional table patient:

[databasegenerated(databasegeneratedoption.identity)]     public guid patientid { get; set; }  [foreignkey("user")]     [display(name = "user id")]     public string userid { get; set; }     public virtual applicationuser user { get; set; } 

my accountcontroller is:

    [httppost]     [allowanonymous]     [validateantiforgerytoken]     public async task<actionresult> register(registerviewmodel model)     {           if (modelstate.isvalid)         {             var user = new applicationuser             {                 username = model.email,                 email = model.email,                 title = model.title,                 firstname = model.firstname,                 lastname = model.lastname,                 dob = model.dob,                 gender = model.gender,                 contactnumber = model.contactnumber,                 address1 = model.address1,                 address2 = model.address2,                 address3 = model.address3,                 county = model.county,                 postcode = model.postcode             };             var result = await usermanager.createasync(user, model.password);             if (result.succeeded)             {               //create patient id              patient patient = new patient();              patient.patientid = guid.newguid();              patient.userid = user.id;              db.patients.add(patient);                  await signinmanager.signinasync(user, ispersistent:false, rememberbrowser:false);                  return redirecttoaction("index", "home");             }             adderrors(result);         }         return view(model);     } 

i trying upon registration create instance of patient generate patientid along referential foreign key user id. when register new user in registration no corresponding patient created. advice appreciated.

thanks

next line db.patients.add(patient); need call savechanges of dbcontext confirm de transaction, in case, add patient.


Comments

Popular posts from this blog

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Handling constructor related functions while testing with mocha and sinon -