129 lines
3.7 KiB
C#
129 lines
3.7 KiB
C#
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 Church.Net.DAL.EF;
|
|
using Church.Net.Entity;
|
|
|
|
namespace Chruch.Net.Areas.dashboard.Controllers
|
|
{
|
|
public class ReligionsController : Controller
|
|
{
|
|
private ChurchNetContext db = new ChurchNetContext();
|
|
|
|
// GET: dashboard/Religions
|
|
public ActionResult Index()
|
|
{
|
|
return View(db.Religions.ToList());
|
|
}
|
|
|
|
// GET: dashboard/Religions/Details/5
|
|
public ActionResult Details(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Religion religion = db.Religions.Find(id);
|
|
if (religion == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(religion);
|
|
}
|
|
|
|
// GET: dashboard/Religions/Create
|
|
public ActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
// POST: dashboard/Religions/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Create([Bind(Include = "ReligionId,Name")] Religion religion)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Religions.Add(religion);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
return View(religion);
|
|
}
|
|
|
|
// GET: dashboard/Religions/Edit/5
|
|
public ActionResult Edit(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Religion religion = db.Religions.Find(id);
|
|
if (religion == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(religion);
|
|
}
|
|
|
|
// POST: dashboard/Religions/Edit/5
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Edit([Bind(Include = "ReligionId,Name")] Religion religion)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Entry(religion).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
return View(religion);
|
|
}
|
|
|
|
// GET: dashboard/Religions/Delete/5
|
|
public ActionResult Delete(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Religion religion = db.Religions.Find(id);
|
|
if (religion == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(religion);
|
|
}
|
|
|
|
// POST: dashboard/Religions/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(int id)
|
|
{
|
|
Religion religion = db.Religions.Find(id);
|
|
db.Religions.Remove(religion);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|