public HttpResponseMessage GetPdf([FromUri] string name, [FromUri] DateTime?fromDate = null, [FromUri] DateTime?toDate = null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); if (!String.IsNullOrEmpty(name)) { switch (name) { case "leads": { //responseData.data = _reportService.Get var reportName = "PotentialCustomerReport_" + DateTime.Now.ToString("dd'-'MM'-'yyyy") + ".pdf"; var pdfManager = new PdfManager(reportName); var fileName = pdfManager.GenerateLeadsReport().fileName; var results = _fileService.GetFile(fileName); if (results.file != null) { response.StatusCode = HttpStatusCode.OK; response.Content = results.file; response.Content.Headers.ContentType = new MediaTypeHeaderValue(results.mimeType); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = results.fileName }; } else { response.StatusCode = HttpStatusCode.Gone; ResponseFormat responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.SOMETHING_WRONG; var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); } break; } case "accounts": { //responseData.data = _reportService.Get var reportName = "CustomerReport_" + DateTime.Now.ToString("dd'-'MM'-'yyyy") + ".pdf"; var pdfManager = new PdfManager(reportName); var fileName = pdfManager.GenerateAccountsReport().fileName; var results = _fileService.GetFile(fileName); if (results.file != null) { response.StatusCode = HttpStatusCode.OK; response.Content = results.file; response.Content.Headers.ContentType = new MediaTypeHeaderValue(results.mimeType); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = results.fileName }; } else { response.StatusCode = HttpStatusCode.Gone; ResponseFormat responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.SOMETHING_WRONG; var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); } break; } case "deals": { var reportName = "DealsReport_" + DateTime.Now.ToString("dd'-'MM'-'yyyy") + ".pdf"; var pdfManager = new PdfManager(reportName); var fileName = pdfManager.GenerateDealsReport(fromDate, toDate).fileName; var results = _fileService.GetFile(fileName); if (results.file != null) { response.StatusCode = HttpStatusCode.OK; response.Content = results.file; response.Content.Headers.ContentType = new MediaTypeHeaderValue(results.mimeType); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = results.fileName }; } else { response.StatusCode = HttpStatusCode.Gone; ResponseFormat responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.SOMETHING_WRONG; var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); } break; } case "revenue": { var reportName = "RevenueReport_" + DateTime.Now.ToString("dd'-'MM'-'yyyy") + ".pdf"; var pdfManager = new PdfManager(reportName); var fileName = pdfManager.GenerateRevenueReport(fromDate, toDate).fileName; var results = _fileService.GetFile(fileName); if (results.file != null) { response.StatusCode = HttpStatusCode.OK; response.Content = results.file; response.Content.Headers.ContentType = new MediaTypeHeaderValue(results.mimeType); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = results.fileName }; } else { response.StatusCode = HttpStatusCode.Gone; ResponseFormat responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.SOMETHING_WRONG; var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); } break; } case "campaigns": { //responseData.data = _reportService.Get var reportName = "CampaignReport_" + DateTime.Now.ToString("dd'-'MM'-'yyyy") + ".pdf"; var pdfManager = new PdfManager(reportName); var fileName = pdfManager.GenerateCampaignsReport().fileName; var results = _fileService.GetFile(fileName); if (results.file != null) { response.StatusCode = HttpStatusCode.OK; response.Content = results.file; response.Content.Headers.ContentType = new MediaTypeHeaderValue(results.mimeType); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = results.fileName }; } else { response.StatusCode = HttpStatusCode.Gone; ResponseFormat responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.SOMETHING_WRONG; var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); } break; } default: break; } } else { response.StatusCode = HttpStatusCode.BadRequest; ResponseFormat responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.INVALID_BODY; var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); } return(response); }