public async Task <WordDownloadLink> CreateWordDownloadLink(ObjectId documentID, ObjectId userID) { try { await wordLinksDatabase.Connect().ConfigureAwait(false); var wordDownloadLink = new WordDownloadLink(userID, documentID); await wordLinksDatabase.Insert(wordDownloadLink).ConfigureAwait(false); return(wordDownloadLink); } catch (Exception ex) when(ex.GetType() != typeof(ArgumentException)) { exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration); throw new DatabaseException("Error occured while working with the database"); } }
public async Task <IActionResult> RenderDocument([FromQuery] string downloadLinkID) { try { ObjectId downloadLinkObjectID = ObjectId.Parse(downloadLinkID); RenderSettings renderSettings = new RenderSettings() { DefaultColor = "#000000", FontFamily = "Times New Roman", DefaultTextSize = "24", }; WordDownloadLink wordDownloadLink = await linkService.GetUnusedDownloadLink(downloadLinkObjectID); await linkService.MarkWordLinkAsUsed(wordDownloadLink.ID).ConfigureAwait(false); byte[] wordFile = await wordService.Render(wordDownloadLink.DocumentID, renderSettings) .ConfigureAwait(false); return(File(wordFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=UTF-8", "word.docx")); } catch (FormatException) { return(new BadSentRequest <string>("Id was not in correct format")); } catch (ArgumentException ex) { return(new BadSentRequest <string>(ex.Message)); } catch (DatabaseException ex) { return(new InternalServerError(ex.Message)); } catch (Exception ex) { exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration); return(new InternalServerError()); } }