public async Task <IHttpActionResult> ExportPatients([FromBody] object body) { try { string query = body.ToString(); // IEnumerable<PatientDTO> patients = await _manager.GetPatients(query); byte[] file = await _manager.ExportPatients(query); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(file) }; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Export" + DateTime.Now.Year.ToString() + ".csv" }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv"); var response = ResponseMessage(result); return(response); } catch (Exception ex) { return(InternalServerError(ex)); } }