sharee.bike-App/TINKLib/Model/Bikes/BikeCollectionFilter.cs

35 lines
1.4 KiB
C#
Raw Normal View History

2021-05-13 20:03:07 +02:00
using System.Collections.Generic;
using System.Linq;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes;
2021-05-13 20:03:07 +02:00
2022-08-30 15:42:25 +02:00
using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo;
2021-05-13 20:03:07 +02:00
namespace TINK.Model
{
2022-09-06 16:08:19 +02:00
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>());
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <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>());
}
}
2021-05-13 20:03:07 +02:00
}