This project is a sample ASP.NET Core Web API application demonstrating user authentication, role management, and CRUD operations on different entities such as Projects, Resumes, and Specialities. The application also supports file uploads and downloads, providing a comprehensive example of how to structure a multi-layered .NET web application.
OPort is an ASP.NET Core Web API designed to showcase how to build a modular back-end system using:
- EF Core with Microsoft SQL Server for data persistence.
- ASP.NET Core Identity for user and role management.
- AutoMapper for model-to-DTO mapping.
- Swagger for API documentation and testing.
The system uses ASP.NET Core Identity to manage users and roles:
- SignUp: Create a new user with a specified password.
- SignIn: Authenticate a user with username/password.
- SignOut: Log out a user.
- UpdateUserRole: Assign a role to a specified user.
- AddRole: Create a new role in the database.
- FetchRoles: Retrieve existing roles.
- GetUserInfo: Fetch user information by user ID.
Controller:
AuthController
CRUD operations on projects, including uploading a project cover file.
Endpoints:
- CreateProject (
POST /api/Projects/create): Create a new project record with an optional cover file. - GetAsync (
GET /api/Projects/{id}): Get a project by its GUID. - FetchByResumeIdAsync (
GET /api/Projects/fetch-by-resume/{resumeId}): Fetch all projects related to a specific resume. - UpdateAsync (
PUT /api/Projects/{id}): Update a project’s details. - DeleteAsync (
DELETE /api/Projects/{id}): Delete a project by its GUID.
Controller:
ProjectsController
CRUD operations for resumes, including the ability to fetch resumes by user ID.
Endpoints:
- Add (
POST /api/Resumes/add): Create a new resume. - Delete (
DELETE /api/Resumes/{id}): Delete a resume by its GUID. - Update (
PUT /api/Resumes/update): Update a resume’s details. - FetchByUserId (
GET /api/Resumes/fetch-by-user/{id}): Fetch resumes belonging to a specific user. - Fetch (
GET /api/Resumes/fetch): Fetch resumes filtered by criteria. - Get (
GET /api/Resumes/{id}): Fetch a single resume by its GUID.
Controller:
ResumesController
CRUD operations for managing user or resume specialities.
Endpoints:
- AddAsync (
POST /api/Specialities/add): Create a new speciality. - Delete (
DELETE /api/Specialities/{id}): Delete a speciality by its integer ID. - Get (
GET /api/Specialities/{id}): Get a speciality by its ID. - Fetch (
GET /api/Specialities/fetch): Fetch a list of all specialities.
Controller:
SpecialitiesController
The system supports file uploads related to projects. The uploaded files are stored on the server’s file system, and the relevant file metadata (path, name, etc.) is saved in the database.
- UploadFile (
POST /api/Files/upload/{projectId}): Upload a file and associate it with a specific project. - GetFile (
GET /api/Files/{fileId}): Download a file by its GUID.
Controller:
FilesController
Ensure you have met the following requirements:
- .NET 6.0 SDK or later
- SQL Server instance (local or remote)
- An IDE or editor like Visual Studio or Visual Studio Code
-
Clone the Repository
git clone https://github.com/your-repo/OPort.git cd OPort -
Configure the Connection String
-
Open the
appsettings.jsonorappsettings.Development.jsonfile. -
Locate the
"ConnectionStrings"section. -
Update the
"default"connection string to match your SQL Server setup:Example:
"ConnectionStrings": { "default": "Server=YOUR_SERVER;Database=YOUR_DATABASE;Trusted_Connection=True;MultipleActiveResultSets=true" }
Replace
YOUR_SERVERandYOUR_DATABASEwith your server and database names.
-
-
Restore & Build the Project
Run the following commands to restore dependencies and build the project:
dotnet restore dotnet build
-
Apply EF Core Migrations
- Apply the migrations using:
dotnet ef database update
- Apply the migrations using:
-
Run the Application
- Start the application with:
dotnet run
- The application will start on the configured port (typically
https://localhost:5001orhttp://localhost:5000for development).
- Start the application with:
-
Open Swagger UI
- Navigate to
https://localhost:5001/swagger(or the corresponding port).
- Navigate to
- SignUp: Use the
POST /api/Auth/signupendpoint to create a user, providingfirstName,lastName,password, andemail. - SignIn: Use the
POST /api/Auth/signinendpoint to log in with the created user credentials.
- AddRole: Use
POST /api/Auth/add-roleto create a new role. - UpdateUserRole: Use
PUT /api/Auth/update-roleto assign a role to a user.
- FilesController: Use
POST /api/Files/upload/{projectId}to upload a file for a given project ID. Include a form-data request with the keyfilepointing to the file to be uploaded.
- Projects: CRUD operations at
/api/Projects. - Resumes: CRUD operations at
/api/Resumes. - Specialities: CRUD operations at
/api/Specialities.