mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-09-26 00:46:28 +02:00
34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
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
|
|
{
|
|
/// <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.StationId == selectedStation)
|
|
.ToDictionary(bike => bike.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 Bikes.BikeInfoNS.BluetoothLock.BikeInfo)
|
|
.ToDictionary(x => x.Id) ?? new Dictionary<string, BikeInfo>());
|
|
}
|
|
}
|
|
}
|