Example #1
0
        private async Task PrintAsync()
        {
            try
            {
                if (_trainingDays == null)
                {
                    await _userDialog.AlertAsync(Translation.Get(TRS.IMPOSSIBLE_ACTION), Translation.Get(TRS.PRINT), Translation.Get(TRS.OK));
                }
                else
                {
                    bool withImages = await _userDialog.ConfirmAsync(Translation.Get(TRS.PRINT_WITH_IMAGES) + " ?", Translation.Get(TRS.PRINT), Translation.Get(TRS.YES), Translation.Get(TRS.NO));

                    var trainingDayReport = new TrainingDayReport()
                    {
                        UserId        = this.UserId,
                        Year          = this.Year,
                        WeekOfYear    = this.WeekOfYear,
                        DayOfWeek     = this.DayOfWeek,
                        DisplayImages = withImages,
                        TrainingDayId = null
                    };
                    var memoryStream = await ReportWebService.TrainingDayReportAsync(trainingDayReport);

                    if (memoryStream != null)
                    {
                        var    pdfName     = Guid.NewGuid().ToString() + ".pdf";
                        var    fileManager = Resolver.Resolve <IFileManager>();
                        string pdfPath     = Path.Combine(AppTools.TempDirectory, pdfName);

                        bool writeSuccess = await fileManager.WriteBinaryFileAsync(pdfPath, memoryStream);

                        if (writeSuccess)
                        {
                            if (Device.OS == TargetPlatform.Android)
                            {
                                Resolver.Resolve <IAndroidAPI> ().OpenPdf(pdfPath);
                            }
                            else if (Device.OS == TargetPlatform.iOS)
                            {
                                await WebViewViewModel.ShowAsync(pdfPath, this);
                            }
                        }
                    }
                }
            }
            catch (Exception except)
            {
                ILogger.Instance.Error("Unable to print trainingDay", except);
            }
        }
Example #2
0
        public IActionResult TrainingDayReport([FromBody] TrainingDayReport trainingDayReport)
        {
            try
            {
                string outputFileName = string.Format("TrainingDayReport_{0}_{1}_{2}_{3}.pdf", trainingDayReport.Year, trainingDayReport.WeekOfYear,
                                                      trainingDayReport.DayOfWeek,
                                                      trainingDayReport.TrainingDayId.HasValue ? trainingDayReport.TrainingDayId.Value.ToString() : "all");
                string reportPath = System.IO.Path.Combine("trainingDay", trainingDayReport.UserId);
                string reportUrl  = string.Format("http://localhost:5000/Report/TrainingDayReport/Index?userId={0}&year={1}&weekOfYear={2}&dayOfWeek={3}&trainingDayId{4}&displayImages={5}&culture={6}&userIdViewer={7}",
                                                  trainingDayReport.UserId, trainingDayReport.Year, trainingDayReport.WeekOfYear,
                                                  trainingDayReport.DayOfWeek,
                                                  trainingDayReport.TrainingDayId.HasValue ? trainingDayReport.TrainingDayId.Value.ToString() : "null", trainingDayReport.DisplayImages,
                                                  CultureInfo.CurrentUICulture.ToString(), SessionUserId);
                return(RedirectToAction("Pdf", "Report", new { area = "Report", reportPath = reportPath, reportUrl = reportUrl, outputFileName = outputFileName }));

                //return new OkObjectResult(result); // BodyExercise
            }
            catch (Exception exception)
            {
                return(BadRequest(new WebApiException("Error", exception)));
            }
        }
 /// <summary>
 /// Crée un report pdf
 /// </summary>
 /// <param name="trainingDayReport">report demandé</param>
 /// <returns>Url du rapport</returns>
 public static async Task <MemoryStream> TrainingDayReportAsync(TrainingDayReport trainingDayReport)
 {
     return(await HttpConnector.Instance.PostAsync <TrainingDayReport, MemoryStream>("Api/Report/TrainingDayReport", trainingDayReport));
 }