/// <summary> /// Executes the upload record command. /// </summary> private async Task ExecuteUploadRecordCommand(bool showConfirmation) { if (IsBusy) { return; } IsBusy = true; try { if (_haccpService.IsConnected() == false) { Page.DisplayAlertMessage(HACCPUtil.GetResourceString("EnableNetworkConnection"), HACCPUtil.GetResourceString( "YourequireanactiveInternetconnectiontoperformsomefunctionsWerecommendthatyouenableWiFiforthispurposeDatachargesmayapplyifWiFiisnotenabled")); return; } Page.ShowUploadProgress(); UploadRecordCommand.ChangeCanExecute(); if (HaccpAppSettings.SharedInstance.SiteSettings.SiteId > 0) { var proceedUpload = false; //Getting check lists and temperatures var checklists = _dataStore.GetCheckListResponses(); var temperatures = _dataStore.GetItemTemperatures(); if ((checklists == null || checklists.Count == 0) && (temperatures == null || temperatures.Count == 0)) { IsBusy = false; Page.DismissUploadProgress(); await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("Norecordsfoundtoupload")); } else if (showConfirmation && await Page.ShowConfirmAlert(HACCPUtil.GetResourceString("UploadRecords"), HACCPUtil.GetResourceString( "Alltherecordswillbeuploadedandthecheckmarkswillbecleared"))) { //confirmation alert proceedUpload = true; } else if (!showConfirmation) { proceedUpload = true; } if (proceedUpload) { if (checklists != null && (checklists.Count > 0 || temperatures.Count > 0)) { //Calling upload records method var response = await _haccpService.UploadRecords(checklists, temperatures); if (response.IsSuccess) { IsBusy = false; Page.DismissUploadProgress(); await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString( "UploadedalltherecordstoHACCPEnterpriseapplicationsuccessfully")); MessagingCenter.Send(new UploadRecordRefreshMessage(), HaccpConstant.UploadRecordRefresh); } else if (!string.IsNullOrEmpty(response.Message)) { IsBusy = false; Page.DismissUploadProgress(); await Page.ShowAlert(string.Empty, response.Message); } else { IsBusy = false; Page.DismissUploadProgress(); await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString( "AnerroroccurredwhileuploadingtherecordsPleasetryagainlater")); } } else { IsBusy = false; Page.DismissUploadProgress(); await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("Norecordsfoundtoupload")); } } } else { IsBusy = false; Page.DismissUploadProgress(); await Page.ShowAlert(HACCPUtil.GetResourceString("NoSiteInformationFound"), HACCPUtil.GetResourceString( "NositeinformationsfoundPleasetapUpdateSiteandSettingsintheWirelessTasksmenu")); } } catch (Exception ex) { Debug.WriteLine("Ooops! Something went wrong while select menu. Exception: {0}", ex); } finally { IsBusy = false; Page.DismissUploadProgress(); UploadRecordCommand.ChangeCanExecute(); } }
/// <summary> /// Executes the update site command. /// </summary> /// <returns>The update site command.</returns> private async Task ExecuteUpdateSiteCommand() { if (IsBusy) { return; } IsBusy = true; UpdateSiteCommand.ChangeCanExecute(); try { if (haccpService.IsConnected() == false) { Page.DismissPopup(); IsBusy = false; Page.DisplayAlertMessage(HACCPUtil.GetResourceString("EnableNetworkConnection"), HACCPUtil.GetResourceString( "YourequireanactiveInternetconnectiontoperformsomefunctionsWerecommendthatyouenableWiFiforthispurposeDatachargesmayapplyifWiFiisnotenabled")); return; } if (!pendingCheckListToUpload && !pendingTemperatureRecordsToUpload) { Page.ShowProgressIndicator(); var res = await haccpService.DownloadSiteAndSettings(false); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.WinPhone) { await Task.Delay(500); } if (res.IsSuccess) { Page.DismissPopup(); IsBusy = false; Page.DisplayAlertMessage("", HACCPUtil.GetResourceString("SiteandSettingsupdatedsuccessfully")); } else { Page.DismissPopup(); IsBusy = false; Page.DisplayAlertMessage("", res.Message); } } else { IsBusy = false; Page.DismissPopup(); await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("UploadRecordsPendingOnUpdateSiteSettingsMessage")); } } catch (Exception ex) { Debug.WriteLine("Ooops! Something went wrong while fetch users from server. Exception: {0}", ex); } finally { IsBusy = false; Page.DismissPopup(); UpdateSiteCommand.ChangeCanExecute(); } }