using System.Diagnostics;
using crudapp.Migrations;
using crudapp.Models;
using Microsoft.AspNetCore.Mvc;
using Students = crudapp.Models.Students;
namespace crudapp.Controllers
{
public class HomeController : Controller
{
private readonly StudentDbContext studentDb;
public HomeController(StudentDbContext studentDbContext)
{
this.studentDb = studentDbContext;
}
public IActionResult Index()
{
return View();
}
[Route("/AddStudent")]
[HttpGet]
public IActionResult AddStudent()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> AddStudent([Bind("Id,Name,Email,Phone,Age")] Students Student)
{
if (ModelState.IsValid)
{
studentDb.Students.Add(Student);
studentDb.SaveChanges();
return RedirectToAction("Read");
}
return View(Student);
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}