This project showcases a basic implementation of a Hangfire application. It provides an API for managing products, allowing users to create, update, and delete products, as well as sort products based on their prices. Along with Hangfire, a task is created to periodically monitor the total number of products in the database and log it. This task runs every 1 minute and provides real-time insights into the product count. The integration of Hangfire enables efficient background job scheduling and execution, ensuring seamless product management and automatic monitoring of the product count.
- Clone the repository
git clone https://github.com/BerkayMehmetSert/net.Hangfire.Logging.git
- Install dependencies
dotnet restore
- Create a database in SQL Server
CREATE DATABASE HangFireDb
- Run the project
dotnet run
- Open
Hangfire Dashboard
in your browser
http://localhost:5228/hangfire
Get all products
GET /api/product
Response body:
{
"success": true,
"message": "Products retrieved successfully",
"data": [
{
"id": "4b4663fb-a819-413e-9d15-bd0b577138a1",
"name": "Product 1",
"description": "Description 1",
"price": 100
},
{
"id": "ef481be9-7363-4420-b62a-546d2a93420b",
"name": "Product 2",
"description": "Description 2",
"price": 110
}
]
}
Get product by id
GET /api/product/{id}
Response body:
{
"success": true,
"message": "Product retrieved successfully",
"data": {
"id": "4b4663fb-a819-413e-9d15-bd0b577138a1",
"name": "Product 1",
"description": "Description 1",
"price": 100
}
}
Get product by name
GET /api/product/name/{name}
Response body:
{
"success": true,
"message": "Product retrieved successfully",
"data": {
"id": "4b4663fb-a819-413e-9d15-bd0b577138a1",
"name": "Product 1",
"description": "Description 1",
"price": 100
}
}
Get products descending by price
GET /api/product/price/descending
Response body:
{
"success": true,
"message": "Products retrieved successfully",
"data": [
{
"id": "ef481be9-7363-4420-b62a-546d2a93420b",
"name": "Product 2",
"description": "Description 2",
"price": 110
}
{
"id": "4b4663fb-a819-413e-9d15-bd0b577138a1",
"name": "Product 1",
"description": "Description 1",
"price": 100
}
]
}
Get products ascending by price
GET /api/product/price/ascending
Response body:
{
"success": true,
"message": "Products retrieved successfully",
"data": [
{
"id": "4b4663fb-a819-413e-9d15-bd0b577138a1",
"name": "Product 1",
"description": "Description 1",
"price": 100
},
{
"id": "ef481be9-7363-4420-b62a-546d2a93420b",
"name": "Product 2",
"description": "Description 2",
"price": 110
}
]
}
Create product
POST /api/product
Request body:
{
"name": "Product 1",
"description": "Description 1",
"price": 100
}
Response body:
{
"success": true,
"message": "Product created successfully"
}
Update product
PUT /api/product/{id}
Request body:
{
"name": "Product 1",
"description": "Description 1",
"price": 110
}
Response body:
{
"success": true,
"message": "Product updated successfully"
}
Delete product
DELETE /api/product/{id}
Response body:
{
"success": true,
"message": "Product deleted successfully"
}