Beispiel #1
0
        ///<sumary>Creación de un nuevo vehiculo</sumary>
        ///<param name="vehicle">Instancia de Vehicle</param>
        ///<returns>Id del vehiculo</returns>
        ///<exception cref="ModelNotFoundException"> Si no existe el modelo </exception>
        ///<exception cref="LocationNotFoundException"> Si no existe la ciudad </exception>
        ///<exception cref="UniqueAttributeException">
        /// Es excepción es lanzada cuando ya existe un carro con dicha matricula
        ///</exception>
        public int AddVehicle(Vehicle vehicle)
        {
            int id = 0;

            try {
                PostgresModelDAO modelDAO = new PostgresModelDAO();
                modelDAO.GetModelById(vehicle.VehicleModelId);          //Throw ModelNotFoundException
                PostgresLocationDAO locationDAO = new PostgresLocationDAO();
                locationDAO.GetLocationById(vehicle.VehicleLocationId); // Throw LocationNotFoundException
                PgConnection pgConnection = PgConnection.Instance;
                DataTable    dataTable    = pgConnection.ExecuteFunction(
                    "LicenseUniqueness(@modelName)", vehicle.License);
                if (Convert.ToBoolean(dataTable.Rows[0][0]))
                {
                    throw new UniqueAttributeException("La matricula " + vehicle.License + " ya existe");
                }
                else
                {
                    dataTable = pgConnection.ExecuteFunction(
                        "AddVehicle(@modelId, @locationId, @license, @price, @status)",
                        vehicle.VehicleModelId, vehicle.VehicleLocationId, vehicle.License, vehicle.Price, vehicle.Status);
                    id = Convert.ToInt32(dataTable.Rows[0][0]);
                }
            } catch (DatabaseException ex) {
                throw new InternalServerErrorException("Error en el servidor : Conexion a base de datos", ex);
            } catch (InvalidStoredProcedureSignatureException ex) {
                throw new InternalServerErrorException("Error en el servidor", ex);
            }
            return(id);
        }
Beispiel #2
0
        ///<sumary>Modificar un vehiculo</sumary>
        ///<param name="vehicle">Instancia de Vehicle</param>
        ///<returns>True si actualizo correctamente</returns>
        ///<exception cref="VehicleNotFoundException"> Si el vehiculo no existe </exception>
        ///<exception cref="ModelNotFoundException"> Si el modelo no existe </exception>
        ///<exception cref="LocationNotFoundException"> Si la ciudad no existe </exception>
        public bool UpdateVehicle(Vehicle vehicle)
        {
            bool updated = false;

            try{
                GetVehicleById(vehicle.Id);                             // Throw VehicleNotFoundException
                PostgresModelDAO modelDAO = new PostgresModelDAO();
                modelDAO.GetModelById(vehicle.VehicleModelId);          //Throw ModelNotFoundException
                PostgresLocationDAO locationDAO = new PostgresLocationDAO();
                locationDAO.GetLocationById(vehicle.VehicleLocationId); // Throw LocationNotFoundException
                PgConnection pgConnection = PgConnection.Instance;
                DataTable    dataTable    = pgConnection.ExecuteFunction(
                    "UpdateVehicle(@vehid, @vehmodel, @vehlocation, @vehlicense, @vehprice, @vehstatus)",
                    vehicle.Id, vehicle.VehicleModelId, vehicle.VehicleLocationId, vehicle.License, vehicle.Price, vehicle.Status);
                if (Convert.ToBoolean(dataTable.Rows[0][0]))
                {
                    updated = true;
                }
            }catch (DatabaseException ex) {
                throw new InternalServerErrorException("Error en el servidor : Conexion a base de datos", ex);
            }catch (InvalidStoredProcedureSignatureException ex) {
                throw new InternalServerErrorException("Error en el servidor", ex);
            }
            return(updated);
        }