sharee.bike-App/TINKLib/Model/Bikes/BikeCollectionFilter.cs
2021-06-26 20:57:55 +02:00

35 lines
1.6 KiB
C#

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