5ac45a7828
...prima delel modifiche che scombinano del tutto il DB...)
137 lines
4.3 KiB
C#
137 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 StocksController : Controller
|
|
{
|
|
private StockManEntities db = new StockManEntities();
|
|
|
|
// GET: Stocks
|
|
public ActionResult Index()
|
|
{
|
|
var stock = db.Stock.Include(s => s.Location).Include(s => s.Items);
|
|
return View(stock.ToList());
|
|
}
|
|
|
|
// GET: Stocks/Details/5
|
|
public ActionResult Details(int? id, string LocationID)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Stock stock = db.Stock.Find(id, LocationID);
|
|
if (stock == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(stock);
|
|
}
|
|
|
|
// GET: Stocks/Create
|
|
public ActionResult Create()
|
|
{
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr");
|
|
ViewBag.ItemID = new SelectList(db.Items, "ID", "Descr");
|
|
return View();
|
|
}
|
|
|
|
// POST: Stocks/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 = "ItemID,LocationID,QtyConf,Note,dtLastUpd")] Stock stock)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Stock.Add(stock);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", stock.LocationID);
|
|
ViewBag.ItemID = new SelectList(db.Items, "ID", "Descr", stock.ItemID);
|
|
return View(stock);
|
|
}
|
|
|
|
// GET: Stocks/Edit/5
|
|
public ActionResult Edit(int? id, string LocationID)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Stock stock = db.Stock.Find(id,LocationID);
|
|
if (stock == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", stock.LocationID);
|
|
ViewBag.ItemID = new SelectList(db.Items, "ID", "Descr", stock.ItemID);
|
|
return View(stock);
|
|
}
|
|
|
|
// POST: Stocks/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 = "ItemID,LocationID,QtyConf,Note,dtLastUpd")] Stock stock)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Entry(stock).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", stock.LocationID);
|
|
ViewBag.ItemID = new SelectList(db.Items, "ID", "Descr", stock.ItemID);
|
|
return View(stock);
|
|
}
|
|
|
|
// GET: Stocks/Delete/5
|
|
public ActionResult Delete(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Stock stock = db.Stock.Find(id);
|
|
if (stock == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(stock);
|
|
}
|
|
|
|
// POST: Stocks/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(int id)
|
|
{
|
|
Stock stock = db.Stock.Find(id);
|
|
db.Stock.Remove(stock);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|