sharee.bike-App/TINKLib/ViewModel/Bikes/Bike/BC/RequestHandler/Booked.cs
2023-06-06 12:05:48 +02:00

75 lines
2.3 KiB
C#

using System;
using System.Threading.Tasks;
using Serilog;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.User;
using TINK.MultilingualResources;
using TINK.View;
namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
{
public class Booked : IRequestHandler
{
/// <summary>
/// If a bike is booked unbooking can not be done by though app.
/// </summary>
public bool IsButtonVisible => false;
/// <summary>
/// Gets the name of the button when bike is cancel reservation.
/// </summary>
public string ButtonText => AppResources.ActionReturn; // "Miete beenden"
/// <summary>
/// Reference on view service to show modal notifications and to perform navigation.
/// </summary>
protected IViewService ViewService { get; }
/// <summary>View model to be used for progress report and unlocking/ locking view.</summary>
public IBikesViewModel BikesViewModel { get; }
/// <summary> Executes user request to cancel reservation. </summary>
public async Task<IRequestHandler> HandleRequest()
{
// Lock list to avoid multiple taps while copri action is pending.
BikesViewModel.ActionText = AppResources.ActivityTextOneMomentPlease;
BikesViewModel.IsIdle = false;
Log.ForContext<BikesViewModel>().Error("User selected booked bike {l_oId}.", SelectedBike.Id);
BikesViewModel.ActionText = string.Empty;
await ViewService.DisplayAlert(
string.Empty,
"Rückgabe nur über Bordcomputer des Fahrrads durch Drücken der Taste 2 möglich!",
"Ok");
BikesViewModel.IsIdle = true;
return this;
}
/// <summary>
/// Bike to display.
/// </summary>
protected IBikeInfoMutable SelectedBike { get; }
/// <summary>Gets the is connected state. </summary>
public bool IsConnected { get; set; }
/// <summary> Gets if the bike has to be removed after action has been completed. </summary>
public bool IsRemoveBikeRequired => false;
/// <param name="bikesViewModel">View model to be used for progress report and unlocking/ locking view.</param>
public Booked(
IBikeInfoMutable selectedBike,
IViewService viewService,
IBikesViewModel bikesViewModel,
IUser activeUser)
{
SelectedBike = selectedBike;
ViewService = viewService;
BikesViewModel = bikesViewModel
?? throw new ArgumentException($"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null.");
}
}
}