Files
Samuele E. Locatelli 2bc5fbb51c modificata gestione locations:
- esplicitata visualizzazione ID
- protetti record che iniziano con "#" come riservati x editing/delete
- inserito TRIM spazi alla creazione nuovo (x Location, ItemFamily...)
2016-10-31 16:29:33 +01:00

148 lines
4.1 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 MovTypesController : Controller
{
private StockManEntities db = new StockManEntities();
// GET: MovTypes
public ActionResult Index()
{
return View(db.MovType.ToList());
}
// GET: MovTypes/Create (mode=std|full, opzionale)
public ActionResult Create(string mode)
{
if (mode == null)
{
mode = "full";
}
if (mode == "std")
{
return PartialView();
}
else
{
return View();
}
}
// POST: MovTypes/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,CssClass")] MovType movType)
{
// verifico ID: nel caso trimmo spazi...
movType.ID = movType.ID.Trim().Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", "_").ToUpper();
if (ModelState.IsValid)
{
db.MovType.Add(movType);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movType);
}
// GET: MovTypes/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);
}
MovType movType = db.MovType.Find(id);
if (movType == null)
{
return HttpNotFound();
}
if (mode == "std")
{
return PartialView(movType);
}
else
{
return View(movType);
}
}
// POST: MovTypes/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,CssClass")] MovType movType)
{
if (ModelState.IsValid)
{
db.Entry(movType).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movType);
}
// GET: MovTypes/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);
}
MovType movType = db.MovType.Find(id);
if (movType == null)
{
return HttpNotFound();
}
if (mode == "std")
{
return PartialView(movType);
}
else
{
return View(movType);
}
}
// POST: MovTypes/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(string id)
{
MovType movType = db.MovType.Find(id);
db.MovType.Remove(movType);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}