private static PedidoSugerido GetStockSimple(int Producto, int Cant) { using (var db = new AppDTEntities()) { var stock = db.PRODUCTOS_PV.Where(a => a.Prod_Id == Producto).ToList(); var s1 = Convert.ToInt32(stock[0].Prod_Stock); if (s1 <= 2) { decimal st = Convert.ToDecimal(stock[0].Prod_Stock); string date = DateTime.Now.Date.ToString("yyyy-MM-dd"); var ps = new PEDIDO_SUGERIDO_PV { Prod_Id = Producto, Sucu_Id = "1", Prod_Stock = st, Prod_date = date, Pedi_Status = 0 }; db.PEDIDO_SUGERIDO_PV.Add(ps); db.SaveChanges(); } int resta = s1 - Cant; if (resta > 0) { var producto = (from s in db.PRODUCTOS_PV where s.Prod_Id == Producto select s).FirstOrDefault(); producto.Prod_Stock = resta; // producto.Ticket_Subtotal = Convert.ToInt32(lblTotal.Text); int num = db.SaveChanges(); } else { MessageBox.Show("No cuentas con stock suficiente"); } var result = new PedidoSugerido { add = resta }; return(result); } }