Basic User Template
I have created a template that allows you to create a project based upon the template. This template is a ZIP File that is included for download here.
Initial Version Basic Eaglin User Template Version 1.zip
Latest version (6/21/2012) Basic User Template Version 3.zip
You can create projects using this template after first importing. Here are a set of convenient video explaining the code. To add this to your menu when creating a new project follow the instructions at http://msdn.microsoft.com/en-us/library/y3kkate1.aspx . Bottom line is put the template above in the ProjectTemplates directory (below) and you will have access to it as a New Project under Visual C#
Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#\ (put zip file here)
Summary
Features of this template are outlined in the video links below. The database script for this system is included below. This demonstrates a simple role based user system and how to implement it. A lot of programming techniques are demonstrated as part of the template and in the supporting video materials.
Video Support
User Management Model in Basic User Template – http://online1.daytonastate.edu/player2.php?id=ed57844fa5e051809ead5aa7e3e1d555
User Controls in Basic User Template – http://online1.daytonastate.edu/player2.php?id=4ebccfb3e317c7789f04f7a558df4537
Database Code
Shown is the SQL Server Script for the Database as used in Version 1 of BasicUserTemplate
/****** Object: Table [dbo].[Users] Script Date: 06/13/2012 16:05:59 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Users]( [id] [int] IDENTITY(1,1) NOT NULL, [UserName] [nvarchar](255) NOT NULL, [UserPassword] [nvarchar](63) NOT NULL, [UserEmail] [nvarchar](255) NOT NULL, [UserCreatedDate] [datetime] NOT NULL, [UserIsDeletedBit] [bit] NOT NULL,PRIMARY KEY CLUSTERED ( [id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GO/****** Object: Table [dbo].[Roles] Script Date: 06/13/2012 16:05:59 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[Roles]( [id] [int] IDENTITY(1,1) NOT NULL, [RoleNameText] [varchar](50) NULL, [RoleDescriptionText] [nvarchar](max) NULL,PRIMARY KEY CLUSTERED ( [id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGO/****** Object: Table [dbo].[PageRoles] Script Date: 06/13/2012 16:05:59 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[PageRoles]( [id] [int] IDENTITY(1,1) NOT NULL, [PageFileName] [varchar](250) NOT NULL, [RoleID] [int] NOT NULL,PRIMARY KEY CLUSTERED ( [id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGO/****** Object: Table [dbo].[UserRoles] Script Date: 06/13/2012 16:05:59 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[UserRoles]( [id] [int] IDENTITY(1,1) NOT NULL, [UserID] [int] NOT NULL, [RoleID] [int] NOT NULL, [RoleAssignedByUserID] [int] NULL, [RoleAssignedDate] [datetime] NULL) ON [PRIMARY]GO/****** Object: StoredProcedure [dbo].[sp_InsertUser] Script Date: 06/13/2012 16:05:58 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE [dbo].[sp_InsertUser] ( @UserName NVARCHAR(255), @UserPassword NVARCHAR(63), @UserEmail NVARCHAR(255) )ASBEGININSERT INTO Users (UserName, UserPassword, UserEmail, UserCreatedDate, UserIsDeletedBit)VALUES (@Username, @UserPassword, @UserEmail, GETDATE(), 0) ENDGO/****** Object: View [dbo].[view_UserRoles] Script Date: 06/13/2012 16:06:00 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE VIEW [dbo].[view_UserRoles]ASSELECT Users.id AS ‘UserID’, Users.UserName AS ‘UserName’, Users.UserEmail AS ‘UserEmail’, Roles.id AS ‘RoleID’, RoleNameText AS ‘RoleName’FROM Users, Roles, UserRolesWHERE UserRoles.UserID = Users.id AND UserRoles.RoleID = Roles.idGO/****** Object: StoredProcedure [dbo].[sp_InsertRole] Script Date: 06/13/2012 16:05:58 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE [dbo].[sp_InsertRole] @RoleNameText VARCHAR(50), @RoleDescriptionText NVARCHAR(MAX)ASBEGINDECLARE @N INTSELECT @N = COUNT(*) FROM Roles WHERE RoleNameText = @RoleNameText IF @N = 0BEGININSERT INTO Roles (RoleNameText, RoleDescriptionText)VALUES (@RoleNameText, @RoleDescriptionText)ENDENDGO/****** Object: StoredProcedure [dbo].[sp_AssignRole] Script Date: 06/13/2012 16:05:58 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE [dbo].[sp_AssignRole] @UserID INT, @RoleID INT, @AssignedByUserID INT = NULLASBEGINDECLARE @N INTSELECT @N = COUNT(*) FROM UserRoles WHERE UserID = @UserID AND RoleID = @RoleID IF @N = 0BEGININSERT INTO UserRoles (UserID, RoleID, RoleAssignedByUserID, RoleAssignedDate)VALUES (@UserID, @RoleID, @AssignedByUserID, GETDATE())ENDENDGO/****** Object: StoredProcedure [dbo].[sp_InsertPageRole] Script Date: 06/13/2012 16:05:58 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE [dbo].[sp_InsertPageRole] @PageFileName VARCHAR(250), @RoleID INT = 1ASBEGINDECLARE @N INTSELECT @N = COUNT(*) FROM PageRoles WHERE PageFileName = @PageFileName AND RoleID = @RoleIDIF @N = 0BEGININSERT INTO PageRoles (PageFileName, RoleID)VALUES (@PageFileName, @RoleID) ENDENDGO/****** Object: ForeignKey [FK__UserRoles__RoleA__07020F21] Script Date: 06/13/2012 16:05:59 ******/ALTER TABLE [dbo].[UserRoles] WITH CHECK ADD FOREIGN KEY([RoleAssignedByUserID])REFERENCES [dbo].[Users] ([id])GO/****** Object: ForeignKey [FK__UserRoles__RoleI__060DEAE8] Script Date: 06/13/2012 16:05:59 ******/ALTER TABLE [dbo].[UserRoles] WITH CHECK ADD FOREIGN KEY([RoleID])REFERENCES [dbo].[Roles] ([id])GO/****** Object: ForeignKey [FK__UserRoles__UserI__0519C6AF] Script Date: 06/13/2012 16:05:59 ******/ALTER TABLE [dbo].[UserRoles] WITH CHECK ADD FOREIGN KEY([UserID])REFERENCES [dbo].[Users] ([id])GO |