Create asp.net core web api from scratch


In this video and in our next few videos in this series, we will discuss creating a RESTful API from scratch using ASP.NET Core MVC. If you already know, how to create RESTful services using ASP.NET Core MVC, you may skip these videos.

Create ASP.NET Core REST API Project

Use the API project template to create a REST API Project. In our case we want to add the REST API project to the BlazorTutorial solution. Here are the steps.

  1. Right click on the solution in the Solution Explorer and select Add - New Project.
  2. In the Add a new project window, select ASP.NET Core Web Application and click Next
  3. Name the project EmployeeManagement.Api and then click Create

create asp.net core web api from scratch

4. On the next screen, select API project template and click Create

EmployeeManagement.Models.Employee class changes

In the Employees database table, we will be storing DepartmentId. So to keep the Employee model class simple, remove Department property and include DepartmentId property. The Employee class must be as shown now.

public class Employee
{
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public DateTime DateOfBrith { get; set; }
    public Gender Gender { get; set; }
    public int DepartmentId { get; set; }
    public string PhotoPath { get; set; }
}

Add reference to EmployeeManagement.Models project

We need the model classes (i.e Employee and Department) defined in EmployeeManagement.Models project in EmployeeManagement.Api project . So add a project reference.

add reference to EmployeeManagement.Models project





© 2020 Pragimtech. All Rights Reserved.