A RESTful API for managing blog posts built with ASP.NET Core, ADO.NET, and SQL Server.
- CRUD Operations: Create, read, update, and delete blog posts
- Soft Delete: Posts are marked as deleted instead of being physically removed
- Partial Updates: Support for PATCH requests to update specific fields
- SQL Server Integration: Uses ADO.NET for database operations
- RESTful Design: Follows REST conventions with proper HTTP verbs
Retrieve all active blog posts (excluding deleted ones).
Response:
json
[
{
"id": 1,
"title": "Sample Blog",
"author": "John Doe",
"content": "Blog content here..."
}
]
Create a new blog post.
Request Body:
json
{
"title": "New Blog",
"author": "Jane Smith",
"content": "Blog content..."
}
Response:
text
"Insertion Successful." or "Insertion Failed."
Update an entire blog post by ID.
Request Body:
json
{
"title": "Updated Blog",
"author": "Updated Author",
"content": "Updated content..."
}
Response:
text
"Updation Successful." or "Updation Failed."
Partially update a blog post by ID.
Request Body:
json
{
"title": "Only update title"
}
Response:
text
"Updating Successful." or "Updating Failed."
Soft delete a blog post by ID (sets DeleteFlag to 1).
Response:
text
"Deletion Successful." or "Deletion Failed."
text
Rest_API_ADO_NET/
├── Controllers/
│ └── BlogsController.cs # Main API controller
├── Models/
│ └── BlogDataModel.cs # Database model
├── ViewModels/
│ └── BlogViewModel.cs # API request/response model
└── Program.cs # Application entry point
- BlogId - Primary key
- BlogTitle - Blog post title
- BlogAuthor - Author name
- BlogContent - Blog content
- DeleteFlag - Soft delete indicator (0 = active, 1 = deleted)
- Id - Blog identifier
- Title - Blog title (nullable)
- Author - Author name (nullable)
- Content - Blog content (nullable)
The application expects a SQL Server database with the following table:
sql
CREATE TABLE Tbl_Blog (
BlogId INT IDENTITY(1,1) PRIMARY KEY,
BlogTitle NVARCHAR(255) NOT NULL,
BlogAuthor NVARCHAR(100) NOT NULL,
BlogContent NVARCHAR(MAX) NOT NULL,
DeleteFlag BIT NOT NULL DEFAULT 0
);
Update the connection string in BlogsController.cs:
csharp
private readonly string _connectionString = "Server=.;Database=TrainingBatch5;User Id=sa;Password=your_password;TrustServerCertificate=True;";
- .NET 6.0 or later
- SQL Server
- ASP.NET Core runtime
-
Clone the repository:
bash git clone https://github.com/thetnaing-dh/RestAPI_ASP.NET_ADO.NET_SQL_CRUD cd Rest_API_ADO_NET
-
Update the database connection string in BlogsController.cs
-
Run the application:
bash dotnet run
The API returns appropriate HTTP status codes:
- 200 OK - Successful operation
- 400 Bad Request - Invalid input (e.g., no fields to update in PATCH)
- 404 Not Found - Blog post not found
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is for educational purposes.