using System.Collections.Generic; using System.Linq; using TINK.Model.Bikes; using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo; namespace TINK.Model { public static class BikeCollectionFilter { /// Filters bikes by station. /// Bikes available, requested and/ or occupied bikes to filter. /// Id of station, might be null /// BikeCollection holding bikes at given station or empty BikeCollection, if there are no bikes. public static BikeCollection GetAtStation( this BikeCollection bikesAtAnyStation, string selectedStation) { return new BikeCollection(bikesAtAnyStation? .Where(bike => !string.IsNullOrEmpty(selectedStation) && bike.StationId == selectedStation) .ToDictionary(bike => bike.Id) ?? new Dictionary()); } /// Filters bikes by bike type. /// Bikes available, requested and/ or occupied bikes to filter. /// BikeCollection holding LockIt-bikes empty BikeCollection, if there are no LockIt-bikes. public static BikeCollection GetLockIt(this BikeCollection bcAndLockItBikes) { return new BikeCollection(bcAndLockItBikes? .Where(bike => bike is Bikes.BikeInfoNS.BluetoothLock.BikeInfo) .ToDictionary(x => x.Id) ?? new Dictionary()); } } }