2bc5fbb51c
- esplicitata visualizzazione ID - protetti record che iniziano con "#" come riservati x editing/delete - inserito TRIM spazi alla creazione nuovo (x Location, ItemFamily...)
151 lines
4.4 KiB
C#
151 lines
4.4 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 ItemFamiliesController : Controller
|
|
{
|
|
private StockManEntities db = new StockManEntities();
|
|
|
|
// GET: ItemFamilies
|
|
public ActionResult Index()
|
|
{
|
|
var ItemFam = db.ItemFamily.Include(vItemFlux2Save => vItemFlux2Save.Item);
|
|
return View(ItemFam.ToList());
|
|
}
|
|
|
|
// GET: ItemFamilies/Create (mode=std|full, opzionale)
|
|
public ActionResult Create(string mode)
|
|
{
|
|
if (mode == null)
|
|
{
|
|
mode = "full";
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView();
|
|
}
|
|
else
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
|
|
// POST: ItemFamilies/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")] ItemFamily itemFamily)
|
|
{
|
|
// verifico ID: nel caso trimmo spazi...
|
|
itemFamily.ID = itemFamily.ID.Trim().Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ","_").ToUpper();
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.ItemFamily.Add(itemFamily);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
return View(itemFamily);
|
|
}
|
|
|
|
// GET: ItemFamilies/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);
|
|
}
|
|
ItemFamily itemFamily = db.ItemFamily.Find(id);
|
|
if (itemFamily == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(itemFamily);
|
|
}
|
|
else
|
|
{
|
|
return View(itemFamily);
|
|
}
|
|
}
|
|
|
|
// POST: ItemFamilies/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")] ItemFamily itemFamily)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Entry(itemFamily).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
return View(itemFamily);
|
|
}
|
|
|
|
// GET: ItemFamilies/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);
|
|
}
|
|
ItemFamily itemFamily = db.ItemFamily.Find(id);
|
|
ViewBag.mode = mode;
|
|
if (itemFamily == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(itemFamily);
|
|
}
|
|
else
|
|
{
|
|
return View(itemFamily);
|
|
}
|
|
}
|
|
|
|
// POST: ItemFamilies/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(string id)
|
|
{
|
|
ItemFamily itemFamily = db.ItemFamily.Find(id);
|
|
db.ItemFamily.Remove(itemFamily);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|