User permission management design (2)

Source: Internet
Author: User
The previous article describes the database design. This time we will talk about the implementation in net.

The implementation of the UI is mainly to facilitate user operations and consider the user experience.

Background Management menu

Role management list

New User

Permission allocation

Now, we generate entity classes based on the database. The Design of entity classes is generally not much different from that of database fields. You can use the relevant ORM to generate

Let's look at the BLL layer.

Here I am the user-role code. Other codes can be used to see what the corresponding method is based on the database stored procedure.

Program code // <summary>
/// Userrole business logic layer
/// </Summary>
Public class memberrole: ABC. idal. SYS. imemberrole
{

Private Static readonly ABC. idal. SYS. imemberrole Dal = ABC. dalfactory. dataaccess. creatememberrole ();

/// <Summary>
/// Add
/// </Summary>
/// <Param name = "model"> Model </param>
/// <Returns> bool </returns>
Public bool insert (ABC. entity. SYS. memberroleinfo Model)
{
Return Dal. insert (model );
}

/// <Summary>
/// Modify
/// </Summary>
/// <Param name = "model"> Model </param>
/// <Returns> bool </returns>
Public bool Update (ABC. entity. SYS. memberroleinfo Model)
{

Return Dal. Update (model );
}
/// <Summary>
/// Delete
/// </Summary>
/// <Param name = "memberroleid"> </param>
/// <Returns> bool </returns>
Public bool Delete (INT memberroleid)
{

Return Dal. Delete (memberroleid );
}

/// <Summary>
/// Delete a role based on the user ID
/// </Summary>
/// <Param name = "memberid"> </param>
/// <Returns> </returns>
Public bool deletebymemberid (INT memberid)
{
Return Dal. deletebymemberid (memberid );
}

/// <Summary>
/// Determine whether the same user-role exists
/// </Summary>
/// <Param name = "memberid"> </param>
/// <Param name = "roleid"> </param>
/// <Returns> </returns>
Public bool ifexist (INT memberid, int roleid)
{
Return Dal. ifexist (memberid, roleid );
}

/// <Summary>
/// Display the user role based on the user ID
/// </Summary>
/// <Param name = "memberid"> memberid </param>
/// <Param name = "pageindex"> pageindex </param>
/// <Param name = "pagesize"> pagesize </param>
/// <Returns> ilist <ABC. entity. SYS. memberroleinfo> </returns>
Public ilist <ABC. entity. SYS. memberroleinfo> List (INT memberid, int pagesize, int pageindex)
{
Return Dal. List (memberid, pagesize, pageindex );

}

/// <Summary>
/// Obtain the member list based on the role ID
/// </Summary>
/// <Param name = "roleid"> </param>
/// <Param name = "pagesize"> </param>
/// <Param name = "pageindex"> </param>
/// <Returns> </returns>
Public ilist <ABC. entity. SYS. memberroleinfo> listbyrole (INT roleid, int pagesize, int pageindex)
{
Return Dal. listbyrole (roleid, pagesize, pageindex );
}
/// <Summary>
/// Calculate the User Role Based on the memberid
/// </Summary>
/// <Param name = "memberid"> memberid </param>
/// <Returns> sum of roles by memberid </returns>
Public int count (INT memberid)
{
Return Dal. Count (memberid );
}

/// <Summary>
/// Calculate the number of members based on the role
/// </Summary>
/// <Param name = "roleid"> </param>
/// <Returns> </returns>
Public int countbyroleid (INT roleid)
{
Return Dal. countbyroleid (roleid );
}

As for front-end permission verification, I took a relatively discounted approach. I compared the title of the current page with the module name in the database by obtaining it, determine whether the user has the corresponding operation permissions. The following code:

Program code // <summary>
/// Verify the operation permission
/// </Summary>
Protected void valiatememberrights ()
{
// Functionid 1 browse 2 add 3 modify 4 Delete 5 query 6 Import 7 export 8 details

String pagetitle = This. Page. Title. tostring ();
ABC. BLL. SYS. Module bllmodule = new ABC. BLL. SYS. Module ();
Int moduleid = bllmodule. getmoduleidbypagetitle (pagetitle );
Int memberid = convert. toint32 (ABC. Common. encrypt. Decode (session ["memberid"]. tostring ()));

ABC. BLL. SYS. Member bllmember = new ABC. BLL. SYS. Member ();

If (bllmember. validateright (memberid, moduleid, 1) = false)
{

ABC. Common. js. closewindow ();
}

}

Some netizens suggested not to use this mode, or to combine menus with permissions.

In the end, the most important thing is the display form of the UI front-end. Here are some tips

1. Bind checkboxlist in the gridview and call the data in the database

2. Use JavaScript to select between listboxes or use listitem for operations

3. How to display the list of function modules with unlimited classification to achieve the best user operations

For the first one, I took some time to think about it. Although the effect was achieved, it is not recommended that you use it. If the data volume is large, it may lead to slow page opening.

For the second one, it is better to use the client JavaScript. Of course, if your server is powerful enough, using listitem is also good.

For the third, I have been looking for controls like the Treeview IN THE gridview. there are indeed many controls on the Internet, but they are not flexible enough. But they should be implemented through jquery.

I would like to provide you with more information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.