using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using AspMvcCodeFirst.Models; namespace AspMvcCodeFirst.Controllers { public class CategoryController : Controller { private CodeFirstModel db = new CodeFirstModel(); // // GET: /Category/ public ActionResult Index() { return View(db.Categories.ToList()); } // // GET: /Category/Details/5 public ActionResult Details(long id = 0) { Category category = db.Categories.Find(id); if (category == null) { return HttpNotFound(); } return View(category); } // // GET: /Category/Create public ActionResult Create() { return View(); } // // POST: /Category/Create [HttpPost] public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return RedirectToAction("Index"); } return View(category); } // // GET: /Category/Edit/5 public ActionResult Edit(long id = 0) { Category category = db.Categories.Find(id); if (category == null) { return HttpNotFound(); } return View(category); } // // POST: /Category/Edit/5 [HttpPost] public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(category); } // // GET: /Category/Delete/5 public ActionResult Delete(long id = 0) { Category category = db.Categories.Find(id); if (category == null) { return HttpNotFound(); } return View(category); } // // POST: /Category/Delete/5 [HttpPost, ActionName("Delete")] public ActionResult DeleteConfirmed(long id) { Category category = db.Categories.Find(id); db.Categories.Remove(category); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { db.Dispose(); base.Dispose(disposing); } } }Dosyayı İndir