ASP (7) organization, role, user rights

Source: Internet
Author: User

0 ASP. Project Rights Management System (0) out of nothing

1 ASP. Project Rights Management System (1) using Adminlte to build the front end

2 ASP. Access Management System (2) function and entity design

3 ASP. Access management system for real-Life Project (3) using PostgreSQL via EntityFramework core

4 ASP (4) Multi-project tiered implementation of dependency injection, warehousing and service

5 ASP. Project Rights Management System (5) User Login

6 ASP. Access Management System (6) Functional management

7 ASP. Project Rights Management System (7) organization, role, user rights

GitHub Source Address

The implementation of the basic framework of the project and the functions of the menu management is realized, the following is the basic implementation method of organization management, user management and role Rights management, the basic implementation steps are as follows:

0 Storage Interface Definition

Under the Irepositories folder of the Fonour.domain project, create a warehousing interface that inherits from the generic interface irepository<t>, and expand the interface according to the actual situation.

1 Warehousing Operation Implementation

Implementation of the interface defined above in the Repositories folder of the Fonour.entityframeworkcore project

2 defining DTOs and creating mapping relationships with entities

In the Fonour.application project, the corresponding DTO class is created according to the implementation of functional management, and the mapping between the created DTO and the concrete entity is increased in FonourMapper.cs.

3 Defining the service interface and implementation

In Fonour.application, the Application service interface and corresponding implementation are defined according to the actual needs.

4 Create controller to implement action

Add the controller that corresponds to the business function in the FONOUR.MVC project, and the action of the corresponding operation.

5 Front-end operation implementation

With Adminlte, the front-end correlation is implemented with AJAX operations.

The above operations, which can be generated automatically with the code generator, can greatly increase development efficiency.

0 Organizational Structure Management

Organizational management and functional management are very similar, are simple single-table additions and deletions to the operation, in the interface layout is the same, the left is the organization tree, the right side of the selected node corresponding to the sub-organizational list. Also includes new top-level, new, delete, edit and other actions. Just follow the implementation steps described above, and gradually to achieve, the final effect is as follows:

1 Role Management

The page layout is designed to have a list of roles on the left, a function tree on the right, a list of functions that are already associated when clicked on the left side, and the ability to modify the selected item directly on the right to adjust the function permissions for the current role.

1.0 List Selected Events add

Instead of using the table plug-in, simply add the click event to the selected TR, change the color of the clicked TR, and clear the background color of the unchecked TR, capturing the ID of the currently selected line in the event, to display the processing of the corresponding function permission according to the role ID.

$ ("Table > Tbody > TR"). Click (function () {    $ ("Table > Tbody > TR"). Removeattr ("style")    $ (this). attr ("Style", "padding:0px; FONT-SIZE:12PX!important; line-height:1.5!important; " >);    Selectedrole = $ (this). Find ("Input"). Val ();    Loadpermissionbyrole (Selectedrole);});
Load functions According to the selected role Permissions function Loadpermissionbyrole (selectedrole) {    $.ajax ({        type: "Get",        URL: "/role/ Getmenusbyrole?roleid= "+ selectedrole +" &_t= "+ New Date (). GetTime (),        success:function (data) {            $ (" # Treediv "). Find (" Li "). each (function () {                $ (" #treeDiv "). Jstree (" Uncheck_node ", $ (this));                if (Data.indexof (this). attr ("id"))! =-1) {                    $ ("#treeDiv"). Jstree ("Check_node", $ (This)),}}}    } );};
2 User Management

In user management, a user role assignment is required, and a user can have multiple roles. Role Multi-Select this uses the Select2 plugin, which can be added directly through the Bower Manager to add the Select2 dependency reference, added after the discovery style and the existing framework is not in harmony with the style, no further adjustments, directly using the Select2 I have previously modified.

2.0 Using Select2

Place the Selcet2 folder under the/wwwroot/lib/folder of the FONOUR.MVC project, modify the contents of the layout page _layout.cshtml, and add references to Select2.css, Select2.js, and the Chinese configuration.

<link rel= "stylesheet" href= "~/lib/select2/select2.css" >
<script src= "~/lib/select2/select2.js" ></script><script src= "~/lib/select2/select2_locale_ Zh-cn.js "></script>

Select2 Loading Data

The interface element adds multiple= "multiple" property, allowing Select2 to support multiple selection operations.

<div class= "Form-group" >    <label class= "col-sm-2 control-label" for= "" > Owned roles </label>    < Div class= "col-sm-10" >        <select id= "Role" class= "Form-control" style= "padding:0px" multiple= "multiple" >        </select>    </div></div>

Call the Select2 () method to create a SELECT2 interface element, return a role list JSON object through an AJAX request, and bind the role information to the Select2 control via the option tag.

function Loadroles (data) {    $ ("#Role"). Select2 ();    var option = "";    $.each (data.roles, function (I, item) {        option + = "<option value= '" + item.id + ">" + item.name + "</option& gt; "    })    $ ("#Role"). HTML (option);}

Select2 supports multiple selections, as well as fuzzy filtering. The interface effect is as follows:

3 Summary

On the basis of the basic framework, the implementation of the function is not complex, so far, the four main basic functions have been implemented, which will involve some of the details of the problem, such as the uniqueness of authentication, password encryption and other functions, did not do too much processing. The next step is to implement the ability to dynamically load the corresponding function menu according to the login user, as well as the function operation permission judgment.

ASP (7) organization, role, user rights

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.