// GET: Employees/GenerateCV/5 public ActionResult GenerateCV(int?id) { Employee employee = db.Employees.Find(id); string profilePicUrl = ""; //getting the picture ready Common.CreateSkillTemplates(employee); if (employee.File != null) { profilePicUrl = Utils.Common.SaveImgLocally(db, employee.File.FileID.ToString()); ViewBag.profilePicUrl = profilePicUrl; } else { ViewBag.profilePicUrl = System.Web.HttpContext.Current.Server.MapPath("~/Content/Pictures/"); } //getting the projects for this employee List <Task> tasks = db.Tasks.Include(x => x.Sprint).Where(x => x.EmployeeID == employee.EmployeeID).ToList(); List <Project> projects = (from t in db.Tasks join s in db.Sprints on t.SprintID equals s.SprintID join p in db.Projects on s.ProjectID equals p.ProjectID where t.EmployeeID == employee.EmployeeID select p).Distinct().ToList(); foreach (Project p in projects) { //selecting the correct tasks for each project List <Task> projectTasks = tasks.Where(x => x.Sprint != null && x.Sprint.ProjectID == p.ProjectID).ToList(); foreach (Task t in projectTasks) { if (t.Estimation.HasValue) { p.ManHoursEffort += t.Estimation.Value; } } } ViewBag.projects = projects; ViewBag.headertext = "CV: " + employee.FirstName + " " + employee.LastName; //initialize baseUrl string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; ViewBag.baseUrl = baseUrl; //initializing CV employee.SkillLevelsList = employee.SkillLevels.ToList(); ViewBag.SkillCategories = db.SkillCategories.OrderByDescending(x => x.Skills.Count).ToList(); //generating the main body string generatedPDFHtml = ViewRenderer.RenderView("~/Views/Employees/PdfCVGenerator.cshtml", employee, ControllerContext); //generating the header string headertext = ViewRenderer.RenderView("~/Views/Employees/PdfCVHeader.cshtml", employee, ControllerContext); byte[] pdfBuffer = PdfGenerator.ConvertHtmlToPDF(generatedPDFHtml, headertext); //delete the temporary generated file if (!String.IsNullOrEmpty(profilePicUrl)) { Utils.Common.DeleteLocalImage(profilePicUrl); } //sending the pdf file to download this.HttpContext.Response.ContentType = "application/pdf"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + "EmployeeCV.pdf"); this.HttpContext.Response.BinaryWrite(pdfBuffer); this.HttpContext.Response.Flush(); this.HttpContext.Response.Close(); return(View(employee)); }