internal async void ShowReport(ReportsModel reportsModel) { try { var res = LabResultListComplete.Where(x => x.ASREF == reportsModel.ASREF && x.ASYEAR == reportsModel.ASYEAR).FirstOrDefault(); if (res != null) { res.IsViewed = true; } App.TabbedPage.viewModel.LabCount--; App.TabbedPage.viewModel.LabCountVisibility = App.TabbedPage.viewModel.LabCount >= 0; Task.Run(async() => { var result = await ReportsService.SetSeenReports(Constants.UserProfile.Role, reportsModel.ASBRCH, reportsModel.ASYEAR, reportsModel.ASREF, "Y"); }); } catch (Exception ex) { } try { if (!String.IsNullOrEmpty(reportsModel.ASREF)) { var name = $"{reportsModel.ASBRCH}_{reportsModel.ASYEAR}_{reportsModel.ASREF}"; var loader = await MaterialDialog.Instance.LoadingDialogAsync("Loading"); var result = await ReportsService.GetAttachmentsList(name); await loader.DismissAsync(); if (result.Success) { var list = result.data.ToList(); list.Insert(0, name + ".pdf"); var newList = new List <string>(); foreach (var item in list) { var newIndex = list.IndexOf(item); if (newIndex == 0) { newList.Add("Main Report"); } else { newList.Add($"Attachment {newIndex}"); } } var index = await ShowActionSheet("Select", newList); if (index >= 0) { if (index >= 1) { var nativeFileHandler = DependencyService.Get <INativeFileHandler>(); //var url = $"{ApiBase.HttpClientBase.BaseUrl}/Attachments/{list[index]}"; var loader1 = await MaterialDialog.Instance.LoadingDialogAsync("Loading"); //var bytes = await ReportsService.Download($"/Attachments/{list[index]}");// DownloadPDFAsync(url); //var response = await ReportsService.DownloadFileBytes(ApiBase.HttpClientBase.BaseUrl + $"api/Reports/GetReportAttachment?filename=X_19_19804_01.PDF"); var response = await ReportsService.DownloadFileBytes(ApiBase.HttpClientBase.BaseUrl + $"api/Reports/GetReportAttachment?filename={list[index]}"); await loader1.DismissAsync(); if (response.FileContents != null && response.FileContents.Length > 1) { await App.Current.MainPage.Navigation.PushAsync(new PdfPage(response.FileContents)); nativeFileHandler.SaveFile(list[index], response.FileContents); // await MaterialDialog.Instance.AlertAsync("Report downloaded in your local storage"); } else { await MaterialDialog.Instance.AlertAsync("Cannot download report due to server issue"); } } else { //var url = $"{ApiBase.HttpClientBase.BaseUrl}/api/Reports/DownloadReport?refernce={reportsModel.ASREF}"; var loader1 = await MaterialDialog.Instance.LoadingDialogAsync("Loading"); var pdfModel = await ReportsService.DownloadBytes($"api/Reports/DownloadReportBytes?brch={reportsModel.ASBRCH}&year={reportsModel.ASYEAR}&refernce={reportsModel.ASREF}"); await loader1.DismissAsync(); if (pdfModel.FileContents != null && pdfModel.FileContents.Length > 1) { //var pdfByte = HtmlByteToPdfByte(pdfModel.FileContents); //await App.Current.MainPage.Navigation.PushAsync(new PdfPage(pdfByte)); await App.Current.MainPage.Navigation.PushAsync(new BrowserPage(pdfModel.FileContents)); } else { await MaterialDialog.Instance.AlertAsync("Report not available"); } } } } else { var url = $"api/Reports/DownloadReportBytes?brch={reportsModel.ASBRCH}&year={reportsModel.ASYEAR}&refernce={reportsModel.ASREF}"; var loader1 = await MaterialDialog.Instance.LoadingDialogAsync("Loading"); var pdfModel = await ReportsService.DownloadBytes(url); await loader1.DismissAsync(); if (pdfModel.FileContents != null && pdfModel.FileContents.Length > 1) { //var pdfByte = HtmlByteToPdfByte(pdfModel.FileContents); //await App.Current.MainPage.Navigation.PushAsync(new PdfPage(pdfByte)); await App.Current.MainPage.Navigation.PushAsync(new BrowserPage(pdfModel.FileContents)); } else { await MaterialDialog.Instance.AlertAsync("Report not available"); } } } else { await MaterialDialog.Instance.AlertAsync("Report not available"); } } catch (Exception ex) { await MaterialDialog.Instance.AlertAsync(ex.Message); } }