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 StockManMVC.Models; namespace StockManMVC.Controllers { public class LocationsController : Controller { private StockManEntities db = new StockManEntities(); // GET: Locations public ActionResult Index() { var location = db.Location.Include(l => l.LocType); return View(location.ToList()); } // GET: Locations/Details/5 public ActionResult Details(string id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Location location = db.Location.Find(id); if (location == null) { return HttpNotFound(); } return View(location); } // GET: Locations/Create public ActionResult Create() { ViewBag.LocTypeID = new SelectList(db.LocType, "ID", "Descr"); return View(); } // POST: Locations/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "ID,Descr,LocTypeID")] Location location) { if (ModelState.IsValid) { db.Location.Add(location); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.LocTypeID = new SelectList(db.LocType, "ID", "Descr", location.LocTypeID); return View(location); } // GET: Locations/Edit/5 public ActionResult Edit(string id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Location location = db.Location.Find(id); if (location == null) { return HttpNotFound(); } ViewBag.LocTypeID = new SelectList(db.LocType, "ID", "Descr", location.LocTypeID); return View(location); } // POST: Locations/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "ID,Descr,LocTypeID")] Location location) { if (ModelState.IsValid) { db.Entry(location).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.LocTypeID = new SelectList(db.LocType, "ID", "Descr", location.LocTypeID); return View(location); } // GET: Locations/Delete/5 public ActionResult Delete(string id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Location location = db.Location.Find(id); if (location == null) { return HttpNotFound(); } return View(location); } // POST: Locations/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(string id) { Location location = db.Location.Find(id); db.Location.Remove(location); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } } }