I'm doing an inventory system, where I have to add or remove stocks of a product. I currently have a table producto
where I keep the product data (as well as the amount that I have in stock), and a table movimientoEntrada
, where I record an entry, the product that enters and the amount of that product that comes through of a TextBox.
I am using entity framework to make the connection to the base and use scaffolding to make some interfaces, the problem is that I can not find a way to add the amount of product that enters specified in the input of the view of movimientoEntrada
, or failing to add the values of the tables to be able to update the stock that I have, these are my codes:
Class / Table movement Entry:
public class MovimientoEntrada
{
public int Id { get; set; }
public int ProductosId { get; set; }
[ForeignKey("ProductosId")]
public virtual Productos Producto { get; set; }
public List<Productos> ProductoCollection { get; set; }
public int Cantidad { get; set; }
}
class / table Products:
public class Productos
{
public int Id { get; set; }
public int CodigoBarras { get; set; }
public string Nombre { get; set; }
public int Precio { get; set; }
public int Cantidad { get; set; }
}
Code in controller with which I generate a new movimientoEntrada
:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,ProductosId,Cantidad")] MovimientoEntrada movimientoEntrada)
{
if (ModelState.IsValid)
{
db.MovimientoEntradas.Add(movimientoEntrada);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.ProductosId = new SelectList(db.Productos, "Id", "Nombre", movimientoEntrada.ProductosId);
return View(movimientoEntrada);
}
My view code of movimientoEntrada
:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>MovimientoEntrada</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.ProductosId, "ProductosId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ProductosId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ProductosId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Cantidad, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Cantidad, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Cantidad, "", new { @class = "text-danger" })
@Html.
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}