internal async Task Initilize() { try { UserDialogs.Instance.ShowLoading(); var result = await NewsServices.GetAllNews(); var list = new List <NewsModel>(); if (result.Success) { int i = 2; foreach (var item in result.data) { item.IssueDate = String.IsNullOrEmpty(item.IssueDate) ? "" : Convert.ToDateTime(item.IssueDate).ToString("dd MMM, yyyy"); //item.ImageURL = (ApiBase.HttpClientBase.BaseUrl + "NewsImages/" + item.ImageURL); //var response = await ReportsService.Download(ApiBase.HttpClientBase.BaseUrl + "NewsImages/" + item.ImageURL); var response = await ReportsService.DownloadFileBytes(ApiBase.HttpClientBase.BaseUrl + "api/News/GetNewsImage?newsimage=" + item.ImageURL); if (response.FileContents.Length > 1) { item.ImageData = ImageSource.FromStream(() => new MemoryStream(response.FileContents)); } item.IssueDate = "Published on " + item.IssueDate; if (item.IsApproved) { //Background color scheme - even odd. if ((i % 2) == 0) { item.BackgroundColor = "#6CAAD3"; } else { item.BackgroundColor = "#D3C1A0"; } i++; list.Add(item); } } NewsList = new ObservableCollection <NewsModel>(list); } else { await UserDialogs.Instance.AlertAsync(result.Message); } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); } UserDialogs.Instance.HideLoading(); }
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); } }