public JsonResult MakeInvoice([FromBody] Invoice _oInvoice) { try { FileResult fileResult; var output = context.Invoices .Include(i => i.Order) .Include(i => i.ClientMaster) .Include(i => i.ClientMaster.StateMaster) .Include(i => i.ClientMaster.DistrictMaster) .Include(i => i.ClientMaster.CityMaster) .Include(i => i.ProductMaster) .Where(w => w.InvoiceID == _oInvoice.InvoiceID && w.IsDraft == false) .FirstOrDefault(); if (output != null) { output.InvoiceDetails = context.InvoiceDetails .Include(i => i.InventoryMaster) .Include(i => i.InventoryMaster.DeviceMaster) .Include(i => i.InventoryMaster.SpareMaster) .Include(i => i.InvoiceHeader) .Where(w => w.InvoiceID == _oInvoice.InvoiceID) .ToList(); if (output.InvoiceDetails != null) { var company = context.Companys.FirstOrDefault(); CommonLogic commonLogic = new CommonLogic(); string body = commonLogic.CreateInvoiceBody(_hostingEnvironment.WebRootPath, output, company); fileResult = commonLogic.ConvertHtmlToPdf(body, output.InvoiceNumber); } else { fileResult = null; } } else { fileResult = null; } return(Json(fileResult)); } catch (Exception ex) { throw; } finally { context = null; } }