public long AddApplicant(Applicant applicant) { try { var duplicates = _context.Applicants.Count(m => m.EmailAdress.Trim() == applicant.EmailAdress.Trim()); if (duplicates > 0) { //Applicant is already added return(-3); } //Determine the next Id applicant.Id = _context.Applicants.Select(x => x.Id).Max() + 1; //insert Applicant _context.Applicants.Add(applicant); _context.SaveChanges(); return(applicant.Id); } catch (Exception e) { //Log Error return(0); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new ApplicantDBContext(serviceProvider.GetRequiredService <DbContextOptions <ApplicantDBContext> >())) { // Look for any board games already in database. if (context.Applicants.Any()) { return; // Database has been seeded } else { //else seed a sample applicant into the database context.Applicants.Add( new Applicant { Id = 1, Name = "Tobias", FamilyName = "Bodmann", Address = "Friedhofstraße 11, 93142 Maxhütte-Haidhof, Germany", EmailAdress = "*****@*****.**", Age = 28, CountryOfOrigin = "Germany", Hired = true }); context.SaveChanges(); } } }
public ActionResult getJobAndEducationInformation(String Title, String[] groupselect, String[] groupselect2) { //This needs to be changed ApplicantDBContext Applicantdb = new ApplicantDBContext(); Applicant applicant = Applicantdb.Applicants.Find(User.Identity.Name); applicant.Education = string.Join("|", groupselect); applicant.IntrestedJobs = string.Join("|", groupselect2); Applicantdb.Entry(applicant).State = EntityState.Modified; Applicantdb.SaveChanges(); return(RedirectToAction("Index", "Applicant", new { area = "" })); }
public ActionResult Create([Bind(Include = "email,firstName,lastName,phoneNumber,Education,IntrestedJobs")] Applicant applicant, HttpPostedFileBase file, HttpPostedFileBase photo) { String resumeExtention = ""; String picExtention = ""; //Check to see if user uploaded a resume if (file == null) { return(RedirectToAction("CreateWithError", new { inValidFile = "RESUME MISSING" })); } else { resumeExtention = System.IO.Path.GetExtension(file.FileName); } if (photo == null) { return(RedirectToAction("CreateWithError", new { inValidFile = "IMAGE MISSING" })); } else { picExtention = System.IO.Path.GetExtension(photo.FileName); } //Check to see if the resume is a pdf if (!resumeExtention.Equals(".pdf")) { return(RedirectToAction("CreateWithError", new { inValidFile = "RESUME INVALID" })); } //Check to see if the image has valid format bool validImage = IsValidImageExtension(picExtention); if (validImage == false) { return(RedirectToAction("CreateWithError", new { inValidFile = "IMAGE" })); } //If files are fine then continue string pathToCreateResume = "~/FolderOfApplicants/" + applicant.email + "/Resume/"; string pathToCreateProfile = "~/FolderOfApplicants/" + applicant.email + "/Profile/"; //string pathToCreate = "~/Applicant/Resume/" + applicant.email; Directory.CreateDirectory(Server.MapPath(pathToCreateResume)); Directory.CreateDirectory(Server.MapPath(pathToCreateProfile)); String serverPath = "~/FolderOfApplicants/" + applicant.email + "/Resume/" + "Resume.pdf"; string path = Server.MapPath("~/FolderOfApplicants/" + applicant.email + "/Resume/" + "Resume.pdf"); file.SaveAs(path); applicant.Path2Resume = serverPath; //Only adds a picture id user has added one if (!picExtention.Equals("")) { String imageExtention = photo.ContentType; imageExtention = imageExtention.Replace("image/", ""); //resize profile picture String serverPath2 = "~/FolderOfApplicants/" + applicant.email + "/Profile/" + "ProfilePic." + imageExtention; string path2 = Server.MapPath("~/FolderOfApplicants/" + applicant.email + "/Profile/" + "ProfilePic." + imageExtention); photo.SaveAs(path2); applicant.Path2Photo = serverPath2; //WebImage profilePic = new WebImage(photo.InputStream); //profilePic.Resize(350, 350); //profilePic.Save(path2); //applicant.Path2Photo = path2;//adds path to image } else { applicant.Path2Photo = "";//puts an empty path to profile image if the user has not givin a profile image } ViewBag.Path = path; if (ModelState.IsValid) { db.Applicants.Add(applicant); db.SaveChanges(); ///return RedirectToAction("Index"); return(RedirectToAction("getJobAndEducationInformation", "Job")); } return(View(applicant)); }