Exemplo n.º 1
0
        public static bool Eliminar(int id)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                var aux = contexto.Ventas.Find(id);

                if (aux != null)
                {
                    var auxVehiculo = contexto.Vehiculos.Find(aux.VehiculoId);
                    if (auxVehiculo != null)
                    {
                        auxVehiculo.Estado = "Disponible";
                        VehiculosBLL.Modificar(auxVehiculo);
                    }
                    contexto.Ventas.Remove(aux);//remueve la informacion de la entidad relacionada
                    paso = contexto.SaveChanges() > 0;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }

            return(paso);
        }
Exemplo n.º 2
0
        private static bool Insertar(Ventas ventas)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                var vehiculo = VehiculosBLL.Buscar(ventas.VehiculoId);

                if (vehiculo != null)
                {
                    vehiculo.Estado = "Vendido";    //Cambiando el estado del vehículo a vendido
                    VehiculosBLL.Modificar(vehiculo);
                }

                contexto.Ventas.Add(ventas);
                paso = contexto.SaveChanges() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }
            return(paso);
        }