A simple ASP.NET MVC web application for Visual Studio 2022 that allows visitors to post guestbook messages and administrators to manage them. Features user authentication with ASP.NET Core Identity and real-time updates via SignalR.
- View Approved Messages: Browse all approved guestbook messages on the home page
- Add New Messages: Submit new messages with your name, message text, and optional category
- View Employee Replies: See official employee responses to messages
- User Registration: Create an account to associate messages with your profile
- Automatic Database Storage: All messages are automatically saved to a local SQLite database
- Real-Time Updates: Pages automatically refresh when database changes occur via SignalR
- Success Notifications: Receive confirmation when messages are submitted
- User Registration: Create a new account with email and password
- User Login/Logout: Secure authentication with ASP.NET Core Identity
- Role-Based Access: Administrator, Employee, and User roles
- Remember Me: Option to stay logged in
- Employee Dashboard: Dedicated panel for employees to manage message replies
- Reply to Messages: Respond to approved guest messages with official replies
- View Reply History: See who replied and when for each message
- Reply Validation: Character limits and validation for quality responses
- Secure Admin Panel: Only accessible to users with Administrator role
- View All Messages: See both approved and pending messages in a comprehensive table
- Approve Messages: Approve pending messages with a single click
- Edit Messages: Modify approved message content
- Delete Messages: Remove any message (approved or pending)
- Status Badges: Visual indicators to distinguish between approved and pending messages
- User & Category Info: View which user posted each message and its category
- User Management Dashboard: View all registered users
- Create Users: Add new users with email, password, and profile details
- Edit Users: Update user information and reset passwords
- Delete Users: Remove user accounts (with protection against self-deletion)
- Role Assignment: Assign or remove Employee role from users
- View User Roles: See current roles for each user
- Framework: ASP.NET Core 9.0 MVC
- Authentication: ASP.NET Core Identity
- Real-Time Communication: SignalR
- Database: SQLite with Entity Framework Core 9.0
- UI: Razor Views with Bootstrap 5
- Architecture: MVC (Model-View-Controller)
The application uses 4 main entity types with relationships:
-
ApplicationUser (extends IdentityUser)
- FirstName, LastName, CreatedAt
- Has many Messages
- Has many Replies (as RepliedByUser)
- Has one UserProfile
-
GuestBookMessage
- Name, Message, CreatedAt, IsApproved
- Reply, RepliedAt, RepliedByUserId (employee reply functionality)
- Belongs to User (optional)
- Belongs to Category (optional)
- Belongs to RepliedByUser (optional - employee who replied)
-
Category
- Name, Description, CreatedAt
- Has many Messages
- Seeded with: General, Feedback, Questions
-
UserProfile
- Bio, Location, WebsiteUrl
- Belongs to User
GuestBook/
├── Controllers/
│ ├── HomeController.cs # Visitor functionality
│ ├── AdminController.cs # Admin functionality (messages & user management)
│ ├── EmployeeController.cs # Employee reply functionality
│ └── AccountController.cs # Authentication (Login/Register/Logout)
├── Models/
│ ├── ApplicationUser.cs # Extended Identity user
│ ├── GuestBookMessage.cs # Message entity with reply support
│ ├── Category.cs # Category entity model
│ ├── UserProfile.cs # User profile entity
│ └── ViewModels/ # Login/Register/User view models
├── Views/
│ ├── Home/
│ │ ├── Index.cshtml # View approved messages with replies
│ │ └── Create.cshtml # Add new message
│ ├── Admin/
│ │ ├── Index.cshtml # Manage all messages
│ │ ├── Edit.cshtml # Edit approved messages
│ │ ├── UserManagement.cshtml # User list and management
│ │ ├── CreateUser.cshtml # Create new user
│ │ └── EditUser.cshtml # Edit user details
│ ├── Employee/
│ │ ├── Index.cshtml # Employee dashboard
│ │ └── Reply.cshtml # Reply to messages
│ ├── Account/
│ │ ├── Login.cshtml # Login page
│ │ ├── Register.cshtml # Registration page
│ │ └── AccessDenied.cshtml # Access denied page
│ └── Shared/
│ └── _Layout.cshtml # Main layout with SignalR integration
├── Hubs/
│ └── DatabaseHub.cs # SignalR hub for real-time notifications
├── Services/
│ └── DatabaseWatcherService.cs # Background service for database monitoring
├── Data/
│ └── ApplicationDbContext.cs # EF Core DbContext with Identity
├── Migrations/ # EF Core migrations
└── Program.cs # Application startup with Identity & SignalR config
- .NET 9.0 SDK or later
- Visual Studio 2022 (recommended) or Visual Studio Code
- Git (for cloning the repository)
-
Clone the repository
git clone https://github.com/DenysTkach/GuestBook.git cd GuestBook -
Open the solution
- Open
GuestBook.slnin Visual Studio 2022, or - Navigate to the
GuestBookfolder in your terminal
- Open
-
Restore dependencies
cd GuestBook dotnet restore -
Apply database migrations (if not already applied)
dotnet ef database update
-
Build and run the application
Using Visual Studio:
- Press
F5or click the "Run" button
Using Command Line:
dotnet run
- Press
-
Access the application
- Open your browser and navigate to
https://localhost:5022(or the port shown in the terminal)
- Open your browser and navigate to
When the application starts for the first time, it automatically creates the following roles and accounts:
- Administrator - Full access to all features including user management
- Employee - Can view approved messages and reply to them
- User - Standard registered user
- Email:
admin@guestbook.com - Password:
Admin123!
- Email:
employee@guestbook.com - Password:
Work123!
- Navigate to the home page to view approved messages and employee replies
- Click "Add New Message" to submit a new message
- Fill in your name, message, and optionally select a category
- Your message will be saved and awaiting admin approval
- Click "Register" to create a new account
- Or click "Login" if you already have an account
- Once logged in, your messages will be associated with your account
- Login with an employee account (or any account with Employee role)
- Click "Employee" in the navigation menu (visible only to employees)
- View all approved messages in the employee dashboard
- Click "Reply" to respond to any guest message
- Replies are displayed publicly alongside the original message
- Login with the admin account (or any account with Administrator role)
- Click "Admin" in the navigation menu to manage messages
- View all messages with their approval status, user, and category
- Click "Approve" to approve pending messages
- Click "Edit" to modify approved message content
- Click "Delete" to remove any message
- Click "User Management" to manage user accounts
- Create new users
- Edit user details and reset passwords
- Assign or remove Employee role
- Delete user accounts
The application uses SignalR to provide real-time page updates:
- When the SQLite database file changes, all connected clients are automatically notified
- Pages refresh automatically to show the latest data
- No manual refresh needed when other users or administrators make changes
The application uses SQLite for data storage. The database file (guestbook.db) is automatically created in the project root directory when you first run the application.
Note: The database file is excluded from version control via .gitignore.
-
Add a new migration:
dotnet ef migrations add MigrationName
-
Update database:
dotnet ef database update
-
Remove last migration:
dotnet ef migrations remove
The application follows standard ASP.NET Core MVC conventions:
- Models: Define data entities and business logic
- Views: Razor templates for UI rendering
- Controllers: Handle HTTP requests and coordinate between models and views
- DbContext: Manages database operations with Entity Framework Core
- Identity: Handles user authentication and authorization
- SignalR: Provides real-time communication for database change notifications
- Hosted Services: Background services for database file monitoring
This project is open source and available for educational purposes.