using System; using System.Threading.Tasks; using Serilog; using ShareeBike.Model.State; using ShareeBike.Model.User; using ShareeBike.View; namespace ShareeBike.ViewModel.Bikes.Bike.BC.RequestHandler { public class NotLoggedIn : IRequestHandler { /// View model to be used for progress report and unlocking/ locking view. 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."); } public bool IsButtonVisible => true; public bool IsIdle { get; private set; } public string ButtonText { get; private set; } public string ActionText { get => BikesViewModel.ActionText; private set => BikesViewModel.ActionText = value; } /// /// Reference on view service to show modal notifications and to perform navigation. /// protected IViewService ViewService { get; } /// View model to be used for progress report and unlocking/ locking view. public IBikesViewModel BikesViewModel { get; } public bool IsConnected => throw new NotImplementedException(); /// Gets if the bike has to be removed after action has been completed. public bool IsRemoveBikeRequired => false; public async Task HandleRequest() { Log.ForContext().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 { // Switch to login page await ViewService.ShowPage("//LoginPage"); } catch (Exception p_oException) { Log.ForContext().Error("Ein unerwarteter Fehler ist in der Klasse NotLoggedIn aufgetreten. Kontext: Aufruf nach Reservierungsversuch ohne Anmeldung. {@Exception}", p_oException); IsIdle = true; return this; } IsIdle = true; return this; } } }