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 OperatorsController : Controller { private StockManEntities db = new StockManEntities(); // GET: Operators public ActionResult Index() { return View(db.Operator.ToList()); } /// /// Selezione operatore da ricerca chiave... /// /// /// public static IEnumerable Select(string SearchVal) { StockManEntities db = new StockManEntities(); if (SearchVal == null) { SearchVal = "##########"; } var answ = db.Operator.Where(s => s.CodExt == SearchVal || s.ID == SearchVal ); return answ; } // GET: Operators/Create (mode=std|full, opzionale) public ActionResult Create(string mode) { if (mode == null) { mode = "full"; } if (mode == "std") { return PartialView(); } else { return View(); } } // POST: Operators/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,CodExt,LastName,FirstName")] Operator @operator) { if (ModelState.IsValid) { db.Operator.Add(@operator); db.SaveChanges(); return RedirectToAction("Index"); } return View(@operator); } // GET: Operators/Edit/5 (mode=std|full, opzionale) public ActionResult Edit(string id, string mode) { if (mode == null) { mode = "full"; } if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Operator @operator = db.Operator.Find(id); if (@operator == null) { return HttpNotFound(); } if (mode == "std") { return PartialView(@operator); } else { return View(@operator); } } // POST: Operators/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,CodExt,LastName,FirstName")] Operator @operator) { if (ModelState.IsValid) { db.Entry(@operator).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(@operator); } // GET: Operators/Delete/5 (mode=std|full, opzionale) public ActionResult Delete(string id, string mode) { if (mode == null) { mode = "full"; } if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Operator @operator = db.Operator.Find(id); if (@operator == null) { return HttpNotFound(); } if (mode == "std") { return PartialView(@operator); } else { return View(@operator); } } // POST: Operators/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(string id) { Operator @operator = db.Operator.Find(id); db.Operator.Remove(@operator); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } } }