Пример #1
0
        private async static Task <bool> Insertar(SalidaVehiculo salida)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                contexto.salidaVehiculos.Add(salida);
                paso = await contexto.SaveChangesAsync() > 0;

                if (paso)
                {
                    Vehiculo vehiculo = await VehiculoBLL.Buscar(salida.VehiculoId);

                    if (vehiculo != null)
                    {
                        vehiculo.Estado = Entidades.Enums.VehiculoEstado.Eliminado;
                        await VehiculoBLL.Modificar(vehiculo);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                await contexto.DisposeAsync();
            }

            return(paso);
        }
Пример #2
0
        public async static Task<bool> Eliminar(int id) {
            bool paso = false;

            var renta = await Buscar(id);

            if (renta != null) {
                renta.Eliminada = true;
                paso = await Modificar(renta);

                if (paso) {
                    var vehiculoRentado = await VehiculoBLL.Buscar(renta.VehiculoId);

                    if (vehiculoRentado != null) {
                        vehiculoRentado.Estado = VehiculoEstado.Disponible;
                        await VehiculoBLL.Modificar(vehiculoRentado);
                    }
                }
            }

            return paso;
        }
Пример #3
0
        private async static Task<bool> Insertar(Renta renta) {
            bool paso = false;
            Contexto contexto = new Contexto();

            try {
                contexto.Rentas.Add(renta);
                paso = await contexto.SaveChangesAsync() > 0;

                if (paso) {
                    var vehiculoRentado = await VehiculoBLL.Buscar(renta.VehiculoId);
                    if (vehiculoRentado != null) {
                        vehiculoRentado.Estado = VehiculoEstado.Rentado;
                        await VehiculoBLL.Modificar(vehiculoRentado);
                    }
                }

            } catch (Exception) {
                throw;
            } finally {
                await contexto.DisposeAsync();
            }

            return paso;
        }