public ActionResult History()
        {
            var schooldata = context.ApplyColleges.Select(a => a).ToList();

            ViewData["History"] = schooldata;
            List <ApplyCollege> history = new List <ApplyCollege>();
            Student_Profile     student = Session["StudentProfile"] as Student_Profile;
            var x = schooldata.Count();

            for (int i = 0; i < x; i++)
            {
                if (schooldata.ElementAtOrDefault(i).StudentId == student.StudentId)
                {
                    ApplyCollege his = new ApplyCollege();
                    his.ApplyCollegeId = schooldata.ElementAtOrDefault(i).ApplyCollegeId;
                    his.StudentId      = schooldata.ElementAtOrDefault(i).StudentId;
                    his.SchoolName     = schooldata.ElementAtOrDefault(i).SchoolName;
                    his.CollegeEmail   = schooldata.ElementAtOrDefault(i).CollegeEmail;
                    his.CourseApplied  = schooldata.ElementAtOrDefault(i).CourseApplied;
                    his.Semester       = schooldata.ElementAtOrDefault(i).Semester;
                    his.DateApplied    = schooldata.ElementAtOrDefault(i).DateApplied;
                    history.Add(his);
                }
            }
            return(View(history));
        }
        public ActionResult ApplyCollege()
        {
            var schooldata = context.SchoolDatas.Select(a => a).ToList();

            ViewData["SchoolName"] = schooldata;
            ApplyCollege    data    = new ApplyCollege();
            Student_Profile student = Session["StudentProfile"] as Student_Profile;

            data.StudentId = student.StudentId;
            return(View(data));
        }
        public ActionResult ApplyCollege(ApplyCollege AppliedCollege, FormCollection form1)
        {
            AppliedCollege.DateApplied          = DateTime.Now;
            context.Entry(AppliedCollege).State = System.Data.EntityState.Added;
            context.SaveChanges();
            var Filepath  = Server.MapPath("pdf") + "\\" + "First PDF document.pdf";
            var Filepath2 = Server.MapPath("pdf") + "\\";

            //Process for creating pdf
            Student_Profile student = Session["StudentProfile"] as Student_Profile;

            string[] filescollection = Directory.GetFiles(Filepath2, "First PDF document.pdf", SearchOption.AllDirectories);
            foreach (var item1 in filescollection)
            {
                System.IO.File.Delete(item1);
            }

            System.IO.FileStream fs = new FileStream(Filepath, FileMode.Create);
            var       doc1          = new Document();
            PdfWriter writer        = PdfWriter.GetInstance(doc1, fs);

            doc1.Open();
            doc1.Add(new Paragraph("STUDENT APPLICATION FORM "));
            PdfPTable table = new PdfPTable(2);
            PdfPCell  cell  = new PdfPCell(new Phrase("Student Data"));

            cell.Colspan             = 2;
            cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
            table.AddCell(cell);
            table.AddCell("First Name");
            table.AddCell(student.FirstName);
            table.AddCell(" Middle Name");
            table.AddCell(student.MiddleName);
            table.AddCell("Last Name");
            table.AddCell(student.LastName);
            table.AddCell("Phone Number");
            table.AddCell(student.PhoneNumber);
            table.AddCell("DateofBirth ");
            table.AddCell(student.DateOfBirth.Value.ToShortDateString());
            table.AddCell("Gender ");
            table.AddCell(student.Gender);
            table.AddCell("SSN");
            table.AddCell(student.SSN);
            table.AddCell("Email");
            table.AddCell(student.Email);
            table.AddCell("Country of Birth");
            table.AddCell(student.CountryofBirth);



            PdfPCell cell1 = new PdfPCell(new Phrase("Address Informtion"));

            cell1.Colspan             = 2;
            cell1.HorizontalAlignment = 1;
            table.AddCell(cell1);
            table.AddCell("Street Address");
            table.AddCell(student.AddressStudents.ElementAtOrDefault(0).AptStreet);
            table.AddCell("City");
            table.AddCell(student.AddressStudents.ElementAtOrDefault(0).City);
            table.AddCell("State");
            table.AddCell(student.AddressStudents.ElementAtOrDefault(0).State);
            table.AddCell("ZipCode");
            table.AddCell(student.AddressStudents.ElementAtOrDefault(0).ZipCode);
            table.AddCell("Country");
            table.AddCell(student.AddressStudents.ElementAtOrDefault(0).Country);
            table.AddCell("Address Type");
            var x = student.AddressStudents.ElementAtOrDefault(0).Type;

            if (x == "1")
            {
                table.AddCell("Permanent");
            }
            else
            {
                table.AddCell("Temporary");
            }



            PdfPCell cell2 = new PdfPCell(new Phrase("Citizenship Informtion"));

            cell2.Colspan             = 2;
            cell2.HorizontalAlignment = 1;
            table.AddCell(cell2);
            table.AddCell("Country of Citizenship");
            table.AddCell(student.CitizenShipInfoes.ElementAtOrDefault(0).CountryOfCitizenship);
            table.AddCell("Ethnicity");
            table.AddCell(student.CitizenShipInfoes.ElementAtOrDefault(0).Ethnicity);
            table.AddCell("I20 required ");
            table.AddCell(student.CitizenShipInfoes.ElementAtOrDefault(0).I20Required);
            table.AddCell("Visa Status ");
            table.AddCell(student.CitizenShipInfoes.ElementAtOrDefault(0).VisaStatus);
            table.AddCell("Current Location ");
            table.AddCell(student.CitizenShipInfoes.ElementAtOrDefault(0).CurrentLocation);
            table.AddCell("Vetran Status ");
            table.AddCell(student.CitizenShipInfoes.ElementAtOrDefault(0).VeteranStatus);



            PdfPCell cell3 = new PdfPCell(new Phrase("Information regarding course enrollement"));

            cell3.Colspan             = 2;
            cell3.HorizontalAlignment = 1;
            table.AddCell(cell3);
            table.AddCell("Admission Type");
            table.AddCell(student.AcademicInfoes.ElementAtOrDefault(0).AdmissionType);
            table.AddCell("Semester");
            table.AddCell(student.AcademicInfoes.ElementAtOrDefault(0).Semester);
            table.AddCell("Application Year");
            table.AddCell(student.AcademicInfoes.ElementAtOrDefault(0).ApplicationYear);
            table.AddCell("Major");
            table.AddCell(student.AcademicInfoes.ElementAtOrDefault(0).Major);


            PdfPTable table4 = new PdfPTable(3);
            PdfPCell  cell4  = new PdfPCell(new Phrase("Previous School information"));

            cell4.Colspan             = 2;
            cell4.HorizontalAlignment = 1;
            table.AddCell(cell4);
            table.AddCell("Previous School Name");
            table.AddCell(student.PreviousSchoolInfoes.ElementAtOrDefault(0).SchoolName);
            table.AddCell("Previous School Start Date");
            table.AddCell(student.PreviousSchoolInfoes.ElementAtOrDefault(0).DateFrom.Value.ToShortDateString());
            table.AddCell("Previous School End Date");
            table.AddCell(student.PreviousSchoolInfoes.ElementAtOrDefault(0).DateTo.Value.ToShortDateString());
            table.AddCell("Degree");
            table.AddCell(student.PreviousSchoolInfoes.ElementAtOrDefault(0).DegreeName);
            table.AddCell("Major");
            table.AddCell(student.PreviousSchoolInfoes.ElementAtOrDefault(0).Major);
            table.AddCell("School Address");
            table.AddCell(student.PreviousSchoolInfoes.ElementAtOrDefault(0).Address);

            PdfPCell cell5 = new PdfPCell(new Phrase("Exam Information"));

            cell5.Colspan             = 2;
            cell5.HorizontalAlignment = 1;
            table.AddCell(cell5);
            table.AddCell("GRE TAKEN ?");
            var y = student.ExamInfoes.ElementAtOrDefault(0).ExamType;

            if (y == null)
            {
                table.AddCell("NO");
            }
            else
            {
                table.AddCell("YES");
                table.AddCell("GRE SCORE");
                table.AddCell(student.ExamInfoes.ElementAtOrDefault(0).Score);
                table.AddCell("GRE DATE");
                table.AddCell(student.ExamInfoes.ElementAtOrDefault(0).DateOfExam.Value.ToShortDateString());
            }
            table.AddCell("TOEFL TAKEN ?");
            var z = student.ExamInfoes.ElementAtOrDefault(1).ExamType;

            if (z == null)
            {
                table.AddCell("NO");
            }
            else
            {
                table.AddCell("YES");
                table.AddCell("TOEFL SCORE");
                table.AddCell(student.ExamInfoes.ElementAtOrDefault(1).Score);
                table.AddCell("TOEFL DATE");
                table.AddCell(student.ExamInfoes.ElementAtOrDefault(1).DateOfExam.Value.ToShortDateString());
            }
            table.AddCell("IELTS TAKEN ?");
            var p = student.ExamInfoes.ElementAtOrDefault(2).ExamType;

            if (p == null)
            {
                table.AddCell("NO");
            }
            else
            {
                table.AddCell("YES");
                table.AddCell("IELTS SCORE");
                table.AddCell(student.ExamInfoes.ElementAtOrDefault(2).Score);
                table.AddCell("IELTS DATE");
                table.AddCell(student.ExamInfoes.ElementAtOrDefault(2).DateOfExam.Value.ToShortDateString());
            }


            PdfPCell cell6 = new PdfPCell(new Phrase("Work Experience"));

            cell6.Colspan             = 2;
            cell6.HorizontalAlignment = 1;
            table.AddCell(cell6);
            table.AddCell("Work Experience");
            var r = student.WorkInfoes.ElementAtOrDefault(0).CompanyName;

            if (r == null)
            {
                table.AddCell("NO");
            }
            else
            {
                table.AddCell("YES");
                table.AddCell("Company name");
                table.AddCell(student.WorkInfoes.ElementAtOrDefault(0).CompanyName);
                table.AddCell("Start date");
                table.AddCell(student.WorkInfoes.ElementAtOrDefault(0).FromDate.Value.ToShortDateString());
                table.AddCell("End date");
                table.AddCell(student.WorkInfoes.ElementAtOrDefault(0).ToDate.Value.ToShortDateString());
                table.AddCell("Description");
                table.AddCell(student.WorkInfoes.ElementAtOrDefault(0).Description);
                table.AddCell("Achievement");
                table.AddCell(student.WorkInfoes.ElementAtOrDefault(0).Achievement);
            }

            doc1.Add(table);
            doc1.Close();

            EmailHelper cs     = new EmailHelper();
            string      result = cs.SendContactUsEmail(student.StudentId, 0, Filepath);

            //String Schoolemail = form1["CollegeEmail"].ToString();
            //String Senderemail = "*****@*****.**";



            return(RedirectToAction("StudentHomePage", new { str = "Your application has been submitted to" + AppliedCollege.SchoolName + " sucessfully!! " }));
        }