using System.Data;
using System.Linq;
using System.Web.Mvc;
namespace MvcAppDemo.Controllers
{
public class HomeController : Controller
{
private EmployeeDBContext db = new EmployeeDBContext();
//
// GET: /Home/
public ActionResult Index()
{
return View(db.tblEmp.ToList());
}
//
// GET: /Home/Details/5
public ActionResult Details(int id = 0)
{
tblEmp tblemp = db.tblEmp.Find(id);
if (tblemp == null)
{
return HttpNotFound();
}
return View(tblemp);
}
//
// GET: /Home/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Home/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(tblEmp tblemp)
{
if (ModelState.IsValid)
{
db.tblEmp.Add(tblemp);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(tblemp);
}
//
// GET: /Home/Edit/5
public ActionResult Edit(int id = 0)
{
tblEmp tblemp = db.tblEmp.Find(id);
if (tblemp == null)
{
return HttpNotFound();
}
return View(tblemp);
}
//
// POST: /Home/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(tblEmp tblemp)
{
if (ModelState.IsValid)
{
db.Entry(tblemp).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(tblemp);
}
//
// GET: /Home/Delete/5
public ActionResult Delete(int id = 0)
{
tblEmp tblemp = db.tblEmp.Find(id);
if (tblemp == null)
{
return HttpNotFound();
}
return View(tblemp);
}
//
// POST: /Home/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
tblEmp tblemp = db.tblEmp.Find(id);
db.tblEmp.Remove(tblemp);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}