This repository contains the source code for a C# inventory management system API. The API is built using ASP.NET Core and provides RESTful services for managing inventory data including products, categories, and suppliers.
- CRUD operations for product management.
- Category management to organize products.
- Supplier interaction to manage product suppliers.
- Detailed API documentation.
- ASP.NET Core 5
- Entity Framework Core
- MySQL
- .NET 5 SDK
- Visual Studio 2022
- MySQL Server
-
Clone the repository:
git clone https://github.com/andrenormlang/inventory-management-api-csharp.git git clone https://github.com/andrenormlang/inventory-management-api-csharp.git
-
Open the solution in Visual Studio 2022.
-
Restore the necessary packages. Visual Studio should prompt you to restore packages once the project is opened. Alternatively, you can restore packages by right-clicking on the solution in Solution Explorer and selecting Restore NuGet Packages.
-
Set up the database URL as an environment variable:
Windows: Open Command Prompt or PowerShell and run:
setx DATABASE_URL "server=localhost;port=3307;database=inventory_management;user=root;password=root"
macOS / Linux: Add the following to your .bashrc, .zshrc, or .bash_profile
export DATABASE_URL="server=localhost;port=3307;database=inventory_management;user=root;password=root"
- Update the database by opening the Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console) and running:
Update-Database
- 🪄Start the application by pressing F5 or clicking on the green Start button.
Once the application is running, you can access the API documentation by navigating to the following URL:
http://localhost:{port}/swagger
This will provide interactive API documentation where you can test out the endpoints directly.
To post multiple categories, products, or suppliers at once, you can use the bulk post endpoints.
-
Bulk Post Categories: Send a
POST
request to/api/categories/bulk
with a JSON array containing multiple categories.Example Request:
[ { "name": "Electronics" }, { "name": "Home Appliances" } ]
-
Bulk Post Suppliers: Send a
POST
request to/api/suppliers/bulk
with a JSON array of suppliers.Example Request:
[ { "name": "Best Supplier", "address": "1234 Market St", "phone": "555-555-5555" }, { "name": "Great Supplier", "address": "5678 Main St", "phone": "555-555-5556" } ]
-
Bulk Post Products: Send a
POST
request to/api/products/bulk
with a JSON array of products.Example Request:
[ { "name": "Laptop", "price": 999.99, "quantity": 10, "categoryId": 1, "supplierId": 2 }, { "name": "Smartphone", "price": 699.99, "quantity": 15, "categoryId": 1, "supplierId": 1 } ]
You should avoid storing sensitive information, such as database credentials, directly in the appsettings.json
. Instead, store these values as environment variables.
DATABASE_URL="server=localhost;port=3307;database=inventory_management;user=root;password=root"
In the appsettings.json
or appsettings.Development.json
, you can reference it like so:
{
"ConnectionStrings": {
"DefaultConnection": "${DATABASE_URL}"
}
}