In the previous tutorial, we created the initial structure of the Employee Tracker Web API application. In this tutorial, we will build the Web API services in Visual Studio 2013.
Since we’re not building a client in this tutorial, we’ll use Postman to test the API.
In Solution Explorer, right-click the EmployeeTracker.Services project, and select Add and then New Folder. Name the folder Charts.
The ChartData class represents a data point on a chart.
In Solution Explorer, right-click the EmployeeTrackerRS Solution, and select Rebuild Solution to rebuild the solution.
The Employee data model (class and interface) contains information of an employee.
In Solution Explorer, right-click the EmployeeTracker.Services project, and select Add and then New Folder. Name the folder Employees.
Next, we will create two data services, i.e. DashboardService and EmployeeService. Both services contain logic to map the returned result from database to their respective data model. We also inject the IRespository interface into the data services.
In order to inject the DashboardService and EmployeeService into the controllers, we need to register it with the Autofac IoC container.
GET /api/dashboards: Retrieves the data for Dashboard.
In Solution Explorer, right-click the Controllers folder of the EmployeeTracker.Api project, and select Add and then New Folder. Name the folder Dashboards.
Right-click the newly created Dashboards folder, select Add and then Controller….
In the Add Scaffold dialog box, select the Web API 2 Controller – Empty and then Add.
In the Add Controller dialog box, type DashboardsController in the Controller name text box and click Add.
GET /api/employees: Retrieves all employees information.
In Solution Explorer, right-click the Controllers folder of the EmployeeTracker.Api project, and select Add and then New Folder. Name the folder Employees.
Right-click the newly created Employees folder, select Add and then Controller….
In the Add Controller dialog box, type EmployeesController in the Controller name text box and click Add.
The connection string is for a SQL Server database using SQL Server security. Replace the User ID and Password in DBConnection with the user credential to log on to your SQL server.
Let’s fire up Postman to test our Web APIs.
In the next tutorial, we will create the Single-Page Application (SPA) interface using AngularJS.
Thanks so much for posting this tutorial.
Ran into 1 Issue with my project & dapper not registering.
Quickly fixed by adding Dapper to the API. Resolved my issue.
Thank you for your feedback. I am glad that you solved the issue.
This is a great tutorial and one that I have been looking for for a very long time. However, I have one small problem. When I select the local IIS, I get a SQL exception. but when I use IIS Express, I am able to see the objects in Postman. The error I received: “Login failed for user ‘my user’. Do I need to change something in my IIS.
Than you for your comments. I am guessing your IIS issue could be the Application Pool setting of the employee-tracker-apis application.
1) The Application Pool of the employee-tracker-apis application should set to DefaultAppPool by Visual Studio 2013.
Thanks for the response. The issue I was having was due to database permission. Once i fixed the db permission issue in SQL server, I was able to connect.
I can’t wait to see what you have next tutorials you have for us.
Polo, I am glad that you solved the issue. Please stay tuned for the next tutorials.
Very good work Cathy. Well explained and planned out.
I am go through the tutorials. If you could also do something with grids in angularjs with webapi that would be great.
Hi Polo, i am facing the same issue could you please let me know the changes you made. URGENT !!