Asp. Net Core project practice-permission management system (2) function and entity design, core permission management system

Source: Internet
Author: User

Asp. Net Core project practice-permission management system (2) function and entity design, core permission management system

0 Asp. Net Core: permission management system (0)

1 Asp. Net Core project practice-permission management system (1) Use AdminLTE to build a front-end

2 Asp. Net Core project practice-permission management system (2) function and entity Design

3. Asp. Net Core: permission management system (3) using PostgreSQL through EntityFramework Core

4 Asp. Net Core project practices-permission management system (4) multi-project hierarchical implementation of dependency injection, warehousing, and services

5 Asp. Net Core project practices-permission management system (5) User Logon

6 Asp. Net Core project practice-permission management system (6) function Management

7 Asp. Net Core project practice permission management system (7) Organization Management

Github Source Code address

0 Function Design

The simplest and most basic permission management system includes organization management, role management, user management, function management, and Role authorization.

1. Function management includes two levels: function menu and function page button.

2. Role authorization.

3. Each user can have multiple roles. the user's actual permissions are obtained based on the union of multiple roles.

0.0 Organization Management

To manage organizations (or Departments, the organization mainly includes the Department name, department code, Department Head, contact phone number, remarks, parent department, creator, and creation phone number.

Organizational Unit management includes adding top-level, adding (adding subordinates of the selected Department), editing, and deleting functions.

Considering that basic entities related to permission management such as organizations and users are often used in business data, for example, if you want to record information such as the department and creator of the business data (such as DepartmentId and UserId recorded in the form of foreign keys), to avoid deletion of organization, user, and other information, the relevant entities cannot be found in business data. To ensure data integrity, the entities designed for permission management are uniformly implemented.Soft Delete(Logical deletion using a delete tag, non-physical deletion.

0.1 function Management

Unified maintenance of system functions. In-depth control is implemented here, and the business logic operation buttons on each functional interface are managed to be displayed in a tree format, the object is identified by a tag attribute as a navigation menu or an operation button under the menu. Take the organization management as an example. The function Management contains an item named organization management, it includes adding organizations, adding top-level organizations, editing organizations, and deleting organizations.

Function management entities mainly include attributes such as parent, serial number, name, encoding, address, type (navigation menu, function button), icon, and remarks.

Function management mainly includes adding top-level, new, edit, and delete functions.

0.2 role management

A role is an abstraction of a group of users with the same functions. The permission management system assigns permissions for specific functions to the role for permission management.

A role entity includes attributes such as the role code, role name, creator, Creation Time, and remarks.

Role management includes adding roles, editing roles, deleting roles, and Role authorization.

Role authorization is an operation that grants the function navigation menu and function page buttons to the selected role. After a user logs on, the user obtains the role based on the current user, obtains the functions of all roles of the user, and determines whether the function menu and related functional interface buttons are available.

0.3 user management

User entities mainly include user name, password, user name, email address, mobile phone number, remarks, creator, creation time, Last Logon Time, number of logins, department, and other attributes.

User management mainly includes adding users, Editing Users, deleting users, resetting passwords, and other functions.

When adding and editing a user, you must first select the user's department and assign the corresponding role to the current user.

1 entity Design

Based on the above functional design, the entity class is designed as follows. Create a generic base class Entity <TPrimaryKey> for all objects. The default primary key type is the Guid Entity class. All objects in the permission management system are inherited from the Entity base class, if you want to implement other types of primary keys, the newly created object can be inherited from the Entity <TPrimaryKey> generic base class.

/// <Summary> /// generic Entity base class /// </summary> /// <typeparam name = "TPrimaryKey"> Primary Key type </typeparam> public abstract class Entity <TPrimaryKey >{/// <summary> /// primary key /// </summary> public virtual TPrimaryKey Id {get; set ;}//< summary> // defines the object base class with the default primary key type of Guid /// </summary> public abstract class Entity: entity <Guid> {}
1.0 organizational entity
/// <Summary> /// Department entity /// </summary> public class Department: entity {// <summary> // Department Name // </summary> public string Name {get; set ;} /// <summary> /// department ID /// </summary> public string Code {get; set ;} /// <summary> /// department head /// </summary> public string Manager {get; set ;} /// <summary> /// contact number /// </summary> public string ContactNumber {get; set ;} /// <summary> /// remarks /// </summ Ary> public string Remarks {get; set ;}/// <summary> /// parent department ID /// </summary> public Guid ParentId {get; set ;} /// <summary> /// creator /// </summary> public Guid CreateUserId {get; set ;} /// <summary> /// creation time /// </summary> public DateTime? CreateTime {get; set ;}/// <summary >/// whether or not the object has been deleted /// </summary> public int IsDeleted {get; set ;} /// <summary> /// contains the User /// </summary> public virtual ICollection <User> Users {get; set ;} /// <summary> /// creator information /// </summary> public virtual User CreateUser {get; set ;}}
1.1 functional entities
/// <Summary> /// function Menu entity /// </summary> public class Menu: entity {// <summary> // parent ID /// </summary> public Guid ParentId {get; set ;} /// <summary> /// serial number /// </summary> public int SerialNumber {get; set ;} /// <summary> /// menu Name /// </summary> public string Name {get; set ;} /// <summary> /// menu encoding /// </summary> public string Code {get; set ;} /// <summary> /// menu address /// </summary> publi C string Url {get; set ;}/// <summary> // type: 0 navigation menu; 1 OPERATION button. /// </Summary> public int Type {get; set ;}/// <summary> // menu Icon /// </summary> public string Icon {get; set ;}//< summary> /// menu Remarks //</summary> public string Remarks {get; set ;}
}
1.2 role entity
public class Role : Entity{     public string Code { get; set; }     public string Name { get; set; }     public Guid CreateUserId { get; set; }     public DateTime? CreateTime { get; set; }     public string Remarks { get; set; }     public virtual User CreateUser { get; set; }     public virtual ICollection<User> Users { get; set; }     public virtual ICollection<Menu> Menus { get; set; }}
1.3 user entity
Public class User: Entity {// <summary> // User name // </summary> public string UserName {get; set ;} /// <summary> /// Password /// </summary> public string Password {get; set ;} /// <summary> /// user Name /// </summary> public string Name {get; set ;} /// <summary> /// EMail address /// </summary> public string EMail {get; set ;} /// <summary> /// mobile phone number /// </summary> public string MobileNumber {get; set ;}/// <Summary> // Remarks /// </summary> public string Remarks {get; set ;} /// <summary> /// creator /// </summary> public Guid CreateUserId {get; set ;} /// <summary> /// creation time /// </summary> public DateTime? CreateTime {get; set ;}/// <summary> /// last logon time /// </summary> public DateTime LastLoginTime {get; set ;} /// <summary> /// Number of logins /// </summary> public int LoginTimes {get; set ;} /// <summary> /// department ID /// </summary> public Guid DeptmentId {get; set ;} /// <summary> /// whether the object has been deleted /// </summary> public int IsDeleted {get; set ;} /// <summary> /// Department entity /// </summary> public virtual Department {get; set ;} /// <summary> /// creator object /// </summary> public virtual User CreateUser {get; set ;} /// <summary> /// Role set /// </summary> public virtual ICollection <Role> Roles {get; set ;}
}
2. Conclusion

This document mainly designs functions and entities for the simplest permission management system. related entity files are added to the project. The current solution structure is as follows:

Next, we will introduce how to use the PostgreSQL database through EntityFramework Core in Asp. Net Core.

Reference page: http://qingqingquege.cnblogs.com/p/5933752.html

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.