From 248292fce2299a516dcfc9d0d0eff5576fa77ca6 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 25 Jun 2020 13:36:53 +0000 Subject: [PATCH] --- .../Controllers/TranslationController.cs | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/server/AyaNova/Controllers/TranslationController.cs b/server/AyaNova/Controllers/TranslationController.cs index 527c824b..9bca0d5e 100644 --- a/server/AyaNova/Controllers/TranslationController.cs +++ b/server/AyaNova/Controllers/TranslationController.cs @@ -48,7 +48,7 @@ namespace AyaNova.Api.Controllers serverState = apiServerState; } - + /// @@ -243,6 +243,56 @@ namespace AyaNova.Api.Controllers } + + + + + + + /// + /// Get Translation all values + /// + /// + /// A single Translation and it's values + [HttpGet("download/{id}")] + public async Task DownloadTranslation([FromRoute] long id) + { + if (serverState.IsClosed) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + + + if (!ModelState.IsValid) + { + return BadRequest(new ApiErrorResponse(ModelState)); + } + + //Instantiate the business object handler + TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext); + + var o = await biz.GetAsync(id); + + //turn into correct format and then send as file + if (o == null) + { + return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); + } + var asText = Newtonsoft.Json.JsonConvert.SerializeObject(o, Newtonsoft.Json.Formatting.None); + var bytes = System.Text.Encoding.UTF8.GetBytes(asText); + var file = new FileContentResult(bytes, "application/octet-stream"); + file.FileDownloadName = o.Name + ".json"; + return file; + + } + + + + + + + + + + #if (DEBUG) public class TranslationCoverageInfo {