146 lines
4.0 KiB
C#
146 lines
4.0 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 LocTypesController : Controller
|
|
{
|
|
private StockManEntities db = new StockManEntities();
|
|
|
|
// GET: LocTypes
|
|
public ActionResult Index()
|
|
{
|
|
return View(db.LocType.ToList());
|
|
}
|
|
|
|
// GET: LocTypes/Create (mode=std|full, opzionale)
|
|
public ActionResult Create(string mode)
|
|
{
|
|
if (mode == null)
|
|
{
|
|
mode = "full";
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView();
|
|
}
|
|
else
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
|
|
// POST: LocTypes/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,IsStock,IsCli,IsFor")] LocType locType)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.LocType.Add(locType);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
return View(locType);
|
|
}
|
|
|
|
// GET: LocTypes/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);
|
|
}
|
|
LocType locType = db.LocType.Find(id);
|
|
if (locType == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(locType);
|
|
}
|
|
else
|
|
{
|
|
return View(locType);
|
|
}
|
|
}
|
|
|
|
// POST: LocTypes/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,IsStock,IsCli,IsFor")] LocType locType)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Entry(locType).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
return View(locType);
|
|
}
|
|
|
|
// GET: LocTypes/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);
|
|
}
|
|
LocType locType = db.LocType.Find(id);
|
|
if (locType == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(locType);
|
|
}
|
|
else
|
|
{
|
|
return View(locType);
|
|
}
|
|
}
|
|
|
|
// POST: LocTypes/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(string id)
|
|
{
|
|
LocType locType = db.LocType.Find(id);
|
|
db.LocType.Remove(locType);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|