Example #1
0
        public IHttpActionResult ExportAsCsv(int?lang)
        {
            var dictionaryService = new DictionaryDataService(ApplicationContext);

            var csv = dictionaryService.GetAllDictionaryItemsSorted().ToCsv(lang);

            string fileName = "dictionary-" + DateTime.Today.ToString("yyyyMMdd") + ".csv";

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(Encoding.UTF8.GetBytes(csv))
            };

            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = fileName,
            };

            result.Content.Headers.ContentLength = Encoding.UTF8.GetByteCount(csv);
            result.Content.Headers.ContentType   = new MediaTypeHeaderValue("text/csv");

            var response = ResponseMessage(result);

            return(response);
        }
 /// <summary>
 /// Instantiates the controller and configures the dictionary data service
 /// </summary>
 public DictionaryEditorController()
 {
     this.dictionaryService = new DictionaryDataService(ApplicationContext);
 }