Adding new data to DB when using 2 tables - asp.net-mvc

I am new to mvc and mvc 3 , I have a db that contain a company table (string id =as the company name )
And a table tourism that contain same info I would like to be able to add data to the tourism table , while selecting a company from the list (that came from the company table)
(The two tables had a dependency vie company_id (and the same name in both))
How can I do it?
Leo_a

create a transaction
insert into the dependent table
inserrt into the main table
commit

I'm not sure I understand the question. You want to select from one table and update the other with the data you selected from the first? Do you have any sample code you can post?

Related

adding a DropDownList on asp.net mvc containing a specific choices

adding a DropDownList on asp.net MVC containing specific choices, when the user chooses, his choice will be saved in the database under his user name on the registration page. I have tried to add a new cell in the table of my database and tried some codes but it doesn't work with me.
my website has 2 user model one of them is metadata and reset password model, one table and one database for now. I wish to add a new cell in the table called college the student will choose one of the colleges on the DropDownList and his choice will be saved under his user name.
for anyone who could help me, I can send my whole project as 1 zip file.

How to store different sets of user information using ASP.NET MVC Simple Memberships

How do I store different sets of user information using Simple Memberships? For eg. I have two roles (doctors and patients) respectively. The extended user information to be stored for both the roles is somewhat different. Simple Membership creates a UserProfile table by default which I'd like to split into two tables to accomodate the user information for both the roles respectively.
Please suggest if and how this can be achieved.
Thanks.
You have Roles defined in your 'Roles' Table. Then, for a particular User, UserId and RoleId both are associated with each other in another Table named '_UserInRoles'. Now, Create another table maybe Named as 'UserAdditionalInfo' and
make table structure as below
Id(PK)
UserId(FK)
RoleId(FK)
Column1
Column2
Now, you can save user additional data according to its RoleId and UserId in another table and when you need to display User Profile on front end, then may be you can use JOIN in these tables and return information.

Concept on displaying cross-table(conjunction) data in ASP MVC

Just a rookie in .NET MVC world and still learning
I created three EF models in framework, one is clients, one is order, and items, below is the relation:
Client Order Items
PK:ID PK Order.id PK Items.ID
... FK:Client.id ...
FK:Item.id
In this case I wanna display all the client information and the item details they've bought in one table, obviously I cannot use any DBcontext here. So what should I do to combine the three table's info and output that? Create a new model on those three?
Any ideas or article are very welcomed!
I would create a ViewModel with all of the Data that you want to display. This is the model that will get populated in the controller and then it would get passed to the View.
So in the View it would use the ViewModel and wouldn't need to know about the underlying Database Model.
And in the Controller you would get the data needed and populate the ViewModel and pass that model onto the View.
Here is a page with an examples. There are plenty more out there too. http://sampathloku.blogspot.com/2012/10/how-to-use-viewmodel-with-aspnet-mvc.html

One Controller with many views for table per type

I have a table per type structure, I want to write an mvc razor application where my only parameter in the mvc routing is the primary key ID. From there the application will establish which type in my tpt structure the ID belongs to then displays the view formatted for particular type.
In addition, based on the type of the ID the view will also contain information related to that ID in from other tables in the tpt structure.
E.g.
Bob is a person with ID 1234
Entity 1234 has comments in the comments table
Entity 1234 has an entry in the entity relationship table to Simon
I've read a number of articles about making a base class controller, but would my URL change from www.something.burp/1234?
Is it possible to have a set of Index, Edit, Create, Details views that have byType separation?
Just looking for some pointers or ideas for me to research.
Thanks for you help.
MVC4, EF4, C#, SQL 2008
Decided to do multi controller, it's not going to matter to the user if it goes between controllers.

Add columns in Membership Provider table

Can I add custom columns to the Membership provider table? I know it has a bunch of Stored Procedures. But all I want to add is three more fields - FirstName, LastName, CompanyID and link it to the Company table. Please refer to the screenshot.
You can. Or you can make another table with the extra information in it and link it by UserId.

Resources