Example #1
0
        public ActionResult Download(int id)
        {
            InitiatedProjectViewModel proposal = _proposalctx.GetProposalById(id);
            string templateName = "External_Project_Proposal.docx";
            string path         = Path.Combine(environment.ContentRootPath, "~/App_Data/Generated", templateName);
            string downloadPath = string.Format(@"{0}{1}.docx", path, "-" + proposal.Title);


            DateTime currentDt = DateTime.Now;
            DateTime Sem1Start = new DateTime(currentDt.Year, 4, 20);
            DateTime Sem2Start = new DateTime(currentDt.Year, 10, 19);
            string   semester  = "";

            if (DateHelper.Between(currentDt, Sem1Start, Sem2Start))
            {
                semester = "1";
            }
            else
            {
                semester = "2";
            }
            DocX document = new DocxFormatter().GetInitiatedProjectProposal(currentDt, semester);

            document.SaveAs(path);

            using (DocX doc = DocX.Load(path))
            {
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProjectTitle", proposal.Title));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProjectOverview", proposal.ProjectOverview));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("IntroBackground", proposal.IntroBackground));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("Approach", proposal.KeyInnovationAndResearchGoals));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ComparisonMerits", proposal.ComparisonOfTheMerits));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("TargetAudience", proposal.TargetAudience));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("BusinessModel", proposal.BusinessModelAndMarketPotential));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("MainFunction", proposal.MainFunction));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProjectPlan", proposal.ProjectPlan));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("HardwareAndSoftwareRequirements", proposal.HardwareAndSoftwareRequirements));
                doc.AddCustomProperty(new Xceed.Words.NET.CustomProperty("ProblemsAndCountermeasures", proposal.ProblemsAndCountermeasures));
                doc.SaveAs(downloadPath);
            }
            return(File(downloadPath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(downloadPath)));
        }
        public ActionResult Generate(int Id)
        {
            dynamic proposal     = _proposalctx.GetProposalById(Id);
            string  templateName = "External_Project_Proposal.docx";
            string  path         = Path.Combine(environment.ContentRootPath, "/App_Data/Generated", templateName);
            string  downloadPath = string.Format(@"{0}{1}.docx", path, "-" + proposal.Title);

            if (proposal.ProjectType == "External")
            {
                DocX document = new DocxFormatter().GetExternalProjectProposalTemplate();
                document.SaveAs(path);
            }

            if (proposal.ProjectType == "Student")
            {
                DateTime currentDt = DateTime.Now;
                DateTime Sem1Start = new DateTime(currentDt.Year, 4, 20);
                DateTime Sem2Start = new DateTime(currentDt.Year, 10, 19);
                string   semester  = "";
                if (DateHelper.Between(currentDt, Sem1Start, Sem2Start))
                {
                    semester = "1";
                }
                else
                {
                    semester = "2";
                }
                DocX document = new DocxFormatter().GetInitiatedProjectProposal(currentDt, semester);
                document.SaveAs(path);
            }
            using (DocX doc = DocX.Load(path))
            {
                //if (doc == null)
                //{
                //DocX document = new DocxFormatter().GetExternalProjectProposalTemplate();
                //document.SaveAs(path);
                //}
                doc.AddCustomProperty(new CustomProperty("ProjectTitle", proposal.Title));
                if (proposal.ProjectType == "External")
                {
                    doc.AddCustomProperty(new CustomProperty("CompanyName", proposal.CompanyName));
                    doc.AddCustomProperty(new CustomProperty("Address", proposal.Address));
                    doc.AddCustomProperty(new CustomProperty("Tel", proposal.Tel));
                    doc.AddCustomProperty(new CustomProperty("Fax", proposal.Fax));
                    doc.AddCustomProperty(new CustomProperty("Email", proposal.Email));
                    doc.AddCustomProperty(new CustomProperty("LiaisonOfficer", proposal.LiaisonOfficer));
                    string WillingToSponsor = "No";
                    if (proposal.WillingToSponsor == true)
                    {
                        WillingToSponsor = "Yes";
                    }
                    doc.AddCustomProperty(new CustomProperty("WillingToSponsor", WillingToSponsor));

                    doc.AddCustomProperty(new CustomProperty("ProjectAims", proposal.Aims));
                    doc.AddCustomProperty(new CustomProperty("ProjectObjectives", proposal.Objectives));
                    doc.AddCustomProperty(new CustomProperty("ProjectSchedule", proposal.Schedule));
                    doc.AddCustomProperty(new CustomProperty("ProjectAudience", proposal.TargetAudience));
                    doc.AddCustomProperty(new CustomProperty("ProjectMainFunction", proposal.MainFunction));
                    doc.AddCustomProperty(new CustomProperty("ProjectRequirements", proposal.HardwareAndSoftwareConfiguration));
                }

                if (proposal.ProjectType == "Student")
                {
                    doc.AddCustomProperty(new CustomProperty("ProjectOverview", proposal.ProjectOverview));
                    doc.AddCustomProperty(new CustomProperty("IntroBackground", proposal.IntroBackground));
                    doc.AddCustomProperty(new CustomProperty("Approach", proposal.KeyInnovationAndResearchGoals));
                    doc.AddCustomProperty(new CustomProperty("ComparisonMerits", proposal.ComparisonOfTheMerits));
                    doc.AddCustomProperty(new CustomProperty("TargetAudience", proposal.TargetAudience));
                    doc.AddCustomProperty(new CustomProperty("BusinessModel", proposal.BusinessModelAndMarketPotential));
                    doc.AddCustomProperty(new CustomProperty("MainFunction", proposal.MainFunction));
                    doc.AddCustomProperty(new CustomProperty("ProjectPlan", proposal.ProjectPlan));
                    doc.AddCustomProperty(new CustomProperty("HardwareAndSoftwareRequirements", proposal.HardwareAndSoftwareRequirements));
                    doc.AddCustomProperty(new CustomProperty("ProblemsAndCountermeasures", proposal.ProblemsAndCountermeasures));
                }

                doc.SaveAs(downloadPath);
            }
            return(File(downloadPath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(downloadPath)));
        }