Lab3.3 Database First Approach-First Starting Web MVC
Lab3.3 Database First Approach-First Starting Web MVC
v=zvMOHUNwO0o
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using WebApplication2;
namespace WebApplication2.Controllers
{
public class StudentDetailsController : Controller
{
private ScholEntities db = new ScholEntities();
// GET: StudentDetails
public ActionResult Index()
{
return View(db.StudentDetails.ToList());
}
// GET: StudentDetails/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StudentDetail studentDetail = db.StudentDetails.Find(id);
if (studentDetail == null)
{
return HttpNotFound();
}
return View(studentDetail);
}
// GET: StudentDetails/Create
public ActionResult Create()
{
return View();
}
// POST: StudentDetails/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include =
"Id,Name,ParentsName,MobileNumber,Status,Remarks")] StudentDetail studentDetail)
{
if (ModelState.IsValid)
{
db.StudentDetails.Add(studentDetail);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(studentDetail);
}
// GET: StudentDetails/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StudentDetail studentDetail = db.StudentDetails.Find(id);
if (studentDetail == null)
{
return HttpNotFound();
}
return View(studentDetail);
}
// POST: StudentDetails/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include =
"Id,Name,ParentsName,MobileNumber,Status,Remarks")] StudentDetail studentDetail)
{
if (ModelState.IsValid)
{
db.Entry(studentDetail).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(studentDetail);
}
// GET: StudentDetails/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StudentDetail studentDetail = db.StudentDetails.Find(id);
if (studentDetail == null)
{
return HttpNotFound();
}
return View(studentDetail);
}
// POST: StudentDetails/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
StudentDetail studentDetail = db.StudentDetails.Find(id);
db.StudentDetails.Remove(studentDetail);
db.SaveChanges();
return RedirectToAction("Index");
}
USE [Schol]
GO
SET QUOTED_IDENTIFIER ON
GO