WEB API Three-tier architecture.
Install :
1. Microsoft.EntityFrameworkCore(3.1.25)
2. Microsoft.EntityFrameworkCore.SqlServer(3.1.25)
3. Microsoft.EntityFrameworkCore.Tools(3.1.25)
To Scaffold one table
Scaffold-DbContext "Server=yourserver;Database=database;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir testDir -t table-name
Scaffold-DbContext "Data Source=DESKTOP-56FAU8K\SQLEXPRESS;Database=DBTest;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Repository/Models
DESKTOP-56FAU8K\SQLEXPRESS
using Data_Access_Layer.Repository.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Web_Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class PersonController : ControllerBase
{
private Business_Logic_Layer.PersonBLL _BLL;
public PersonController()
{
_BLL =new Business_Logic_Layer.PersonBLL();
}
[HttpGet]
[Route("getPersons")]
public List<Person> GetAllperson()
{
return _BLL.GetAllpersons();
}
[HttpGet]
[Route("getPersonById")]
public ActionResult<Person> GetPersonById(int id)
{
var Person = _BLL.GetPersonById(id);
if (Person == null)
{
return NotFound("Data not found");
}
return Ok(Person);
}
[Route("postPerson")]
[HttpPost]
public void postPerson([FromBody] Person p)
{
_BLL.PostPerson(p);
}
[Route("deletePerson")]
[HttpDelete]
public void deletePerson(int id)
{
_BLL.DeletePerson(id);
}
}
}
Get details by id
0 Comments