protected override async void OnResume() { lstMessage = new List <clsMessages>(); var snackbarConfiguration = new MaterialSnackbarConfiguration() { TintColor = Color.White, MessageTextColor = HttpRequest.CheckConnection() ? Color.White : Color.Red }; if (!HttpRequest.CheckConnection()) { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are not connected to internet."); } else { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are connected to internet."); DependencyService.Get <IProgressBar>().Show(Resx.AppResources.pleaseWait); var data = App.database.GetBooking(); if (data != null) { if (data.Count > 0) { try { await DependencyService.Get <IXSnack>().ShowMessageAsync("Syncing Data. Please wait.."); foreach (var item in data) { clsMessages messagedata = new clsMessages(); var locjsonStringOfflone = Newtonsoft.Json.JsonConvert.DeserializeObject <LocationData>(item.Location); var locationData = new LocationData() { lat = locjsonStringOfflone.lat, lng = locjsonStringOfflone.lng, radius = locjsonStringOfflone.radius }; var locjsonString = Newtonsoft.Json.JsonConvert.SerializeObject(locationData); var postData = new List <BookingModel>() { new BookingModel() { DateTime = item.DateTime, Direction = item.Direction, Location = locjsonString, HappinessOption = item.HappinessOption, ReasonCode = item.ReasonCode } }; var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(postData); var loginInfo = await CommonMethods.BookingAttendance(jsonString); if (loginInfo.Status) { messagedata.Status = loginInfo.Status; messagedata.Message = loginInfo.Message; App.database.ClearBookingBasedOnId(item); //await MaterialDialog.Instance.SnackbarAsync(message: "Data successfully synced to the server.", //msDuration: MaterialSnackbar.DurationLong); } else { messagedata.Status = loginInfo.Status; messagedata.Message = loginInfo.Message; DependencyService.Get <IProgressBar>().Hide(); //await MaterialDialog.Instance.SnackbarAsync(message: "Error syncing data to the server.", // msDuration: MaterialSnackbar.DurationLong); } lstMessage.Add(messagedata); } } catch (Exception ex) { DependencyService.Get <IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync(ex.Message); } finally { DependencyService.Get <IProgressBar>().Hide(); if (lstMessage.Any(x => x.Status == false)) { await DependencyService.Get <IXSnack>().ShowMessageAsync("Error syncing data to the server."); } else { await DependencyService.Get <IXSnack>().ShowMessageAsync("Data successfully synced to the server."); } } } else { DependencyService.Get <IProgressBar>().Hide(); Device.BeginInvokeOnMainThread(async() => { await DependencyService.Get <IXSnack>().ShowMessageAsync("There is no record stored locally."); }); } } else { DependencyService.Get <IProgressBar>().Hide(); Device.BeginInvokeOnMainThread(async() => { await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.ErrorLoadingData); }); } } }
public async void ExecuteSubmitCommand() { IsEnabledSubmitButton = false; try { //if (!Validate()) //{ // await DependencyService.Get<IXSnack>().ShowMessageAsync(Error); // return; //} if (!HttpRequest.CheckConnection()) { //DependencyService.Get<IProgressBar>().Show(Resx.AppResources.pleaseWait); using (await MaterialDialog.Instance.LoadingDialogAsync(message: Resx.AppResources.pleaseWait)) { var request = new GeolocationRequest(GeolocationAccuracy.High); var fakelocation = await Geolocation.GetLocationAsync(request); if (fakelocation != null) { if (fakelocation.IsFromMockProvider) { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are using Fake Location."); return; } } var locator = CrossGeolocator.Current; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var sourceLocation = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); if (sourceLocation != null) { Location sourceCoordinates = new Location(sourceLocation.Latitude, sourceLocation.Longitude); double distance = Location.CalculateDistance(sourceCoordinates, LatLongLocation, DistanceUnits.Kilometers); double distanceMeter = distance * 1000; var locationDataOfflone = new LocationData() { lat = sourceCoordinates.Latitude, lng = sourceCoordinates.Longitude, radius = distanceMeter }; var locjsonStringOfflone = Newtonsoft.Json.JsonConvert.SerializeObject(locationDataOfflone); var tzIana = TimeZoneLookup.GetTimeZone(sourceCoordinates.Latitude, sourceCoordinates.Longitude).Result; var tzInfo = TimeZoneInfo.FindSystemTimeZoneById(tzIana); GPSDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzInfo); var postDataOfflone = new List <BookingModel>() { new BookingModel() { DateTime = GPSDateTime, Direction = Direction, Location = locjsonStringOfflone, HappinessOption = SelectedHappinessOption?.HappynessCode, ReasonCode = SelectedReason?.code } }; foreach (var item in postDataOfflone) { DBBookingModel dbdata = new DBBookingModel(); dbdata.DateTime = item.DateTime; dbdata.Direction = item.Direction; dbdata.HappinessOption = item.HappinessOption; dbdata.Location = item.Location; dbdata.ReasonCode = item.ReasonCode; App.Database.SaveBooking(dbdata); } IsUserExist = true; await _navigation.PopAsync(); await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.youAreChecked + " " + Direction + " " + Resx.AppResources.successfully); } } else { await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.pleaseEnableYourLocationService); } } return; } using (await MaterialDialog.Instance.LoadingDialogAsync(message: Resx.AppResources.pleaseWait)) { var request = new GeolocationRequest(GeolocationAccuracy.High); var fakelocation = await Geolocation.GetLocationAsync(request); if (fakelocation != null) { if (fakelocation.IsFromMockProvider) { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are using Fake Location."); return; } } var locator = CrossGeolocator.Current; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var sourceLocation = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); if (sourceLocation != null) { Location sourceCoordinates = new Location(sourceLocation.Latitude, sourceLocation.Longitude); double distance = Location.CalculateDistance(sourceCoordinates, LatLongLocation, DistanceUnits.Kilometers); double distanceMeter = distance * 1000; var locationData = new LocationData() { lat = sourceCoordinates.Latitude, lng = sourceCoordinates.Longitude, radius = distanceMeter }; var locjsonString = Newtonsoft.Json.JsonConvert.SerializeObject(locationData); var tzIana = TimeZoneLookup.GetTimeZone(sourceCoordinates.Latitude, sourceCoordinates.Longitude).Result; var tzInfo = TimeZoneInfo.FindSystemTimeZoneById(tzIana); GPSDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzInfo); var postData = new List <BookingModel>() { new BookingModel() { DateTime = GPSDateTime, Direction = Direction, Location = locjsonString, HappinessOption = SelectedHappinessOption?.HappynessCode, ReasonCode = SelectedReason?.code } }; var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(postData); var loginInfo = await CommonMethods.BookingAttendance(jsonString); if (loginInfo.Status) { IsUserExist = true; await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.youAreChecked + " " + Direction + " " + Resx.AppResources.successfully); await _navigation.PopAsync(); } else { //DependencyService.Get<IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync(loginInfo.Message); IsUserExist = false; } } } else { await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.pleaseEnableYourLocationService); } } //DependencyService.Get<IProgressBar>().Show(Resx.AppResources.pleaseWait); } catch (Exception ex) { //DependencyService.Get<IProgressBar>().Hide(); IsUserExist = false; await DependencyService.Get <IXSnack>().ShowMessageAsync(ex.Message); } finally { IsUserExist = false; IsEnabledSubmitButton = true; //DependencyService.Get<IProgressBar>().Hide(); } }