148 lines
4.3 KiB
C#
148 lines
4.3 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 StockManMVC.Models;
|
|
|
|
namespace StockManMVC.Controllers
|
|
{
|
|
public class OperatorsController : Controller
|
|
{
|
|
private StockManEntities db = new StockManEntities();
|
|
|
|
// GET: Operators
|
|
public ActionResult Index()
|
|
{
|
|
return View(db.Operator.ToList());
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Selezione operatore da ricerca chiave...
|
|
/// </summary>
|
|
/// <param name="SearchVal"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable<Operator> 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/Details/5
|
|
public ActionResult Details(string id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Operator @operator = db.Operator.Find(id);
|
|
if (@operator == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(@operator);
|
|
}
|
|
|
|
// GET: Operators/Create
|
|
public ActionResult Create()
|
|
{
|
|
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
|
|
public ActionResult Edit(string id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Operator @operator = db.Operator.Find(id);
|
|
if (@operator == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
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
|
|
public ActionResult Delete(string id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Operator @operator = db.Operator.Find(id);
|
|
if (@operator == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|