public async Task <IActionResult> Export(ExportInputModel model) { var viewedItems = (await _netflixViewedItemRepository.GetByGuidAsync(model.Identifier)) ?.OrderByDescending(x => x.PlaybackDateTime); if (!viewedItems?.Any() ?? true) { return(RedirectToAction("NoResults")); } var fileExporter = _netlNetflixViewedItemsFileExporters.FirstOrDefault(x => x.IsFormatSupported(model.Format)); if (fileExporter == null) { return(BadRequest($"Unknown format: {model.Format}")); } fileExporter.ViewedItems = _mapper.Map <IEnumerable <Models.ImportExportModels.NetflixViewedItem> >(viewedItems); return(File(fileExporter.GetFileContent(), fileExporter.GetMimeType(), fileExporter.GetFileName())); }
public byte[] ProcessWordDocument(ExportInputModel inputModel) { using (MemoryStream mem = new MemoryStream()) { // Create Document using (WordprocessingDocument wordDocument = WordprocessingDocument.Create( mem, WordprocessingDocumentType.Document)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure and add some text. mainPart.Document = new Document(); Body docBody = mainPart.Document.AppendChild(new Body()); var html = new StringBuilder(); html.AppendLine("<html>"); html.AppendLine("<h1 style=\"text-align: center; display: block; color: midnightblue\">Workout Plan</h1>"); html.AppendLine("<ol>"); foreach (var day in inputModel.Days) { html.AppendLine($"<li style=\"font-size: 25px; \">{day.Day}</li>"); html.AppendLine($"<ul style=\"display: block\">"); foreach (var exercise in day.Exercises) { if (exercise.BodyPart.ToLower() == "cardio") { html.AppendLine($"<li style=\"font-size: 20px; list-style-type: bullet\">" + $"{exercise.Name}({exercise.BodyPart}) - {exercise.MinReps} - {exercise.MaxReps} minutes ({exercise.Difficulty})</li>"); } else { html.AppendLine($"<li style=\"font-size: 20px; list-style-type: bullet\">" + $"{exercise.Name}({exercise.BodyPart}) - {exercise.MinReps} - {exercise.MaxReps} reps ({exercise.Difficulty})</li>"); } } html.AppendLine($"</ul>"); } html.AppendLine("</ol>"); html.AppendLine("</html>"); // Add your docx content here // Create a memory stream with the HTML required MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(html.ToString())); // Create an alternative format import part on the MainDocumentPart AlternativeFormatImportPart altformatImportPart = wordDocument.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html); // Add the HTML data into the alternative format import part altformatImportPart.FeedData(ms); // Create a new altChunk and link it to the id of the AlternativeFormatImportPart AltChunk altChunk = new AltChunk(); altChunk.Id = wordDocument.MainDocumentPart.GetIdOfPart(altformatImportPart); // add the altChunk to the document wordDocument.MainDocumentPart.Document.Body.Append(altChunk); wordDocument.Save(); } return(mem.ToArray()); } }