A comprehensive ASP.NET Core Web API for managing user records, built for TechHive Solutions' internal tools. This project demonstrates enterprise-level API development with comprehensive middleware, security, and monitoring capabilities.
This API has been developed across three comprehensive activities and is now ready for production deployment with enterprise-level features including authentication, comprehensive logging, error handling, and security compliance.
- Full CRUD Operations: Create, Read, Update, and Delete user records
- Data Validation: Comprehensive input validation using Data Annotations
- Soft Delete: Users are marked as inactive rather than permanently deleted
- Search Functionality: Find users by department or email
- RESTful Design: Follows REST API best practices
- OpenAPI Documentation: Auto-generated API documentation
- Error Handling: Proper HTTP status codes and error messages
Retrieve all active users.
Response: 200 OK
[
{
"id": 1,
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@techhive.com",
"phoneNumber": "555-0101",
"department": "IT",
"position": "Software Developer",
"hireDate": "2023-01-15T00:00:00",
"isActive": true,
"createdAt": "2024-01-01T10:00:00",
"updatedAt": null
}
]Retrieve a specific user by ID.
Response: 200 OK or 404 Not Found
Retrieve all users in a specific department.
Response: 200 OK
Retrieve a user by email address.
Response: 200 OK or 404 Not Found
Create a new user.
Request Body:
{
"firstName": "Alice",
"lastName": "Johnson",
"email": "alice.johnson@techhive.com",
"phoneNumber": "555-0104",
"department": "Marketing",
"position": "Marketing Specialist",
"hireDate": "2024-01-15T00:00:00"
}Response: 201 Created or 409 Conflict (if email already exists)
Update an existing user.
Request Body (all fields optional):
{
"firstName": "Alice",
"lastName": "Smith",
"email": "alice.smith@techhive.com",
"phoneNumber": "555-0105",
"department": "Sales",
"position": "Sales Representative",
"hireDate": "2024-01-15T00:00:00",
"isActive": true
}Response: 200 OK, 404 Not Found, or 409 Conflict
Soft delete a user (marks as inactive).
Response: 200 OK or 404 Not Found
- .NET 9.0 SDK or later
- Visual Studio 2022 or VS Code
-
Navigate to the project directory:
cd UserManagementAPI -
Restore dependencies:
dotnet restore
-
Run the application:
dotnet run
-
The API will be available at:
- API Base URL:
https://localhost:7001orhttp://localhost:5000 - Swagger Documentation:
https://localhost:7001/swaggerorhttp://localhost:5000/swagger
- API Base URL:
-
Get All Users
- Method:
GET - URL:
https://localhost:7001/api/users
- Method:
-
Get User by ID
- Method:
GET - URL:
https://localhost:7001/api/users/1
- Method:
-
Create New User
- Method:
POST - URL:
https://localhost:7001/api/users - Headers:
Content-Type: application/json - Body:
{ "firstName": "Sarah", "lastName": "Wilson", "email": "sarah.wilson@techhive.com", "phoneNumber": "555-0106", "department": "Finance", "position": "Financial Analyst", "hireDate": "2024-02-01T00:00:00" } - Method:
-
Update User
- Method:
PUT - URL:
https://localhost:7001/api/users/1 - Headers:
Content-Type: application/json - Body:
{ "department": "Engineering", "position": "Senior Developer" } - Method:
-
Delete User
- Method:
DELETE - URL:
https://localhost:7001/api/users/1
- Method:
# Get all users
curl -X GET "https://localhost:7001/api/users"
# Get user by ID
curl -X GET "https://localhost:7001/api/users/1"
# Create new user
curl -X POST "https://localhost:7001/api/users" \
-H "Content-Type: application/json" \
-d '{
"firstName": "Sarah",
"lastName": "Wilson",
"email": "sarah.wilson@techhive.com",
"phoneNumber": "555-0106",
"department": "Finance",
"position": "Financial Analyst",
"hireDate": "2024-02-01T00:00:00"
}'
# Update user
curl -X PUT "https://localhost:7001/api/users/1" \
-H "Content-Type: application/json" \
-d '{
"department": "Engineering",
"position": "Senior Developer"
}'
# Delete user
curl -X DELETE "https://localhost:7001/api/users/1"UserManagementAPI/
βββ Controllers/
β βββ UsersController.cs # API endpoints
βββ Models/
β βββ User.cs # User entity model
β βββ UserDto.cs # Data transfer objects
βββ Services/
β βββ IUserService.cs # Service interface
β βββ UserService.cs # Service implementation
βββ Program.cs # Application configuration
βββ appsettings.json # Configuration settings
βββ README.md # This file
The User model includes the following fields:
Id(int): Unique identifierFirstName(string): User's first nameLastName(string): User's last nameEmail(string): Unique email addressPhoneNumber(string): Contact phone numberDepartment(string): User's departmentPosition(string): User's job positionHireDate(DateTime): Date when user was hiredIsActive(bool): Whether the user is activeCreatedAt(DateTime): Record creation timestampUpdatedAt(DateTime?): Last update timestamp
The API returns appropriate HTTP status codes:
200 OK: Successful operation201 Created: Resource created successfully400 Bad Request: Invalid input data404 Not Found: Resource not found409 Conflict: Resource conflict (e.g., duplicate email)
- Database integration (Entity Framework Core)
- Authentication and authorization
- Pagination for large datasets
- Advanced filtering and sorting
- Logging and monitoring
- Unit and integration tests
- Docker containerization
This is a demonstration project for learning purposes. Feel free to extend and improve the functionality as needed.