public ActionResult Registrar() { ASIGNACIONES asignaciones = new ASIGNACIONES(); var con = new SqlConnection("Data Source=DESKTOP-I5C9AA0\\SQLEXPRESS2008;Initial Catalog=InventarioUXBD;Integrated Security=True"); con.Open(); Item i = new Item(); List <Item> cart = (List <Item>)Session["cart"]; int preciototal = 0; asignaciones.EMPLEADOID = int.Parse(Session["ID"].ToString()); int departamentoid = int.Parse(Session["Departamento"].ToString()); int trabajadorid = int.Parse(Session["Trabajador"].ToString()); asignaciones.DEPARTAMENTOID = departamentoid; asignaciones.Fecha = DateTime.Now; db.ASIGNACIONES.Add(asignaciones); db.SaveChanges(); foreach (Item item in cart) { ASIGNACIONES_LISTA asignaciones_lista = new ASIGNACIONES_LISTA(); asignaciones_lista.PRODUCTOID = item.Producto.ID; asignaciones_lista.PRECIO = item.Producto.PRECIO; preciototal = preciototal + (item.Producto.PRECIO * item.Cantidad); asignaciones_lista.ASIGNACIONID = asignaciones.ID; db.ASIGNACIONES_LISTA.Add(asignaciones_lista); db.SaveChanges(); //Asigna nombre de depto al producto SqlCommand command2 = new SqlCommand("SELECT NOMBRE FROM DEPARTAMENTOS WHERE ID = " + departamentoid + "", con); string departamentonombre = (string)(command2.ExecuteScalar()); SqlCommand command = new SqlCommand("UPDATE PRODUCTOS SET UBICACION = '" + departamentonombre + "' WHERE ID = " + item.Producto.ID + "", con); command.ExecuteNonQuery(); //Asigna nombre de empleado al producto SqlCommand command3 = new SqlCommand("SELECT NOMBRE FROM TRABAJADORESUXes WHERE ID = " + trabajadorid + "", con); string trabajadornombre = (string)(command3.ExecuteScalar()); SqlCommand command4 = new SqlCommand("UPDATE PRODUCTOS SET EMPLEADOASIGNACION = '" + trabajadornombre + "' WHERE ID = " + item.Producto.ID + "", con); command4.ExecuteNonQuery(); } asignaciones.PRECIOTOTAL = preciototal; db.SaveChanges(); Session.Remove("cart"); Session.Remove("Departamento"); Session.Remove("Trabajador"); return(View()); }
public ActionResult ReciboAsignacion(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ASIGNACIONES mOV_ASIGNACION = db.ASIGNACIONES.Find(id); if (mOV_ASIGNACION == null) { return(HttpNotFound()); } List <int> result = new List <int>(); var con = new SqlConnection("Data Source=DESKTOP-I5C9AA0\\SQLEXPRESS2008;Initial Catalog=InventarioUXBD;Integrated Security=True"); con.Open(); var command = new SqlCommand("SELECT ID FROM ASIGNACIONES_LISTA WHERE ASIGNACIONID='" + id + "'", con); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { result.Add(Convert.ToInt32(reader["ID"])); } List <ASIGNACIONES_LISTA> listaProductos = new List <ASIGNACIONES_LISTA>(); int i = 0; foreach (var w in result) { var x = db.ASIGNACIONES_LISTA.Find(result[i]); ASIGNACIONES_LISTA x2 = new ASIGNACIONES_LISTA(); x2.CONTAINING_PRODUCTOS = x.CONTAINING_PRODUCTOS; x2.PRECIO = x.PRECIO; x2.CANTIDAD = x.CANTIDAD; listaProductos.Add(x2); i++; } ViewBag.ListaAsignacion = listaProductos; return(View(mOV_ASIGNACION)); }