需求分析
这个类似于 StackOverFlow 的论坛由下面四个重要部分组成:
User management:用户的注册、登入(出)、访问控制
Forum management:论坛的 CRUD 和锁定
Topic management:论坛中帖子的 CRUD 和回复及锁定
Message management:用户间收发消息
数据库设计
User
A user is a person registered in the CoreBBsystem.
Name | Type | Description |
---|---|---|
ID | int | Theauto-generated unique ID of the user |
Name | string | Thedisplay name of the user |
PasswordHash | string | Theencrypted password |
Description | string | Theuser’s introduction |
IsAdministrator | bool | Indicatesif the user is an administrator |
IsLocked | bool | Indicatesif the user is locked |
RegisterDateTime | DateTime | Theregistration date and time |
LastLogInDateTime | DateTime | Thelast login date and time |
The user-related features include:
User can register to the CoreBBapplication.
If there are no prior userswithin the application, the user’s IsAdministrator will be set to true automatically.
User can log in and log out.
A locked user cannot log in.
Only logged-in users can posttopics.
Only administrators can manageforums.
Only administrators can manageother users.
Forum
A forum is a container of topics. Each forumhas its name, which indicates the category of the topics.
Name | Type | Description |
---|---|---|
ID | int | Theauto-generated unique ID of the forum |
OwnerID | int | TheID of the user (administrator) who created this forum |
Name | string | Thename/title of the forum |
Description | string | TheIntroduction to the forum |
IsLocked | bool | Indicatesif the forum is locked |
CreateDateTime | DateTime | Thelast login date and time |
The forumrelated features include:
Only administrators can createand manage forums.
Locked forums will be hiddenfrom common users but not administrators.
Topic
A topic is a content item posted in a forum.
Name | Type | Description |
---|---|---|
ID | int | Theauto-generated unique ID of the topic |
OwnerID | int | TheID of the user who posted this topic |
ForumID | int | TheID of the forum to which the topic belongs |
RootTopicID | int | TheID of the first (root) topic of the “topic tree” |
ReplyToTopicID | int | TheID of the topic to which the current topic replies |
Title | string | Thetitle of the topic |
Content | string | Thecontent of the topic |
PostDateTime | DateTime | Thepost date and time |
ModifiedByUserID | int | TheID of the user who modified this topic |
ModifiedDateTime | DateTime | Themodification date and time |
IsLocked | bool | Indicatesif the topic is locked |
The topicrelated features include:
Any logged-in user can createand manage their own topics.
Administrators can edit otherusers’ topics.
A topic and its descendant topicform a topic tree. All topics in the same topic tree share the same roottopic ID.
Users can reply to a non-lockedtopic.
Message
A message is a content item sent betweenusers. In some forum systems, messages are also called private messages orinternal messages.
Name | Type | Description |
---|---|---|
ID | int | Theauto-generated unique ID of the message |
FromUserID | int | TheID of the user who sends this message |
ToUserID | int | TheID of the user to whom this message is sent |
SendDateTime | DateTime | Thesend date and time |
IsRead | bool | Indicatesif this message has been read |
Title | string | Thetitle of the message |
Content | string | Thecontent of the message |
数据库实现
SQLServer 实现
课程提供了 CoreBB.sql,用于在 SQL Server 中生成数据库。
CoreBB.zip
MySQL 实现
如果想在 MySQL 中实现,推荐参考 复制 SQLServer 数据库至 MySQL。先在 SQLServer 中创建数据库再通过 EF Core 将其复制到 MySQL。