ASP.NET Core 3 Web API to manage clients and legal cases
- Description
- Technologies used
- Live Site
- Set up
- Configuration: Azure web app and Azure Active Directory
- Configuration: Authentication / Authorization
- Configuration: Database
- Run Application
- Endpoints
- Related Repos
ClientsManager is an ASP.NET Core 3.1 Web API.
Using ClientsManager you can manage your clients, legal cases, and billable activities.
ASP.NET Core 3.1, C#, AutoMapper, Swagger, Serilog, Entity Framework Core, SQL Server
Complete the following steps to start a new project (NEW-PROJECT-NAME):
- Clone this repository to your local machine
git clone https://github.com/rodrigohervas/ClientManagerAPI.git NEW-PROJECT-NAME
cd
into the cloned repository- Make a fresh start of the git history for this project with
rm -r -Force .git
, amd thengit init
- Make sure that the .gitignore file is encoded as 'UTF-8'
Note. This server can be used with the following client repo: xxxx
Before using the API there are several steps to follow in order to create the API in Azure App Services and register it in Azure Active Directory:
- Register the API in Azure Active Directory (you'll need to have an Azure Active Directory tenant configured)
Recommended Read: Protected Web API app registration
-
Configure the API registration in Azure Active Directory (the registration must expose at least one scope/role in the Expose an API section)
-
In appsettings.json / secrets.json, add the following configuration (get your config data from the Azure AD API registration):
{
"AzureAd": {
"ClientId": "your-API-Azure-client-Id",
"Instance": "https://login.microsoftonline.com/",
"TenantId": "your-azure-AD-tenant-Id",
"APIApplicationIdUri": "api://your-API-Azure-client-Id",
"ClientAudience": "your-client-Azure-AD-Id", //This is the intended recipient(s) for this token (the calling client Id in Azure AD).
"APIAudience": "your-API-Azure-client-Id" //This claim identifies the audience for this token (your API Azure AD Client Id)
}
}
- Create a web app in Azure App Services for your API
Recommended read: Publish web app to Azure
-
Publish the API to Azure
-
Configure the web app created in Azure App Services, specially the appsettings in Azure (or a Key Vault if preferred).
All API requests must be made using an access_token. The access_token is a JWT Bearer Token, issued by Azure Active Directory.
After the API configuration in Azure Web Services and Azure Active Directory the app is ready to authenticate JWT Tokens.
Regarding Token validation, check ClientsManager.WebAPI.Authentication.AddAuthenticationExtensions.cs, called from the Startup.ConfigureServices method.
Authorization is configured at the controller level using the [Authorize] attribute.
During the API Publish process you can create the Database in Azure. If you want to run the scripts, you can find them in ClientsManager.SQLscripts:
-
Run Create_ClientsManager_DB_Script.sql to create the ClientManagers database
-
Run Create_EmployeeTypes_Table_Script.sql to create the EmployeeTypes table
-
Run Create_Employees_Table_Script.sql to create the Employees table
-
Run Create_Clients_Table_Script.sql to create the Clients table
-
Run Create_Addresses_Table_Script.sql to create the Addresses table
-
Run Create_Contacts_Table_Script.sql to create the Contacts table
-
Run Create_Logs_Table_Script.sql to create the EventLogging.Logs table
Build the solution
Run the application
The API has the following endpoints:
-
Clients: CRUD Clients
-
LegalCases: CRUD LegalCases for a Client
-
BillableActivities: CRUD BillableActivities for a LegalCase
-
Addresses: CRUD Adresses for a Client
-
Contacts: CRUD Contacts for a Client
-
Employees: CRUD Employees for a LegalCase
-
EmployeeTypes: CRUD EmployeeTypes for an Employee
-
Description: returns an array of Client objects, paged by the provided pageNumber and pageSize
-
Request params:
param name | type | param type |
---|---|---|
pageNumber | String | querystring |
pageSize | String | querystring |
- Response:
A collection of Client objects:
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
-
Description: returns a Client object for the provided client id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | route |
- Response:
A Client object:
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
-
Description: returns an array of Client objects, with its related LegalCases
-
Request params:
param name | type | param type |
---|---|---|
id | Number | route |
- Response:
An array of Client objects, with its LegalCase objects:
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
legalcases | Array |
-
Description: returns a Client object for the provided client id, including its related Address objects
-
Request params:
param name | type | param type |
---|---|---|
id | Number | route |
- Response:
A Client object:
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
addresses | Array |
-
Description: returns a Client object for the provided id, including its related Contact objects
-
Request params:
param name | type | param type |
---|---|---|
id | Number | route |
- Response:
A Client object with its related Contact objects:
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
contacts | Array |
-
Description: creates a Client object
-
Request params:
param name | type | param type |
---|---|---|
name | String | Body |
description | String | Body |
website | String | Body |
- Response:
The Client object created.
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
-
Description: updates an existing Client object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
name | String | Body |
description | String | Body |
website | String | Body |
- Response:
The Client object updated
param name | type |
---|---|
id | Number |
name | String |
description | String |
website | String |
-
Description: deletes an existing Client object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
The number of Client objects deleted
param name | type |
---|---|
number | Number |
-
Description: returns an array of LegalCase objects, paged by the provided pageNumber and pageSize
-
Request params:
param name | type | param type |
---|---|---|
pageNumber | String | querystring |
pageSize | String | querystring |
- Response:
An array of LegalCase of objects.
param name | type |
---|---|
id | Number |
client_id | Number |
title | String |
description | String |
trustfund | Number |
-
Description: returns all LegalCases for a provided Client id
-
Request params:
param name | type | param type |
---|---|---|
client_id | Number | Route |
- Response:
An array of LegalCase objects.
param name | type |
---|---|
id | Number |
client_id | Number |
title | String |
description | String |
trustfund | Number |
-
Description: returns a LegalCase object for a provided id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
A LegalCase object.
param name | type |
---|---|
id | Number |
client_id | Number |
title | String |
description | String |
trustfund | Number |
-
Description: returns a LegalCase object for a provided id, with all its related BillableActivity objects
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
A LegalCase object
param name | type |
---|---|
id | Number |
client_id | Number |
title | String |
description | String |
trustfund | Number |
BillableActivities | Array |
-
Description: creates a LegalCase object
-
Request params:
param name | type | param type |
---|---|---|
client_id | Number | Body |
title | String | Body |
description | String | Body |
trustfund | Number | Body |
- Response:
The created LegalCase object
param name | type |
---|---|
id | Number |
client_id | Number |
title | String |
description | String |
trustfund | Number |
-
Description: updates an existing LegalCase object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
client_id | Number | Body |
title | String | Body |
description | String | Body |
trustfund | Number | Body |
- Response:
The updated LegalCase object
param name | type |
---|---|
id | Number |
client_id | Number |
title | String |
description | String |
trustfund | Number |
-
Description: deletes an existing LegalCase object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
The number of deleted LegalCase objects
param name | type |
---|---|
number | Number |
-
Description: returns an array of BillableActivity objects, paged by the provided pageNumber and pageSize
-
Request params:
param name | type | param type |
---|---|---|
pageNumber | String | querystring |
pageSize | String | querystring |
- Response:
An array of BillableActivity objects.
param name | type |
---|---|
id | Number |
legalcase_id | Number |
employee_id | Number |
title | String |
description | String |
price | Number |
start_datetime | String |
finish_datetime | String |
-
Description: returns the an array of BillableActivity objects, for a provided Employee id
-
Request params:
param name | type | param type |
---|---|---|
employee_id | Number | Route |
- Response:
An array of BillableActivity objects
param name | type |
---|---|
id | Number |
legalcase_id | Number |
employee_id | Number |
title | String |
description | String |
price | Number |
start_datetime | String |
finish_datetime | String |
-
Description: returns an array of BillableActivity objects, for a provided LegalCase id
-
Request params:
param name | type | param type |
---|---|---|
legalcase_id | Number | Route |
- Response:
A LegalCase object.
An array of BillableActivity objects
param name | type |
---|---|
id | Number |
legalcase_id | Number |
employee_id | Number |
title | String |
description | String |
price | Number |
start_datetime | String |
finish_datetime | String |
-
Description: returns a BillableActivity object, for a provided id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
A BillableActivity object.
param name | type |
---|---|
id | Number |
legalcase_id | Number |
employee_id | Number |
title | String |
description | String |
price | Number |
start_datetime | String |
finish_datetime | String |
-
Description: creates a BillableActivity object
-
Request params:
param name | type | param type |
---|---|---|
legalcase_id | Number | Body |
employee_id | Number | Body |
title | String | Body |
description | String | Body |
price | Number | Body |
start_datetime | String | Body |
finish_datetime | String | Body |
- Response:
The created BillableActivity object.
param name | type |
---|---|
id | Number |
legalcase_id | Number |
employee_id | Number |
title | String |
description | String |
price | Number |
start_datetime | String |
finish_datetime | String |
-
Description: updates an existing BillableActivity object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
legalcase_id | Number | Body |
employee_id | Number | Body |
title | String | Body |
description | String | Body |
price | Number | Body |
start_datetime | String | Body |
finish_datetime | String | Body |
- Response:
The updated BillableActivity object.
param name | type |
---|---|
id | Number |
legalcase_id | Number |
employee_id | Number |
title | String |
description | String |
price | Number |
start_datetime | String |
finish_datetime | String |
-
Description: deletes an existing BillableActivity object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
The number of deleted BillableActivity objects
param name | type |
---|---|
number | Number |
-
Description: returns an array of Address objects, paged by the provided pageNumber and pageSize
-
Request params:
param name | type | param type |
---|---|---|
pageNumber | String | querystring |
pageSize | String | querystring |
- Response:
An array of Address objects.
param name | type |
---|---|
id | Number |
client_id | Number |
streetnumber | String |
city | String |
stateprovince | String |
zipcode | String |
country | String |
-
Description: returns an array of Address objects, for a provided Client id
-
Request params:
param name | type | param type |
---|---|---|
client_id | Number | Route |
- Response:
An array of Address objects
param name | type |
---|---|
id | Number |
client_id | Number |
streetnumber | String |
city | String |
stateprovince | String |
zipcode | String |
country | String |
-
Description: returns an Address object, for a provided id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
An Address object
param name | type |
---|---|
id | Number |
client_id | Number |
streetnumber | String |
city | String |
stateprovince | String |
zipcode | String |
country | String |
-
Description: returns an Address object, for a provided id, with its related Contact objects
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
An Address object
param name | type |
---|---|
id | Number |
client_id | Number |
streetnumber | String |
city | String |
stateprovince | String |
zipcode | String |
country | String |
contacts | Array |
-
Description: creates an Address object
-
Request params:
param name | type | param type |
---|---|---|
client_id | Number | Body |
streetnumber | String | Body |
city | String | Body |
stateprovince | String | Body |
zipcode | String | Body |
country | String | Body |
- Response:
The created Address object.
param name | type |
---|---|
id | Number |
client_id | Number |
streetnumber | String |
city | String |
stateprovince | String |
zipcode | String |
country | String |
-
Description: updates an existing Address object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
client_id | Number | Body |
streetnumber | String | Body |
city | String | Body |
stateprovince | String | Body |
zipcode | String | Body |
country | String | Body |
- Response:
The updated Address object.
param name | type |
---|---|
id | Number |
client_id | Number |
streetnumber | String |
city | String |
stateprovince | String |
zipcode | String |
country | String |
-
Description: deletes an existing Address object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
The number of deleted Address objects
param name | type |
---|---|
number | Number |
-
Description: returns an array of Contact objects, paged by the provided pageNumber and pageSize
-
Request params:
param name | type | param type |
---|---|---|
pageNumber | String | querystring |
pageSize | String | querystring |
- Response:
An array of Contact objects
param name | type |
---|---|
id | Number |
client_id | Number |
address_id | Number |
name | String |
position | String |
telephone | String |
cellphone | String |
String |
-
Description: returns an array of Contact objects, for a provided Client id
-
Request params:
param name | type | param type |
---|---|---|
client_id | Number | Route |
- Response:
An array of Contact objects
param name | type |
---|---|
id | Number |
client_id | Number |
address_id | Number |
name | String |
position | String |
telephone | String |
cellphone | String |
String |
-
Description: returns a Contact object, for a provided id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
A Contact object
param name | type |
---|---|
id | Number |
client_id | Number |
address_id | Number |
name | String |
position | String |
telephone | String |
cellphone | String |
String |
-
Description: returns a Contact object, for a provided id, with its related Address objects
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
A Contact object
param name | type |
---|---|
id | Number |
client_id | Number |
address_id | Number |
name | String |
position | String |
telephone | String |
cellphone | String |
String | |
addresses | Array |
-
Description: creates a Contact object
-
Request params:
param name | type | param type |
---|---|---|
client_id | Number | Body |
address_id | Number | Body |
name | String | Body |
position | String | Body |
telephone | String | Body |
cellphone | String | Body |
String | Body |
- Response:
The created Contact object.
param name | type |
---|---|
client_id | Number |
address_id | Number |
name | String |
position | String |
telephone | String |
cellphone | String |
String |
-
Description: updates an existing Contact object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
client_id | Number | Body |
address_id | Number | Body |
name | String | Body |
position | String | Body |
telephone | String | Body |
cellphone | String | Body |
String | Body |
- Response:
The updated Contact object.
param name | type |
---|---|
id | Number |
client_id | Number |
address_id | Number |
name | String |
position | String |
telephone | String |
cellphone | String |
String |
-
Description: deletes an existing Contact object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
The number of deleted Contact objects
param name | type |
---|---|
number | Number |
-
Description: returns an array of Employee objects, paged by the provided pageNumber and pageSize
-
Request params:
param name | type | param type |
---|---|---|
pageNumber | String | querystring |
pageSize | String | querystring |
- Response:
An array of Employee objects
param name | type |
---|---|
id | Number |
name | String |
employeetype_id | String |
position | String |
-
Description: returns an array of Employee objects, for a provided id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
An array of Employee objects
param name | type |
---|---|
id | Number |
name | String |
employeetype_id | String |
position | String |
-
Description: returns an array of Employee objects, for a provided EmployeeType id
-
Request params:
param name | type | param type |
---|---|---|
employeetype_id | Number | Route |
- Response:
An array of Employee objects
param name | type |
---|---|
id | Number |
name | String |
employeetype_id | String |
position | String |
-
Description: creates an Employee object
-
Request params:
param name | type | param type |
---|---|---|
name | Number | Body |
employeetype_id | String | Body |
position | String | Body |
- Response:
The created Employee object
param name | type |
---|---|
id | Number |
name | String |
employeetype_id | String |
position | String |
-
Description: updates an existing Employee object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
name | String | Body |
employeetype_id | String | Body |
position | String | Body |
- Response:
The updated Employee object
param name | type |
---|---|
id | Number |
name | String |
employeetype_id | String |
position | String |
-
Description: deletes an existing Employee object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
The number of deleted Employee objects
param name | type |
---|---|
number | Number |
-
Description: returns an array of EmployeeType objects
-
Request params:
None
- Response:
An array of EmployeeType objects
param name | type |
---|---|
id | Number |
description | String |
-
Description: returns an EmployeeType object, for a provided id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
- Response:
An array of Employee objects
param name | type |
---|---|
id | Number |
description | String |
-
Description: creates an EmployeeType object
-
Request params:
param name | type | param type |
---|---|---|
description | String | Body |
- Response:
The created EmployeeType object
param name | type |
---|---|
id | Number |
description | String |
-
Description: updates an existing EmployeeType object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
description | String | Body |
- Response:
The updated EmployeeType object
param name | type |
---|---|
id | Number |
description | String |
-
Description: deletes an existing EmployeeType object
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Route |
id | Number | Body |
description | String | Body |
- Response:
The number of deleted EmployeeType objects
param name | type |
---|---|
number | Number |