protected async override void OnAppearing()
        {
            base.OnAppearing();

            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location);

            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.LocationAlways);

            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.LocationWhenInUse);

            var location = await Xamarin.Essentials.Geolocation.GetLastKnownLocationAsync();

            if (location == null)
            {
                return;
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                map.Pins.Add(new Pin()
                {
                    Position    = HospitalPosition,
                    IsDraggable = false,
                    Type        = PinType.SavedPin,
                    Label       = "St. Joseph Medical Center - Achrafieh",
                    Address     = "St. Joseph Medical Center - Achrafieh",
                });

                map.Pins.Add(new Pin()
                {
                    Position = new Position(location.Latitude, location.Longitude),
                    Address  = "Your Location",
                    Label    = "Your Location",
                });
                map.MoveCamera(CameraUpdateFactory.NewCameraPosition(new CameraPosition(new Position(HospitalPosition.Latitude, HospitalPosition.Longitude), 18d, 0d, 0d)));
                map.UiSettings.RotateGesturesEnabled = false;
            });

            await LoadRoute(location.Latitude.ToString(), location.Longitude.ToString(), HospitalPosition.Latitude.ToString(), HospitalPosition.Longitude.ToString());
        }
        private async Task <bool> TryLoginAsync()
        {
            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Storage);

            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location);

            string username = Settings.Email;
            string password = Settings.Password;

            var loader = await MaterialDialog.Instance.LoadingDialogAsync("Signing In");

            AuthServices auth   = new AuthServices();
            var          result = await auth.Login(username, password);

            if (result.Success)
            {
                Constants.UserProfile = result;

                FirebaseTokenService firebaseToken = new FirebaseTokenService();

                var tokenResult = await firebaseToken.InsertFirebaseToken(result.LabID, result.Role, Settings.FirebaseToken, App.IsAndroid, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff"));

                if (tokenResult.Success)
                {
                    return(true);
                }
                else
                {
                    await MaterialDialog.Instance.AlertAsync(tokenResult.Message);
                }
            }
            else
            {
                await MaterialDialog.Instance.AlertAsync(result.Message);
            }
            await loader.DismissAsync();

            return(false);
        }
        private async void LoginCommandAsync(object obj)
        {
            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Storage);

            await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location);

            var loader = await MaterialDialog.Instance.LoadingDialogAsync("Signing In");

            Models.UserProfileModel result = new Models.UserProfileModel();

            if (Settings.IsRemember && Settings.Email != string.Empty && Settings.Password != string.Empty)
            {
                //result = await AuthServices.Login(Settings.Email, Settings.Password);
                result = new Models.UserProfileModel
                {
                    Email    = Settings.Email,
                    LabID    = Settings.LabId,
                    UserID   = Settings.UserID,
                    UserPass = Settings.Password,
                    Role     = Settings.Role,
                    Name     = Settings.Name,
                    Phone    = Settings.Phone
                };
                Constants.UserProfile = result;
                App.Current.MainPage  = new NavigationPage(new HomeView());
            }
            else
            {
                if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
                {
                    await MaterialDialog.Instance.AlertAsync("Please fill both the fields to continue");

                    return;
                }
                result = await AuthServices.Login(Username, Password);
            }

            if (result.Success)
            {
                Constants.UserProfile = result;
                if (RememberChecked)
                {
                    Settings.Email      = !String.IsNullOrEmpty(Constants.UserProfile.Email) ? Constants.UserProfile.Email : Constants.UserProfile.UserID;
                    Settings.Password   = Constants.UserProfile.UserPass;
                    Settings.Role       = result.Role;
                    Settings.LabId      = result.LabID;
                    Settings.Name       = result.Name;
                    Settings.Phone      = result.Phone;
                    Settings.UserID     = result.UserID;
                    Settings.IsRemember = true;
                }

                var tokenResult = await FirebaseTokenService.InsertFirebaseToken(result.LabID, result.Role, Settings.FirebaseToken, App.IsAndroid, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff"));

                if (tokenResult.Success)
                {
                    if (String.IsNullOrEmpty(Constants.UserProfile.Email))
                    {
                        //await PushAsync(new SignUpPage());
                        await this.Navigation.PushAsync(new SignUpPage(), false);

                        //App.Current.MainPage = new NavigationPage(new SignUpPage());
                    }
                    else
                    {
                        App.Current.MainPage = new NavigationPage(new HomeView());
                    }
                }
                else
                {
                    await UserDialogs.Instance.AlertAsync(tokenResult.Message);
                }
            }
            else
            {
                await MaterialDialog.Instance.AlertAsync(result.Message);
            }
            await loader.DismissAsync();
        }