Asp.netCore

Asp.net core Perfect learning tutorial [Sampurna] #2

Hey guys in this tutorial we are going to create a simple asp.net core web api migrating to data base. and making some crud operation.

Create a new project > Asp.netcorewebApp>WebApplication4(Anyname) >SelectApi>

At first check your project is running or not.

Create a new Folder Naming it as Models>create a class(TicketClass)

tep2:

Create a TicketContextClass inside model Folder Name it as TicketContext.cs

//here DbContext inherits from using Microsoft.EntityFrameworkCore;

//This TicketItems will take all the contents from the database so of course we need to tell data base to get connection :
so lets go to Startup.cs

If you don’t know how to access the GetConnectionString then you can store it on in memory database see this

fakingwithdb

Now we are all ready to store it on db.If using in memory db you don’t need to perform this steps:

Inside PackagemanagerConsole:
Add-Migration Initial
Update-Database
That’s all
Now it’s time to Create a TicketController.cs inside TicketController Folder.
Insert This code to create read update and delete.

now it’s time to use postman before that you have to disable ssl certificate option inside your project properties.

Hit this url for
GET .
http://localhost:50409/api/ticket

POST:http://localhost:50409/api/Ticket
select post>body>raw>select JSON/(application/json)
send this:

{
"concert": "Xamarin",
"artist": null,
"available": true
}

PUT:
http://localhost:50409/api/Ticket
selectput>body>raw>select Json(application/json)
{
“id”:2,
“concert”: “Xamarin”,
“artist”: null,
“available”: true
}

165 total views, 2 views today

Leave a Reply