1

I'm very new to Visual Studio, C#, and the MVC Framework, but I've come across an issue I can't resolve on my own.

I've started a new Web Project in Visual Studio with Single User Authentication. So Visual Studio generates all the stuff I need for the user to register to my site - perfecto.

However, I have another table of user data that I need to be filled with default data whenever a user signs up.

PDC User Table

These will always start the same for each user - except for ID and then the foreign AspNetUserId. (You know, until they use the app).

This is the pre generated code that registers a user.

Code that executes when a user Registers

How can I edit this to simultaneously call a create method from my PDC_UserController to add data to my second table?

This is the code that would have to have the default values for the PDC_User table already specified.

enter image description here

  • How do I call a Create method from PDC_UserController from my AccountController's Register method?
  • How can I edit the PDC_UserController Create method to take the AspNetUserId from the AccountController and set the other values as default values?

Thanks for any help, I hope that's not too confusing

1 Answer 1

1

You wouldn't call the create method... Just do your db.add call in the Account Controller where you already have the username and other data available. Something similar to below then save the changes after. You can look up examples if you need more specifics.

db.PDC_User.Add(new PDC_User{
   DbRowName = defaultValue,
   *etc*
}
Sign up to request clarification or add additional context in comments.

3 Comments

okay that makes a lot more sense, but I'm still hazy on db I'm pretty sure it's var db = new ____() Hopefully I can figure it out - it seems like it shouldn't be difficult to find
db is a variable representing your database that you should declare under the class in the Account Controller. Something along the lines of: private DbContextname db = new DbContextname();
Yes it did! Thank you a ton!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.