This is the Web Service (Server) portion of our Internship project. Built with .NET WebApi SDK and Entity Framework.
- Technologies Used
- Required Dependencies
- Installation
- Before You Run
- Development
- Connect other devices to this server
- Features
- Suggested VS Code Extensions
- Contributors
.NET 8.0.403 SDKEntity Framework CoreMicrosoft SQL Server 2022 - Express editionMicrosoft SQL Server Management Studio - SSMS
Make sure to have these installed before proceeding with the project setup.
Note: If you encounter any issues installing the .NET runtime, consider installing it through Visual Studio. Details are provided below.
Follow these steps to download Visual Studio 2022 and dotnet runtime.
-
Download Visual Studio 2022:
- Visit the official Visual Studio 2022 download page.
- Choose the
Communityedition (free) or the version that suits your needs. - Click
Downloadand follow the installation prompts.
-
Launch the Visual Studio Installer:
- After downloading the installer, open it to start setting up Visual Studio.
- You'll be prompted to select workloads to install.
-
Select the .NET Workloads and start the installation:
- In the
Workloadstab, find the section labeledASP.NET and web development. - Check the box for
ASP.NET and web developmentto install all necessary tools. - Click
Installto download and install the selected features.
- In the
-
Verify .NET Runtime:
-
After the installation, you can verify the installed
.NET runtimeby opening a terminal and typing the following command:dotnet --version
-
It should return the version of the
.NET SDKinstalled by Visual Studio.
-
Follow these steps to set up and run the application locally.
-
Clone the repository:
git clone https://github.com/YGOhappy123/NHT_Marine_BE.git
-
Navigate to the project directory:
cd NHT_Marine_BE -
Install dependencies:
dotnet restore
Before running the project, make sure to set up the database and environment variables:
-
Create a
appsettings.Development.jsonfile:In the root directory of your project (at the same level as
Program.cs), create aappsettings.Development.jsonfile. -
Populate the environment variables:
Copy the structure from
appsettings.Example.jsonfile intoappsettings.Development.jsonand replace the placeholder values with your actual configuration.Notes:
-
You must replace
<your_server_name>with the actual value of your local Microsoft SQL Server instance. -
Ensure that
NHT_Marine(the database name) is correct, as the application uses migrations that depend on this database.
-
-
For collaborators:
If you are a collaborator on this project, please contact the project owner to obtain the values for the environment variables.
-
Apply the migrations to create the necessary database tables. Use the following command in the terminal:
dotnet ef database update
This command will apply the existing migrations to the specified database, ensuring that the required tables are created.
Note: If you encounter any errors like
dotnet-ef: command not found, install thedotnet-eftool globally on your machine using the following command an retry:dotnet tool install --global dotnet-ef --version 8.0.10
-
Verify the created database:
If you don't see a database name
NHT_Marinein your SQL Server Management Studio after refreshing, try disconnecting and reconnecting your SQL Server.
To start the development server, use:
dotnet watch runThis will start the Dotnet development server
You can access the app by visiting http://localhost:5000/api/v1 in your browser.
You can also replace localhost with your device's IPv4 Address, which can be found by entering the following command in the terminal and look for Wireless LAN adapter Wi-Fi > IPv4 Address:
ipconfigRequirement: All devices must be connected to the same network.
Follow these steps to ensure that your firewall allows incoming connections on port 5000.
- Open
Windows Defender Firewall. - Click on
Advanced settings. - Select
Inbound Rulesand thenNew Rule. - Choose
Port, clickNext. - Select
TCPand enter5000in the specific local ports box. - Allow the connection and complete the wizard.
Now you can access the app using other devices by visiting http://<IPv4 Adddess>:5000/api/v1
- RESTful API 🛠 Exposes endpoints following REST principles for ease of use and scalability.
- Database Integration 💾 Uses Microsoft SQL Server with Entity Framework Core for data persistence.
- Swagger Documentation 📜 Automatically generated API documentation with Swagger/OpenAPI.
- Authentication and Authorization 🔑 Secure your API with JWT-based authentication.
- Cross-Platform 🌐 Runs on any operating system that supports .NET Core.
- Migrations 🔄 Easily handle database schema changes using Entity Framework Core migrations.
| Extension | Publisher | Required? | Supported features |
|---|---|---|---|
| C# Dev Kit | Microsoft | Yes | Install necessary tools for developing C# and .NET app |
| .NET Extension Pack | Microsoft | Yes | Install necessary tools for developing C# and .NET app |
| CSharpier - Code formatter | csharpier | Yes | Code formatting |
| NuGet Gallery | pcislo | Yes | Streamlining the process of managing NuGet packages |
| IntelliCode for C# Dev Kit | Microsoft | No | AI-assisted development for C# Dev Kit |
| C# Extensions | JosKreativ | No | Add C# related stuffs to VS Code context menu |
| Code Spell Checker | Street Side Software | No | Spelling checker for source code |
| Multiple cursor case preserve | Cardinal90 | No | Preserves case when editing with multiple cursors |
Thanks to the following people for contributing to this project ✨:
|
YGOhappy123 |
DinhToanIT2003 |
Nguyen1609 |