Add columns in Membership Provider table - asp.net-mvc

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.

Related

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.

How to bind DataTable to DataGridView that consists of a DatagridViewTextBoxColumn and a DataGridViewComboBoxColumn?

I want to ask you a question about my project.
I have a DataGridView in my C# project which has two columns: One is DataGridViewTextBoxColumn, the other is DataGridViewComboBoxColumn.
I have usernames and authorities columns in my DB. Usernames are email addresses like abc#domain.com and authorities are either user or admin.
I want to bind via DataTable usernames to DataGridViewTextBoxColumn and authorities to DataGridViewComboBoxColumn but combo boxes must show usernames' authority by default and also have the option to change it between user and admin.
Thanks for any help.
you can do all you need in the designer ... you just have to put "user" and "admin" in the Items collection of your DataGridViewComboBoxColumn

How to update the same attributes in several tables with Postgresql and Rails

In order to minimize the number of joins that I have to execute in my application I decided to copy in my database the same field in several tables for example :
I have a User, Product and a Wishlist Table.
My Product pages shows the user who created the product, as the wishlists pages which also shows the user who created them.
So I added in my products and wishlists table all the users field needed to show the required informations.
How can I update the users related fields in my Products and Wishlists Table as soon as the user change his information ?
Here is a part of my model :
User Table
Full Name
UserName
Avatar URL
Product Table
Product Name
Product Price
User ID
User Full Name
Username
User Avatar URL
Wishlist Table
Wishlist Name
User ID
User Full Name
Username
User Avatar URL
Thanks in advance for your answers !
Firstly, by denormalizing the data in the way that you are, you are working against what relational databases are meant to do. They thrive on joins, and having each piece of data appear as few times as possible. So you really want to make sure that this is the schema that you want.
That being said, you can use the basic update_attibute syntax to update any field in any table. So, if a user edited his or her username, you would do:
User.update_attribute(:username, username)
Product.update_attribute(:username, username)
Wishlist.update_attribute(:username, username)

Adding custom fields to aspnetdb.mdf

OK so I've created a new table within the existing aspnetdb.mdf database aspnet_Groups, and added and related a foreign key to the aspnet_Users table GroupId.
So users table now goes:
ApplicationId
UserId
UserName
LoweredUserName
MobileAlias
IsAnonymous
LastActivityDate
GroupId //<--- Added by me, and related to aspnet_Groups table
Groups table only has GroupId and GroupName so it's pretty simple actually.
What I wanna know, is how do I save and get data for this field/table from within MVC application. Or does this have to be done another way?
Edited
I would not recommend intervining into aspnetdb working ...
If you need to - create your own table and link it to aspnetdb.
More control, more customization, less bugs introduced to internal MS authentication...
Great posting about this Storing data in a Custom table within ASPNETDB.mdf vs. storing information about a user in a profile
But again, there's no right answer to your question - as long as it works and having good usability and readability - its fine.
If you can use Roles as your groups - this can do the trick, but if not, I'd define additional table, rather than intervining into prebuilt one. This is my opinion.
Edit 2
There are many ways you can work with aspnetdb. You can even embed it into your own database. Like this: Configuring ASP.NET 2.0 Application Services to use SQL Server 2000 or SQL Server 2005
Answering your particular question: you can access aspentdb via authentication API:
string userName = Membership.GetUserNameByEmail(emailToCheck);
if (userName != null)
or override membershipprovider, roleprovider and securityprovider or even access directly like described here
Membership, Role, and Security
Hope this helps!

Adding new data to DB when using 2 tables

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?

Resources