public ActionResult AddFile(HttpPostedFileBase UploadFile) { if (ModelState.IsValid) { if (UploadFile != null && UploadFile.ContentLength > 0) { ProspectiveStudentResume f = new ProspectiveStudentResume(); ProspectModel prospect = new ProspectModel(); using (MemoryStream ms = new MemoryStream()) { UploadFile.InputStream.CopyTo(ms); f.FileContent = ms.ToArray(); f.FileName = Path.GetFileName(UploadFile.FileName); f.ContentType = UploadFile.ContentType; f.ContentLength = UploadFile.ContentLength; //DatabaseHelper.UploadFile(f, User.Identity.Name); // here you write file into the database. You will have to write this method or just add it right here... DatabaseHelper.UploadResume(f, prospect); } TempData["Upload"] = "Thank you for uploading your resume."; return RedirectToAction("Index", "Resume"); } else { ModelState.AddModelError("", "The resume was not uploaded."); } } // If we got this far, something failed, redisplay form return View(); }
// POST: Dynamic Prospect page. public ActionResult StoreProspectPage(ProspectModel prospect) { bool edit = false; if (prospect.ProspectiveStudentTextField == null) { prospect = DatabaseHelper.GetProspectData(prospect, WebSecurity.GetUserId(User.Identity.Name)); prospect.ProspectiveStudentTextField = ""; if (DatabaseHelper.StoreProspectData(prospect, ref edit)) { TempData["Message"] = "Successfully deleted your story as a graduate student."; return RedirectToAction("Index", "GraduateStudents"); } else { TempData["Message"] = "Failed to delete your story as a graduate student."; return RedirectToAction("Index", "GraduateStudents"); } } else { ProspectModel currentProspect = new ProspectModel(); currentProspect = DatabaseHelper.GetProspectData(currentProspect, WebSecurity.GetUserId(User.Identity.Name)); string newTextField = prospect.ProspectiveStudentTextField; prospect = currentProspect; prospect.ProspectiveStudentTextField = newTextField; if (DatabaseHelper.StoreProspectData(prospect, ref edit)) { TempData["Message"] = "Successfully entered your story as a graduate student."; return RedirectToAction("Index", "GraduateStudents"); } else { TempData["Message"] = "Failed to enter your story as a graduate student."; return RedirectToAction("Index", "GraduateStudents"); } } }
public ActionResult DisplayProspect() { ProspectModel prospect = new ProspectModel(); if (DatabaseHelper.GetProspectData(prospect, -1) == null) { TempData["RegistrationMessage"] = "Prospective student registration form."; } return View(prospect); }
public ActionResult StoreProspect(ProspectModel prospect) { if (ModelState.IsValid) { bool edit = false; //This code solves the bug when registering a new student if (prospect.AccountStatus < 1) { prospect.AccountStatus = 1; } else if (prospect.AccountStatus > 4) { prospect.AccountStatus = 4; } if (prospect.ProspectiveStudentTextField == null && WebSecurity.GetUserId(prospect.EmailAddress) > 0) { ProspectModel oldProspect = new ProspectModel(); string field = DatabaseHelper.GetProspectData(oldProspect, WebSecurity.GetUserId(prospect.EmailAddress)).ProspectiveStudentTextField; prospect.ProspectiveStudentTextField = field; } if (DatabaseHelper.StoreProspectData(prospect, ref edit)) { int ID = WebSecurity.GetUserId(prospect.EmailAddress); if (edit == true && ID != WebSecurity.CurrentUserId) { TempData["Message"] = "Successfully edited the user's information."; return RedirectToAction("User", "Admin", new { ID }); } else if (edit == true) { TempData["Message"] = "Successfully edited your information."; return RedirectToAction("Manage", "Account"); } else { TempData["Message"] = "Thank you for registering to IT in the D. You will be contacted within 24-48 hours."; return RedirectToAction("ThankYou", "Home"); } } else { TempData["Message"] = "Registeration failed."; return RedirectToAction("DisplayProspect", "Account"); } } TempData["Message"] = "Registeration failed."; return RedirectToAction("DisplayProspect", "Account"); }
// POST: Resume and/or Transcript. public ActionResult StoreProspectFiles(ProspectModel prospect) { prospect = DatabaseHelper.GetProspectData(prospect, -1); var resumeUploaded = DatabaseHelper.GetProspectData(prospect, -1).ResumeFile; bool edit = false; if (resumeUploaded == null || resumeUploaded.ContentLength == 0) { TempData["Message"] = "Required files are not uploaded, please upload required files and try again."; return RedirectToAction("DisplayProspectFiles", "Account"); } else { if (DatabaseHelper.StoreProspectData(prospect, ref edit)) { if (DatabaseHelper.GetProspectData(prospect, WebSecurity.GetUserId(prospect.EmailAddress)).ResumeUploaded == "No") { TempData["Message"] = "Uploading files failed."; return RedirectToAction("DisplayProspectFiles", "Account"); } TempData["Message"] = "Successfully uploaded your files."; return RedirectToAction("DisplayProspectFiles", "Account"); } else { TempData["Message"] = "Uploading files failed."; return RedirectToAction("DisplayProspectFiles", "Account"); } } }
// GET: Dynamic Prospect page. public ActionResult DisplayProspectPage() { ProspectModel currentProspect = new ProspectModel(); currentProspect = DatabaseHelper.GetProspectData(currentProspect, WebSecurity.GetUserId(User.Identity.Name)); return View(currentProspect); }
public ActionResult DisplayProspectFiles() { ProspectModel prospect = new ProspectModel(); prospect = DatabaseHelper.GetProspectData(prospect, -1); return View(prospect); }
//==================================================================================// // Get Prospect Student information // // // // Gets the prospect student information if it is not empty. // // // // Note: If the User ID is -1 then it is being checked out by the user. // // If not then it is being checked by the admin. // //==================================================================================// public static ProspectModel GetProspectData(ProspectModel prospect, int UserId) { // If the User ID is -1 then it is being checked out by the user. We will then // get the current user ID. if (UserId == -1) { UserId = WebSecurity.CurrentUserId; } try { using (ITintheDTestTableEntities context = new ITintheDTestTableEntities()) { // Put everything we find in the database in the var variable. All the // information will be gotten using the User ID. var ExistingProspect = from r in context.ProspectiveStudent where r.UserId == UserId select r; // If the user has some information then edit it. // Otherwise return nothing. if (ExistingProspect.Count() > 0) { prospect.AccountStatus = ExistingProspect.FirstOrDefault().Status; prospect.Name = ExistingProspect.FirstOrDefault().Name; prospect.Telephone = ExistingProspect.FirstOrDefault().Telephone; prospect.EmailAddress = ExistingProspect.FirstOrDefault().EmailAddress; prospect.DesiredCareerPath = ExistingProspect.FirstOrDefault().DesiredCareerPath; prospect.Gender = ExistingProspect.FirstOrDefault().Gender; prospect.ResumeUploaded = ExistingProspect.FirstOrDefault().ResumeUploaded; prospect.TranscriptUploaded = ExistingProspect.FirstOrDefault().TranscriptUploaded; prospect.ImageUploaded = ExistingProspect.FirstOrDefault().ImageUploaded; prospect.ProspectiveStudentTextField = ExistingProspect.FirstOrDefault().ProspectiveStudentTextField; // Return the modal that is filled with information from the database. return (prospect); } else { return (null); } } } catch { return (null); } }
//==================================================================================// // Upload Prospect Student Transcript. // // // // Uploads the prospective student transcript if it is not empty. // //==================================================================================// public static bool UploadTranscript(ProspectiveStudentTranscript f, ProspectModel prospect) { int UserId = WebSecurity.GetUserId(prospect.EmailAddress); try { using (ITintheDTestTableEntities context = new ITintheDTestTableEntities()) { // Put everything we find in the database in the var variable. All the // information will be gotten using the User ID. var UserTranscript = from r in context.ProspectiveStudentTranscripts where r.UserId == UserId select r; // If the user has a transcript then update it. // Otherwise make a new row in the database. if (UserTranscript.Count() > 0) { ProspectiveStudentTranscript currentTranscript = UserTranscript.FirstOrDefault(); currentTranscript.UserId = UserId; currentTranscript.FileContent = f.FileContent; currentTranscript.FileName = f.FileName; currentTranscript.ContentLength = f.ContentLength; context.SaveChanges(); return true; } else { f.UserId = UserId; context.AddToProspectiveStudentTranscripts(f); context.SaveChanges(); return true; } } } catch (Exception) { return false; } }
//==================================================================================// // Store Prospect Student information // // // // Register the prospective student information if it is // // empty. Otherwise edit it. // // // // Note: If the edit is true then the account is being edited. // // Otherwise it is being registered. // //==================================================================================// public static bool StoreProspectData(ProspectModel prospect, ref bool edit) { int UserId = WebSecurity.GetUserId(prospect.EmailAddress); ProspectiveStudent CurrentStudent; edit = false; try { using (ITintheDTestTableEntities context = new ITintheDTestTableEntities()) { // Put everything we find in the database in the var variable. All the // information will be gotten using the User ID. var ProspectData = from r in context.ProspectiveStudent where r.UserId == UserId select r; // If the user has some information then edit it. // Otherwise register the account. if (ProspectData.Count() > 0 && UserId > 0) { edit = true; CurrentStudent = ProspectData.FirstOrDefault(); CurrentStudent.Status = prospect.AccountStatus; CurrentStudent.UserId = UserId; CurrentStudent.Name = prospect.Name; CurrentStudent.Telephone = prospect.Telephone; CurrentStudent.EmailAddress = prospect.EmailAddress; CurrentStudent.DesiredCareerPath = prospect.DesiredCareerPath; CurrentStudent.Gender = prospect.Gender; CurrentStudent.ProspectiveStudentTextField = prospect.ProspectiveStudentTextField; // Store the avatar if it is supplied. if (prospect.ImageFile != null) { UserImage image = new UserImage(); using (MemoryStream ms = new MemoryStream()) { prospect.ImageFile.InputStream.CopyTo(ms); image.FileContent = ms.ToArray(); image.FileName = Path.GetFileName(prospect.ImageFile.FileName); image.ContentType = prospect.ImageFile.ContentType; image.ContentLength = prospect.ImageFile.ContentLength; DatabaseHelper.UploadImage(image, CurrentStudent.UserId); CurrentStudent.ImageUploaded = "Yes"; prospect.ImageUploaded = "Yes"; } } // Store the new resume if it is supplied and not empty. if (prospect.ResumeFile != null && prospect.ResumeFile.ContentLength > 0) { ProspectiveStudentResume Resume = new ProspectiveStudentResume(); using (MemoryStream ms = new MemoryStream()) { prospect.ResumeFile.InputStream.CopyTo(ms); Resume.FileContent = ms.ToArray(); Resume.FileName = Path.GetFileName(prospect.ResumeFile.FileName); Resume.ContentType = prospect.ResumeFile.ContentType; Resume.ContentLength = prospect.ResumeFile.ContentLength; DatabaseHelper.UploadResume(Resume, prospect); CurrentStudent.ResumeUploaded = "Yes"; prospect.ResumeUploaded = "Yes"; } } // Store the new transcript if it is supplied and not empty. if (prospect.TranscriptFile != null && prospect.TranscriptFile.ContentLength > 0) { ProspectiveStudentTranscript Transcript = new ProspectiveStudentTranscript(); using (MemoryStream ts = new MemoryStream()) { prospect.TranscriptFile.InputStream.CopyTo(ts); Transcript.FileContent = ts.ToArray(); Transcript.FileName = Path.GetFileName(prospect.TranscriptFile.FileName); Transcript.ContentType = prospect.TranscriptFile.ContentType; Transcript.ContentLength = prospect.TranscriptFile.ContentLength; DatabaseHelper.UploadTranscript(Transcript, prospect); CurrentStudent.TranscriptUploaded = "Yes"; prospect.TranscriptUploaded = "Yes"; } } } else { CurrentStudent = new ProspectiveStudent(); CurrentStudent.Status = prospect.AccountStatus; CurrentStudent.Name = prospect.Name; CurrentStudent.Telephone = prospect.Telephone; CurrentStudent.EmailAddress = prospect.EmailAddress; CurrentStudent.DesiredCareerPath = prospect.DesiredCareerPath; CurrentStudent.Gender = prospect.Gender; CurrentStudent.ProspectiveStudentTextField = prospect.ProspectiveStudentTextField; context.AddToProspectiveStudent(CurrentStudent); } try { // If the account is edited then save changes. Otherwise register the account. if (edit == false) { WebSecurity.CreateUserAndAccount(prospect.EmailAddress, prospect.Password); // User is automatically logged in here. WebSecurity.Login(prospect.EmailAddress, prospect.Password); DatabaseHelper.AddUserToRole(prospect.EmailAddress, "Student"); CurrentStudent.UserId = WebSecurity.GetUserId(prospect.EmailAddress); // Store the avatar if it is supplied. if (prospect.ImageFile != null) { UserImage image = new UserImage(); using (MemoryStream ms = new MemoryStream()) { prospect.ImageFile.InputStream.CopyTo(ms); image.FileContent = ms.ToArray(); image.FileName = Path.GetFileName(prospect.ImageFile.FileName); image.ContentType = prospect.ImageFile.ContentType; image.ContentLength = prospect.ImageFile.ContentLength; DatabaseHelper.UploadImage(image, CurrentStudent.UserId); CurrentStudent.ImageUploaded = "Yes"; prospect.ImageUploaded = "Yes"; } } else { CurrentStudent.ImageUploaded = "No"; prospect.ImageUploaded = "No"; } // Store the resume if it is supplied and not empty. if (prospect.ResumeFile != null && prospect.ResumeFile.ContentLength > 0) { ProspectiveStudentResume Resume = new ProspectiveStudentResume(); using (MemoryStream ms = new MemoryStream()) { prospect.ResumeFile.InputStream.CopyTo(ms); Resume.FileContent = ms.ToArray(); Resume.FileName = Path.GetFileName(prospect.ResumeFile.FileName); Resume.ContentType = prospect.ResumeFile.ContentType; Resume.ContentLength = prospect.ResumeFile.ContentLength; DatabaseHelper.UploadResume(Resume, prospect); CurrentStudent.ResumeUploaded = "Yes"; prospect.ResumeUploaded = "Yes"; } } else { CurrentStudent.ResumeUploaded = "No"; prospect.ResumeUploaded = "No"; } // Store the resume if it is supplied and not empty. if (prospect.TranscriptFile != null && prospect.TranscriptFile.ContentLength > 0) { ProspectiveStudentTranscript Transcript = new ProspectiveStudentTranscript(); using (MemoryStream ts = new MemoryStream()) { prospect.TranscriptFile.InputStream.CopyTo(ts); Transcript.FileContent = ts.ToArray(); Transcript.FileName = Path.GetFileName(prospect.TranscriptFile.FileName); Transcript.ContentType = prospect.TranscriptFile.ContentType; Transcript.ContentLength = prospect.TranscriptFile.ContentLength; DatabaseHelper.UploadTranscript(Transcript, prospect); CurrentStudent.TranscriptUploaded = "Yes"; prospect.TranscriptUploaded = "Yes"; } } else { CurrentStudent.TranscriptUploaded = "No"; prospect.TranscriptUploaded = "No"; } } context.SaveChanges(); return true; } catch { return false; } } } catch { return false; } }