public async Task <IActionResult> GetBudget([FromRoute] int Id) { try { Service.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; Service.Token = Request.Headers["Authorization"].First().Replace("Bearer ", ""); await Service.GeneratePO(Id); var model = Service.ReadModelById(Id).Result; var rateModel = _rateService.Get().SingleOrDefault(x => x.Name == "THR"); //Get Default THR From Rate (Master Ongkos) var viewModel = Service.MapToViewModel(model); var rateViewModel = _rateService.MapToViewModel(rateModel); viewModel.Thr = rateViewModel; CostCalculationRetailBudgetPdfTemplate PdfTemplate = new CostCalculationRetailBudgetPdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = "CostCalculationRetailBudget_" + viewModel.RO + ".pdf" }); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }