public IActionResult InternshipApply(int?id, ApplyInternship fromData) { // the User is student // Make changes to AppliedInternship table. // make nortfication. try { using (GlobalDBContext _context = new GlobalDBContext()) { Internship intern = _context.Internships.Find(id); User user = _context.Users.Find(_customAuthManager.Tokens.FirstOrDefault().Value.Item3); AppliedInternship APP_Intern = new AppliedInternship(user, intern); _context.AppliedInternships.Add(APP_Intern); _context.SaveChanges(); return(View()); } } catch (Exception) { throw; } }
public IActionResult InternshipApply(int?id, ApplyInternship fromData) { // the User is student // Make changes to AppliedInternship table. // make nortfication. using (GlobalDBContext _context = new GlobalDBContext()) { string FinalCVPath; string FinalCLPath; string FinalCLString = null; // CV if (fromData.TemporaryCV != null && fromData.TemporaryCV.Length > 0) { string UserCVFolder = _env.WebRootPath + @"\uploads\UserCV\"; // File of code need to be Tested FinalCVPath = HelpersFunctions.StoreFile(UserCVFolder, fromData.TemporaryCV); } else { if (fromData.isCVExisting) { UserDocument Doc = _context.UserDocuments.Include(u => u.User).FirstOrDefault(p => p.User.UserId == _user.UserId && p.DocumentType == "CV"); FinalCVPath = Doc.DocumentPath; } else { FinalCVPath = null; } } // COVER Letter if (fromData.TemporaryCL != null && fromData.TemporaryCL.Length > 0) { string UserCLFolder = _env.WebRootPath + @"\uploads\UserCL\"; // File of code need to be Tested FinalCLPath = HelpersFunctions.StoreFile(UserCLFolder, fromData.TemporaryCL); } else { if (fromData.isCLExisting) { UserDocument Doc = _context.UserDocuments.Include(u => u.User).FirstOrDefault(p => p.User.UserId == _user.UserId && p.DocumentType == "CL"); FinalCLPath = Doc.DocumentPath; } else { FinalCLPath = null; if (fromData.isCLTextArea) { FinalCLString = fromData.WrittenCL; } else { FinalCLString = null; } } } Internship intern = _context.Internships.Find(id); // AppliedInternship constructor takes User and Internship object to create AppliedInternship object AppliedInternship APP_Intern = new AppliedInternship(_user, intern) { TempCVPath = FinalCVPath, TempCLPath = FinalCLPath, CoverLetterText = FinalCLString, EmployerStatus = "Pending" }; // Adding who applied the intership _context.AppliedInternships.Add(APP_Intern); _context.SaveChanges(); return(View()); } }