Devhq provide a lot of services

Make a StudentController.cs file and add this code
private readonly IStudent _studentService;
public StudentController(IStudent studentService)
{
_studentService = studentService;
}
C#This code give access to use all function inside the Istudent interface.
Now Lets Write Crud Operation code for Student
⭐Read Student (Get Student)
[HttpGet]
public async Task<ActionResult<List<Student>>> Get()
{
return await _studentService.GetStudents();
}
C#⭐Search Student (Get one Student )
[HttpGet("{id:length(24)}", Name = "GetStudent")]
public async Task<ActionResult<Student>> Get(string id)
{
var student = await _studentService.GetStudent(id);
if (student == null)
{
return NotFound();
}
return student;
}
C#⭐Add Student (Post Student)
[HttpPost]
public async Task<ActionResult<Student>> Create(Student student)
{
await _studentService.CreateStudent(student);
return CreatedAtRoute("GetStudent", new { id = student.Id.ToString() }, student);
}
C#⭐Update Student (Put Student)
[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Student studentIn)
{
var student = _studentService.GetStudent(id);
if (student == null)
{
return NotFound();
}
await _studentService.UpdateStudent(id, studentIn);
return NoContent();
}
C#⭐Delete Student (delete Student)
[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
var student = _studentService.GetStudent(id);
if (student == null)
{
return NotFound();
}
await _studentService.DeleteStudent(id);
return NoContent();
}
C#Full Code will look like this
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Univercity.Models;
using Univercity.Services.Interfaces;
namespace Univercity.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class StudentController : ControllerBase
{
private readonly IStudent _studentService;
public StudentController(IStudent studentService)
{
_studentService = studentService;
}
[HttpGet]
public async Task<ActionResult<List<Student>>> Get()
{
return await _studentService.GetStudents();
}
[HttpGet("{id:length(24)}", Name = "GetStudent")]
public async Task<ActionResult<Student>> Get(string id)
{
var student = await _studentService.GetStudent(id);
if (student == null)
{
return NotFound();
}
return student;
}
[HttpPost]
public async Task<ActionResult<Student>> Create(Student student)
{
await _studentService.CreateStudent(student);
return CreatedAtRoute("GetStudent", new { id = student.Id.ToString() }, student);
}
[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Student studentIn)
{
var student = _studentService.GetStudent(id);
if (student == null)
{
return NotFound();
}
await _studentService.UpdateStudent(id, studentIn);
return NoContent();
}
[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
var student = _studentService.GetStudent(id);
if (student == null)
{
return NotFound();
}
await _studentService.DeleteStudent(id);
return NoContent();
}
}
}
C#