public ActionResult Create() { ViewBag.fechaI = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"); ViewBag.ubicacionInOut = new SelectList(db.DataBodega, "id", "nombreBodega"); ViewBag.tipoInOut = new SelectList(db.tipoInOut, "id", "nombretipoInOut"); if (Session["entradaM"] == null) { ViewBag.cant = 0; Session["emlist"] = new List <DetalleEntrada>(); MasterEntrada entradaM = new MasterEntrada(); entradaM.varDetalleInOutP = new List <DetalleEntrada>(); entradaM.varTitulosDetalleInOutP = new DetalleEntrada(); entradaM.varInOut = new InOut(); Session["entradaM"] = entradaM; ViewBag.de = Session["emlist"]; return(View(entradaM)); } var eM = Session["entradaM"] as MasterEntrada; int a = 0; foreach (var item in eM.varDetalleInOutP) { a += item.unit; } ViewBag.cant = a; return(View(eM)); }
public ActionResult Create(MasterEntrada add) { MasterEntrada me = Session["entradaM"] as MasterEntrada; int a = 0; foreach (var item in me.varDetalleInOutP) { a += item.unit; } int ubi = int.Parse(Request["ubicacionInOut"]); string desc = add.varInOut.descripcion; DateTime fe = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); InOut io = new InOut(); io.cantidadInOut = a; io.ubicacionInOut = ubi; io.tipoInOut = 1; io.fechaInOut = fe; io.descripcion = desc; db.InOut.Add(io); db.SaveChanges(); int ioid = db.InOut.ToList().Last().id; foreach (var item in me.varDetalleInOutP) { DetalleInOutP dp = new DetalleInOutP(); dp.coidgoInOut = ioid; dp.codigoProducto = item.id; dp.cantidadP = item.unit; dp.inoutType = true; db.DetalleInOutP.Add(dp); db.SaveChanges(); int dpid = db.DetalleInOutP.ToList().Last().id; for (int i = 0; i < item.unit; i++) { Inventario inv = new Inventario(); inv.precioVenta = item.costoProducto; inv.codigoProducto = item.id; inv.ubicacionProducto = ubi; inv.estadoProducto = 1; db.Inventario.Add(inv); db.SaveChanges(); int invid = db.Inventario.ToList().Last().id; DetalleInOut dino = new DetalleInOut(); dino.codigoProducto = invid; dino.cantidad = 1; dino.coidgoInOut = dpid; db.DetalleInOut.Add(dino); db.SaveChanges(); } } ViewBag.fechaI = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"); ViewBag.ubicacionInOut = new SelectList(db.DataBodega, "id", "nombreBodega"); ViewBag.tipoInOut = new SelectList(db.tipoInOut, "id", "nombretipoInOut"); ViewBag.cant = 0; Session["emlist"] = new List <DetalleEntrada>(); MasterEntrada entradaM = new MasterEntrada(); entradaM.varDetalleInOutP = new List <DetalleEntrada>(); entradaM.varTitulosDetalleInOutP = new DetalleEntrada(); entradaM.varInOut = new InOut(); Session["entradaM"] = entradaM; ViewBag.de = Session["emlist"]; return(RedirectToAction("Create", entradaM)); }