My permission system is designed to implement MVC4 + WebAPI + EasyUI + Knockout (4) authorization code Maintenance

Source: Internet
Author: User

I. Preface
In the permission system design, authorization code is used to control data access permissions. The authorization code is simply a tree-structured data and has no other business significance. The page features are very simple.

Ii. Text
We actually want to implement a treegrid addition, deletion, and modification function, which is technically easy to implement.
1. Create a controller PermissionControlle. cs

     

The mvc controller does not need to write any code.

2. Create a view

    
Refresh add edit Delete Save authorization name authorization code superior authorization

This view is quite concise compared to other pages.

3. Front-end implementation mainly implements online editing of easyui treegrid and the interaction logic of buttons

Self =. grid = 4, h: 40'/api/sys/permission ''_ id'' permissionname' = utils. copyProperty (d. rows | d, ["PermissionCode"], ["_ id"], utils. toTreeData (d, '_ id', 'parentcode', "children ". refreshClick =. addClick = row = {_ id: utils. uuid (), PermissionCode: '', PermissionName: '''append', {parent: '''select'" datagrid ". editClick = row = self. grid. treegrid ('getselected' treeData = JSON. parse (JSON. stringify (s Elf. grid. treegrid ('getdata ')). replace (/_ id/g, "id "). replace (/PermissionName/g, "text" "id": 0, "text": "" gridOpt = $. data (self. grid. $ element () [0], "datagrid" col = $. grep (gridOpt. columns [0], (n) {n. field = 'parentcode'}) [0 = {type: 'combotree' = isChild = 'warning', 'you cannot set yourself or your subordinates as the parent node '! Self. grid. treegrid ('ineinedit '=. grid. onBeforeDestroyEditor = editors+'parentcode'{.tar get. combotree ('gettext '. deleteClick = row = self. grid. treegrid ('getselected'' remove '"datagrid ". grid. onDblClickRow =. grid. onClickRow = edit_id = (!! (Self. grid. treegrid ('validaterow', edit_id) {self. grid. treegrid ('enabled' = {self. grid. treegrid ('select '. saveClick = post = com. editTreeGridViewModel (self. grid ). getChanges (['_ id', 'permissioncode', 'permissionname', 'parentcode' (self. grid. onClickRow () & '/api/sys/permission/edit''success', 'saved successfully! ''Acceptchanges'


4. Now, I think I am reading front-end articles. In fact, I am also very powerful in the background framework ., Now let's look at the processing in web api. Two web APIs are used here.
1. GET authorization code data: GET/api/sys/permission
2. Save changes in treegrid (including new, modified, and Deleted Data) POST/api/sys/permission

Pay attention to the WebApi implementation, which is a simple code implementation.

     sys_permissionService service =  IEnumerable<dynamic>         pQuery =                  listWrapper = RequestWrapper.Instance().LoadSettingXmlString(        service.Edit(

The above two methods have implemented all the functions. Here we seem to call all the methods in the service, so let's look at the service class.

  sys_permissionService : ServiceBase<sys_permission>

This data service class is empty and does not have any methods. It only inherits my service base class and has the methods defined in the base class.
Here, I will briefly introduce my service base class. As long as the service class inherits the service base class, it will have the following methods:

 ServiceBase( List<dynamic> GetDynamicList(ParamQuery param = );      dynamic GetDynamicListWithPaging(ParamQuery param = );  List<T> GetModelList(ParamQuery param = );              dynamic GetModelListWithPaging(ParamQuery param = );         T GetModel(ParamQuery param);                               dynamic GetDynamic(ParamQuery param);                       TField GetField<TField>(ParamQuery param);                                               OnAfterEditDetail(EditEventArgs arg);

Each object, such as query, add, modify, delete, and stored procedure, corresponds to a parameter constructor. The query corresponds to ParamQuery, and each write method can be the same as that of linq, Which is concise.
Now, let's look at the code in my webapi. Is there only two lines of code for each method and complicated operations have been implemented.
Just because of my framework, I was freed from the background and had more time and energy to study the front-end.

III,
This function can be completed with a few simple codes. Let's take a look at the implementation results.

OK for adding, modifying, and deleting tests

 

V. Subsequent descriptions
If you think it is good, please [Recommend] me. Your support is the motivation for me to stick to writing this series of articles.
Technical Exchange QQ Group: Group 1: 328510073 (full), group 2: 167813846. welcome to join us.

Blog series links:

My permission system design and implementation MVC4 + WebAPI + EasyUI + Knockout (3) Graphical mechanism tree

My permission system is designed to implement MVC4 + WebAPI + EasyUI + Knockout (2) menu navigation

My permission system is designed to implement MVC4 + WebAPI + EasyUI + Knockout (1)

Related Article

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.