public ParkingSpaceDTO Read(int parkingspaceID)
        {
            ParkingSpaceDTO pspace = new ParkingSpaceDTO();

            using var connection = Connection.GetConnection();
            {
                using var command = connection.CreateCommand();

                command.CommandText = "SELECT * FROM ParkingSpace WHERE ParkingSpaceID = @parkingspaceID";
                command.Parameters.AddWithValue("@parkingspaceID", parkingspaceID);

                connection.Open();

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        pspace = new ParkingSpaceDTO(
                            reader.GetInt32("ParkingSpaceID"),
                            reader.GetInt32("BusID"),
                            reader.GetInt32("Number"),
                            reader.GetInt32("Type"),
                            reader.GetBoolean("Occupied")
                            );
                    }
                }

                connection.Close();
                return(pspace);
            }
        }
        public ParkingSpace Read(int parkingspaceID)
        {
            ParkingSpaceDTO pspaceDTO = handler.Read(parkingspaceID);

            if (pspaceDTO.ParkingSpaceID == 0)
            {
                return(null);
            }
            ParkingSpace pspace = new(pspaceDTO.ParkingSpaceID, pspaceDTO.BusID, pspaceDTO.Number, (ParkingTypeEnum)pspaceDTO.Type, pspaceDTO.Occupied);

            return(pspace);
        }
        public bool UpdateOccupied(ParkingSpaceDTO ParkingSpace)
        {
            using var connection = Connection.GetConnection();
            {
                try
                {
                    using var command = connection.CreateCommand();

                    command.CommandText = "UPDATE ParkingSpace SET BusID = @BusID, Occupied = @Occupied WHERE ParkingSpaceID = @ParkingSpaceID";
                    command.Parameters.AddWithValue("@ParkingSpaceID", ParkingSpace.ParkingSpaceID);
                    command.Parameters.AddWithValue("@BusID", ParkingSpace.BusID);
                    command.Parameters.AddWithValue("@Occupied", ParkingSpace.Occupied);

                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();

                    return(true);
                }
                catch { connection.Close(); return(false); }
            }
        }
        public bool Create(ParkingSpaceDTO pspaceDTO)
        {
            using var connection = Connection.GetConnection();
            {
                try
                {
                    using var command = connection.CreateCommand();

                    command.CommandText = "INSERT INTO ParkingSpace(BusID, Number, Type, Occupied) VALUES(@busID, @number, @type, @occupied);";
                    command.Parameters.AddWithValue("@busID", pspaceDTO.BusID);
                    command.Parameters.AddWithValue("@number", pspaceDTO.Number);
                    command.Parameters.AddWithValue("@type", pspaceDTO.Type);
                    command.Parameters.AddWithValue("@occupied", pspaceDTO.Occupied);

                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                    return(true);
                }
                catch { connection.Close(); return(false); }
            }
        }
Beispiel #5
0
 public async Task <ParkingSpaceDTO> Update(ParkingSpaceDTO parkingSpace)
 {
     return(await MappingDataUtils.WrapperMappingDALFunc <ParkingSpaceDTO, ParkingSpace>
                (_database.ParkingSpaceRepository.Update, parkingSpace, _mapper));
 }
        public bool UpdateOccupied(ParkingSpace parkingSpace)
        {
            ParkingSpaceDTO parkingSpaceDTO = new ParkingSpaceDTO(parkingSpace.ParkingSpaceID, parkingSpace.BusID, parkingSpace.Occupied);

            return(handler.UpdateOccupied(parkingSpaceDTO));
        }
        public bool Update(ParkingSpace parkingSpace)
        {
            ParkingSpaceDTO parkingSpaceDTO = new ParkingSpaceDTO(parkingSpace.ParkingSpaceID, parkingSpace.BusID, parkingSpace.Number, (int)parkingSpace.Type, parkingSpace.Occupied);

            return(handler.Update(parkingSpaceDTO));
        }