sharee.bike-App/TINKLib/ViewModel/Bikes/Bike/BC/RequestHandler/NotLoggedIn.cs

84 lines
2.4 KiB
C#
Raw Normal View History

2023-11-06 12:23:09 +01:00
using System;
2021-05-13 20:03:07 +02:00
using System.Threading.Tasks;
2022-08-30 15:42:25 +02:00
using Serilog;
2021-05-13 20:03:07 +02:00
using TINK.Model.State;
using TINK.Model.User;
using TINK.View;
namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
{
2022-09-06 16:08:19 +02:00
public class NotLoggedIn : IRequestHandler
{
/// <param name="bikesViewModel">View model to be used for progress report and unlocking/ locking view.</param>
public NotLoggedIn(
InUseStateEnum state,
IViewService viewService,
IBikesViewModel bikesViewModel,
IUser activeUser)
{
ButtonText = state.GetActionText();
IsIdle = true;
ViewService = viewService;
BikesViewModel = bikesViewModel
?? throw new ArgumentException($"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null.");
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public bool IsButtonVisible => true;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public bool IsIdle { get; private set; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public string ButtonText { get; private set; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public string ActionText { get => BikesViewModel.ActionText; private set => BikesViewModel.ActionText = value; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Reference on view service to show modal notifications and to perform navigation.
/// </summary>
protected IViewService ViewService { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>View model to be used for progress report and unlocking/ locking view.</summary>
public IBikesViewModel BikesViewModel { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public bool IsConnected => throw new NotImplementedException();
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets if the bike has to be removed after action has been completed. </summary>
public bool IsRemoveBikeRequired => false;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public async Task<IRequestHandler> HandleRequest()
{
Log.ForContext<NotLoggedIn>().Information("User selected bike but is not logged in.");
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
// User is not logged in
ActionText = string.Empty;
var l_oResult = await ViewService.DisplayAlert(
"Hinweis",
"Bitte anmelden vor Reservierung eines Fahrrads!\r\nAuf Anmeldeseite wechseln?",
"Ja",
"Nein");
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
if (l_oResult == false)
{
// User aborted booking process
IsIdle = true;
return this;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
try
{
// Switch to login page
await ViewService.ShowPage("//LoginPage");
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
}
catch (Exception p_oException)
{
Log.ForContext<BikesViewModel>().Error("Ein unerwarteter Fehler ist in der Klasse NotLoggedIn aufgetreten. Kontext: Aufruf nach Reservierungsversuch ohne Anmeldung. {@Exception}", p_oException);
IsIdle = true;
return this;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
IsIdle = true;
return this;
}
}
2021-05-13 20:03:07 +02:00
}