public FileStreamResult Get([FromQuery] int?beforeThisYear, int?afterThisYear, int?authorId, bool?isBestSeller, int docType = 1) { if (string.IsNullOrEmpty(Request.QueryString.Value)) { throw new ArgumentNullException("QueryParams", "You should provide at least one query parameter"); } var dictionary = Request.QueryString.Value.Replace("?", "").Split('&') .ToDictionary(x => x.Split('=')[0], x => x.Split('=')[1]).Where(s => !string.IsNullOrEmpty(s.Value)); if (!dictionary.Any()) { throw new ArgumentNullException("QueryParams", "You should provide at least one query parameter"); } ; var ls = _bookService.Get(beforeThisYear, afterThisYear, authorId, isBestSeller); switch (docType) { case (int)DocumentType.Word: ICreatorService wordReportCreator = new WordReportCreator(); return(wordReportCreator.CreateReport(ls)); case (int)DocumentType.Pdf: ICreatorService pdfReportCreator = new PdfReportCreator(); return(pdfReportCreator.CreateReport(ls)); default: throw new InvalidOperationException("Select a valid document type for creating report"); } }
public void CreateReport() { if (_graph == null) { MessageBox.Show("Nie wygenerowano grafu.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); return; } var dialog = new SaveFileDialog { Filter = "Plik tekstowy|*.txt|Plik PDF|*.pdf" }; if (dialog.ShowDialog() != true) { return; } IReportCreator reportCreator = null; switch (Path.GetExtension(dialog.FileName).ToLower()) { case ".pdf": reportCreator = new PdfReportCreator(_graph, new DfsAlgorithm(), _graphImageProvider, new GreedyVertexColoringAlgorithm()); break; default: reportCreator = new TextReportCreator(_graph, new DfsAlgorithm(), new GreedyVertexColoringAlgorithm()); break; } using (var outputStream = new FileStream(dialog.FileName, FileMode.OpenOrCreate)) { outputStream.Position = 0; outputStream.SetLength(0); reportCreator.Create(outputStream); } }