2021-05-13 20:03:07 +02:00
using Serilog ;
using System ;
using System.Threading.Tasks ;
using TINK.Model.State ;
using TINK.Model.User ;
using TINK.View ;
namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
{
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 )
{
State = state ;
IsIdle = true ;
ViewService = viewService ;
BikesViewModel = bikesViewModel
? ? throw new ArgumentException ( $"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null." ) ;
}
public InUseStateEnum State { get ; }
public bool IsButtonVisible = > true ;
public bool IsIdle { get ; private set ; }
public string ButtonText = > State . GetActionText ( ) ;
public string ActionText { get = > BikesViewModel . ActionText ; private set = > BikesViewModel . ActionText = value ; }
/// <summary>
2021-08-01 17:24:15 +02:00
/// Reference on view service to show modal notifications and to perform navigation.
2021-05-13 20:03:07 +02:00
/// </summary>
protected IViewService ViewService { get ; }
/// <summary>View model to be used for progress report and unlocking/ locking view.</summary>
public IBikesViewModel BikesViewModel { get ; }
public bool IsConnected = > throw new NotImplementedException ( ) ;
/// <summary> Gets if the bike has to be removed after action has been completed. </summary>
public bool IsRemoveBikeRequired = > false ;
public async Task < IRequestHandler > HandleRequest ( )
{
Log . ForContext < NotLoggedIn > ( ) . Information ( "User selected bike but is not logged in." ) ;
// 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" ) ;
if ( l_oResult = = false )
{
// User aborted booking process
IsIdle = true ;
return this ;
}
try
{
2021-06-26 20:57:55 +02:00
// Switch to login page
2021-08-28 10:04:10 +02:00
#if USEFLYOUT
2021-05-13 20:03:07 +02:00
ViewService . ShowPage ( ViewTypes . LoginPage ) ;
2021-06-26 20:57:55 +02:00
#else
await ViewService . ShowPage ( "//LoginPage" ) ;
#endif
2021-05-13 20:03:07 +02:00
}
catch ( Exception p_oException )
{
2021-07-22 22:41:35 +02:00
Log . ForContext < BikesViewModel > ( ) . Error ( "Ein unerwarteter Fehler ist in der Klasse NotLoggedIn aufgetreten. Kontext: Aufruf nach Reservierungsversuch ohne Anmeldung. {@Exception}" , p_oException ) ;
2021-05-13 20:03:07 +02:00
IsIdle = true ;
return this ;
}
IsIdle = true ;
return this ;
}
}
}