private void UpdateApplicantSkills(string[] selectedOptions, Applicant applicantToUpdate) { if (selectedOptions == null) { applicantToUpdate.ApplicantSkills = new List <ApplicantSkill>(); return; } var selectedOptionsHS = new HashSet <string>(selectedOptions); var applicantOptionsHS = new HashSet <int> (applicantToUpdate.ApplicantSkills.Select(c => c.SkillID));//IDs of the currently selected skills foreach (var option in _context.Skills) { if (selectedOptionsHS.Contains(option.ID.ToString())) { if (!applicantOptionsHS.Contains(option.ID)) { applicantToUpdate.ApplicantSkills.Add(new ApplicantSkill { ApplicantID = applicantToUpdate.ID, SkillID = option.ID }); } } else { if (applicantOptionsHS.Contains(option.ID)) { ApplicantSkill conditionToRemove = applicantToUpdate.ApplicantSkills.SingleOrDefault(c => c.SkillID == option.ID); _context.Remove(conditionToRemove); } } } }
public async Task <IActionResult> Create([Bind("ID,FirstName,MiddleName,LastName,SIN,Phone,eMail,RetrainingProgramID")] Applicant applicant, string[] selectedOptions, IFormFile thePicture, List <IFormFile> theFiles) { //Get the URL with the last filter, sort and page parameters ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Applicants"); try { //Add the selected skills if (selectedOptions != null) { foreach (var skill in selectedOptions) { var skillToAdd = new ApplicantSkill { ApplicantID = applicant.ID, SkillID = int.Parse(skill) }; applicant.ApplicantSkills.Add(skillToAdd); } } if (ModelState.IsValid) { await AddPicture(applicant, thePicture); await AddDocumentsAsync(applicant, theFiles); _context.Add(applicant); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { applicant.ID })); } } catch (RetryLimitExceededException /* dex */) { ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator."); } catch (DbUpdateException dex) { if (dex.GetBaseException().Message.Contains("UNIQUE constraint failed")) { ModelState.AddModelError("", "Unable to save changes. Remember, you cannot have duplicate eMail addresses."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } PopulateDropDownLists(applicant); return(View(applicant)); }
public ApplicantDTO GetDataProfileByID(int empID) { ApplicantDTO listData = new ApplicantDTO(); ApplicantProfile applicantProfile = new ApplicantProfile(); ApplicantSkill applicantSkill = new ApplicantSkill(); List <ApplicantEduHistory> applicantEduHis = new List <ApplicantEduHistory>(); List <ApplicantWorkingHistory> applicantWorkingHistories = new List <ApplicantWorkingHistory>(); List <ApplicantTrainingHistory> applicantTrainingHistories = new List <ApplicantTrainingHistory>(); List <ApplicantSkillLanguage> applicantSkillLanguages = new List <ApplicantSkillLanguage>(); List <ApplicantRef> applicantRefs = new List <ApplicantRef>(); applicantProfile = Context.ApplicantProfile.Where(x => x.Empid == empID).FirstOrDefault(); applicantSkill = Context.ApplicantSkill.Where(x => x.Empid == empID).FirstOrDefault(); applicantEduHis = Context.ApplicantEduHistory.Where(x => x.Empid == empID).ToList(); applicantWorkingHistories = Context.ApplicantWorkingHistory.Where(x => x.Empid == empID).ToList(); applicantTrainingHistories = Context.ApplicantTrainingHistory.Where(x => x.Empid == empID).ToList(); applicantSkillLanguages = Context.ApplicantSkillLanguage.Where(x => x.Empid == empID).ToList(); applicantRefs = Context.ApplicantRef.Where(x => x.Empid == empID).ToList(); listData.ApplicantProfile.TitelnameTh = applicantProfile.TitlenameTh; listData.ApplicantProfile.FirstnameTh = string.IsNullOrEmpty(applicantProfile.FirstnameTh) ? "" : applicantProfile.FirstnameTh; listData.ApplicantProfile.LastnameTh = string.IsNullOrEmpty(applicantProfile.LastnameTh) ? "" : applicantProfile.LastnameTh; listData.ApplicantProfile.TitelnameEn = applicantProfile.TitlenameEn; listData.ApplicantProfile.FirstnameEn = string.IsNullOrEmpty(applicantProfile.FirstnameEn) ? "" : applicantProfile.FirstnameEn; listData.ApplicantProfile.LastnameEn = string.IsNullOrEmpty(applicantProfile.LastnameEn) ? "" : applicantProfile.LastnameEn; listData.ApplicantProfile.Birthday = applicantProfile.Birthday; listData.ApplicantProfile.Age = applicantProfile.Age != null ? applicantProfile.Age : 0; listData.ApplicantProfile.IdCard = string.IsNullOrEmpty(applicantProfile.IdCard) ? "" : applicantProfile.IdCard; listData.ApplicantProfile.Status = string.IsNullOrEmpty(applicantProfile.Status) ? "" : applicantProfile.Status; listData.ApplicantProfile.Height = applicantProfile.Height != null ? applicantProfile.Height : 0; listData.ApplicantProfile.Weight = applicantProfile.Weight != null ? applicantProfile.Weight : 0; listData.ApplicantProfile.Nationality = string.IsNullOrEmpty(applicantProfile.Nationality) ? "" : applicantProfile.Nationality; listData.ApplicantProfile.Religion = string.IsNullOrEmpty(applicantProfile.Religion) ? "" : applicantProfile.Religion; listData.ApplicantProfile.Tel = string.IsNullOrEmpty(applicantProfile.Tel) ? "" : applicantProfile.Tel; listData.ApplicantProfile.Email = string.IsNullOrEmpty(applicantProfile.Email) ? "" : applicantProfile.Email; listData.ApplicantProfile.LineID = applicantProfile.Lineid; listData.ApplicantProfile.Address = string.IsNullOrEmpty(applicantProfile.Address) ? "" : applicantProfile.Address; listData.ApplicantProfile.Province = string.IsNullOrEmpty(applicantProfile.Province) ? "" : applicantProfile.Province; listData.ApplicantProfile.District = string.IsNullOrEmpty(applicantProfile.District) ? "" : applicantProfile.District; listData.ApplicantProfile.SubDistrict = string.IsNullOrEmpty(applicantProfile.SubDistrict) ? "" : applicantProfile.SubDistrict; listData.ApplicantProfile.PostalCode = int.Parse(applicantProfile.PostalCode); listData.ApplicantProfile.Stay = applicantProfile.Stay; listData.ApplicantProfile.ImgPath = string.IsNullOrEmpty(applicantProfile.ImgPath) ? "" : applicantProfile.ImgPath; listData.ApplicantProfile.Position = string.IsNullOrEmpty(applicantProfile.Position) ? "" : applicantProfile.Position; listData.ApplicantProfile.Salary = string.IsNullOrEmpty(applicantProfile.Salary) ? "" : applicantProfile.Salary; listData.ApplicantProfile.TypeEmployee = string.IsNullOrEmpty(applicantProfile.TypeEmployee) ? "" : applicantProfile.TypeEmployee; listData.ApplicantSkill.TypingTh = applicantSkill.TypingTh != null ? applicantSkill.TypingTh : 0; listData.ApplicantSkill.TypingEn = applicantSkill.TypingEn != null ? applicantSkill.TypingEn : 0; listData.ApplicantSkill.Special1 = string.IsNullOrEmpty(applicantSkill.Special1) ? "" : applicantSkill.Special1; listData.ApplicantSkill.Special2 = string.IsNullOrEmpty(applicantSkill.Special2) ? "" : applicantSkill.Special2; listData.ApplicantSkill.Special3 = string.IsNullOrEmpty(applicantSkill.Special3) ? "" : applicantSkill.Special3; listData.ApplicantSkill.Special4 = string.IsNullOrEmpty(applicantSkill.Special4) ? "" : applicantSkill.Special4; listData.ApplicantProfile.CrBy = string.IsNullOrEmpty(applicantProfile.CrBy) ? "" : applicantProfile.CrBy; listData.ApplicantProfile.CrDate = applicantProfile.CrDate; listData.ApplicantProfile.Gender = string.IsNullOrEmpty(applicantProfile.Gender) ? "" : applicantProfile.Gender; listData.ApplicantProfile.StatusApplicant = string.IsNullOrEmpty(applicantProfile.StatusApplicant) ? "" : applicantProfile.StatusApplicant; listData.ApplicantProfile.FirstnameTh = string.IsNullOrEmpty(applicantProfile.FirstnameTh) ? "" : applicantProfile.FirstnameTh; listData.ApplicantProfile.UpdBy = string.IsNullOrEmpty(applicantProfile.UpdBy) ? "" : applicantProfile.UpdBy; listData.ApplicantProfile.UpdDate = applicantProfile.UpdDate; foreach (ApplicantEduHistory eduHistory in applicantEduHis) { if (eduHistory != null) { ApplicantEduHistoryDTO eduHistoryDTO = new ApplicantEduHistoryDTO(); eduHistoryDTO.Education = eduHistory.Education; eduHistoryDTO.SchoolName = eduHistory.SchoolName; eduHistoryDTO.Faculty = eduHistory.Faculty; eduHistoryDTO.Major = eduHistory.Major; eduHistoryDTO.GradYear = DateTime.Parse("01/01/" + eduHistory.GradYear); eduHistoryDTO.Gpa = eduHistory.Gpa; listData.ApplicantEduHistories.Add(eduHistoryDTO); } else { listData.ApplicantEduHistories = null; } } foreach (ApplicantWorkingHistory workingHistory in applicantWorkingHistories) { if (workingHistory != null) { ApplicantWorkingHistoryDTO workingHistoryDTO = new ApplicantWorkingHistoryDTO(); workingHistoryDTO.StartDate = workingHistory.StartDate; workingHistoryDTO.EndDate = workingHistory.EndDate; workingHistoryDTO.CompanyName = workingHistory.CompanyName; workingHistoryDTO.CompanyAddress = workingHistory.CompanyAddress; workingHistoryDTO.Position = workingHistory.Position; workingHistoryDTO.Salary = workingHistory.Salary; listData.ApplicantWorkingHistories.Add(workingHistoryDTO); } else { listData.ApplicantWorkingHistories = null; } } foreach (ApplicantTrainingHistory trainingHistory in applicantTrainingHistories) { if (trainingHistory != null) { ApplicantTrainingHistoryDTO trainingHistoryDTO = new ApplicantTrainingHistoryDTO(); trainingHistoryDTO.StartDate = trainingHistory.StartDate; trainingHistoryDTO.EndDate = trainingHistory.EndDate; trainingHistoryDTO.TrainingName = trainingHistory.TrainingName; trainingHistoryDTO.CourseName = trainingHistory.CourseName; trainingHistoryDTO.Certificate = trainingHistory.Certificate; listData.ApplicantTrainingHistories.Add(trainingHistoryDTO); } else { listData.ApplicantTrainingHistories = null; } } foreach (ApplicantSkillLanguage skillLanguage in applicantSkillLanguages) { if (skillLanguage != null) { ApplicantSkillLanguageDTO skillLanguageDTO = new ApplicantSkillLanguageDTO(); skillLanguageDTO.Language = skillLanguage.Language; skillLanguageDTO.LanguageSpeak = skillLanguage.LanguageSpeak; skillLanguageDTO.LanguageRead = skillLanguage.LanguageRead; skillLanguageDTO.LanguageWrite = skillLanguage.LanguageWrite; listData.ApplicantSkillLanguages.Add(skillLanguageDTO); } else { listData.ApplicantTrainingHistories = null; } } foreach (ApplicantRef Ref in applicantRefs) { if (Ref != null) { ApplicantRefDTO RefDTO = new ApplicantRefDTO(); RefDTO.RefName = Ref.RefName; RefDTO.RefPosition = Ref.RefPosition; RefDTO.RefTel = Ref.RefTel; listData.ApplicantRef.Add(RefDTO); } else { listData.ApplicantRef = null; } } return(listData); }
public async Task <string> SaveApplicant(ApplicantDTO data) { using (var dbContextTransaction = Context.Database.BeginTransaction()) { try { int empID = Context.ApplicantProfile.Max(i => i.Empid) + 1; // EMDID DateTime dateTime = DateTime.Now; #region // ########## Table APPLICANT_PROFILE ########## // ApplicantProfile applicant = new ApplicantProfile(); // EMDID applicant.Empid = empID; // รูปโปรไฟล์ applicant.ImgPath = data.ApplicantProfile.ImgPath; // ลักษณะงานที่ต้องการ applicant.Position = data.ApplicantProfile.Position; applicant.Salary = data.ApplicantProfile.Salary; applicant.TypeEmployee = data.ApplicantProfile.TypeEmployee; // ข้อมูลส่วนตัว applicant.TitlenameTh = data.ApplicantProfile.TitelnameTh; applicant.FirstnameTh = data.ApplicantProfile.FirstnameTh; applicant.LastnameTh = data.ApplicantProfile.LastnameTh; applicant.TitlenameEn = data.ApplicantProfile.TitelnameEn; applicant.FirstnameEn = data.ApplicantProfile.FirstnameEn; applicant.LastnameEn = data.ApplicantProfile.LastnameEn; applicant.Birthday = data.ApplicantProfile.Birthday; applicant.Age = data.ApplicantProfile.Age; applicant.Gender = data.ApplicantProfile.Gender; applicant.Status = data.ApplicantProfile.Status; applicant.IdCard = data.ApplicantProfile.IdCard; applicant.Religion = data.ApplicantProfile.Religion; applicant.Nationality = data.ApplicantProfile.Nationality; applicant.Height = data.ApplicantProfile.Height; applicant.Weight = data.ApplicantProfile.Weight; // ข้อมูลการติดต่อ applicant.Tel = data.ApplicantProfile.Tel; applicant.Email = data.ApplicantProfile.Email; applicant.Lineid = data.ApplicantProfile.LineID; // ข้อมูลที่อยู่ปัจจุบัน applicant.Address = data.ApplicantProfile.Address; applicant.Province = data.ApplicantProfile.Province; applicant.District = data.ApplicantProfile.District; applicant.SubDistrict = data.ApplicantProfile.SubDistrict; applicant.PostalCode = data.ApplicantProfile.PostalCode.ToString(); // Status applicant.StatusApplicant = "New"; applicant.CrBy = "Coop";; applicant.CrDate = dateTime; applicant.UpdBy = "Coop"; applicant.UpdDate = dateTime; Context.ApplicantProfile.Add(applicant); #endregion #region // ########## Table APPLICANT_EDU_HISTORY ########## // int eduNo = 0; foreach (ApplicantEduHistoryDTO edu in data.ApplicantEduHistories) { ApplicantEduHistory applicantEdu = new ApplicantEduHistory(); eduNo++; // EMPID applicantEdu.Empid = empID; // ประวัติการศึกษา applicantEdu.No = eduNo; applicantEdu.Education = edu.Education; applicantEdu.SchoolName = edu.SchoolName; applicantEdu.Faculty = edu.Faculty; applicantEdu.Major = edu.Major; applicantEdu.GradYear = edu.GradYear.Year.ToString(); applicantEdu.Gpa = edu.Gpa; applicantEdu.CrBy = "Coop"; applicantEdu.CrDate = dateTime; applicantEdu.UpdBy = "Coop"; applicantEdu.UpdDate = dateTime; Context.ApplicantEduHistory.Add(applicantEdu); } #endregion #region // ########## Table APPLICANT_WORKING_HISTORY ########## // int workNo = 0; foreach (ApplicantWorkingHistoryDTO work in data.ApplicantWorkingHistories) { ApplicantWorkingHistory applicantWork = new ApplicantWorkingHistory(); workNo++; // EMPID applicantWork.Empid = empID; // ประวัติการทำงาน/ฝึกงาน applicantWork.No = workNo; applicantWork.StartDate = work.StartDate; applicantWork.EndDate = work.EndDate; applicantWork.CompanyName = work.CompanyName; applicantWork.CompanyAddress = work.CompanyAddress; applicantWork.Position = work.Position; applicantWork.Salary = work.Salary; applicantWork.CrBy = "Coop"; applicantWork.CrDate = dateTime; applicantWork.UpdBy = "Coop"; applicantWork.UpdDate = dateTime; Context.ApplicantWorkingHistory.Add(applicantWork); } #endregion #region // ########## Table APPLICANT_TRAINING_HISTORY ########## // int trainingNo = 0; foreach (ApplicantTrainingHistoryDTO training in data.ApplicantTrainingHistories) { ApplicantTrainingHistory applicantTraining = new ApplicantTrainingHistory(); trainingNo++; // EMPID applicantTraining.Empid = empID; // ประวัติการฝึกอบรม/ประกาศนียบัตร applicantTraining.No = trainingNo; applicantTraining.StartDate = training.StartDate; applicantTraining.EndDate = training.EndDate; applicantTraining.TrainingName = training.TrainingName; applicantTraining.CourseName = training.CourseName; applicantTraining.Certificate = training.Certificate; applicantTraining.CrBy = "Coop"; applicantTraining.CrDate = dateTime; applicantTraining.UpdBy = "Coop"; applicantTraining.UpdDate = dateTime; Context.ApplicantTrainingHistory.Add(applicantTraining); } #endregion #region // ########## Table APPLICANT_SKILL_LANGUAGE ########## // int languageNo = 0; foreach (ApplicantSkillLanguageDTO language in data.ApplicantSkillLanguages) { ApplicantSkillLanguage applicantLanguage = new ApplicantSkillLanguage(); languageNo++; // EMPID applicantLanguage.Empid = empID; // ความสามารถทางภาษา applicantLanguage.No = languageNo; applicantLanguage.Language = language.Language; applicantLanguage.LanguageSpeak = language.LanguageSpeak; applicantLanguage.LanguageRead = language.LanguageRead; applicantLanguage.LanguageWrite = language.LanguageWrite; applicantLanguage.CrBy = "Coop"; applicantLanguage.CrDate = dateTime; applicantLanguage.UpdBy = "Coop"; applicantLanguage.UpdDate = dateTime; Context.ApplicantSkillLanguage.Add(applicantLanguage); } #endregion #region // ########## Table APPLICANT_SKILL ########## // ApplicantSkill applicantSkill = new ApplicantSkill(); // EMPID applicantSkill.Empid = empID; // พิมพ์ดีด applicantSkill.TypingTh = data.ApplicantSkill.TypingTh; applicantSkill.TypingEn = data.ApplicantSkill.TypingEn; // กรุณาเรียงลำดับความสามารถด้านคอมพิวเตอร์ (เช่นภาษา/โปรแกรม/ระบบปฏิบัติการอื่นๆ) applicantSkill.Special1 = data.ApplicantSkill.Special1; applicantSkill.Special2 = data.ApplicantSkill.Special2; applicantSkill.Special3 = data.ApplicantSkill.Special3; applicantSkill.Special4 = data.ApplicantSkill.Special4; applicantSkill.CrBy = "Coop"; applicantSkill.CrDate = dateTime; applicantSkill.UpdBy = "Coop"; applicantSkill.UpdDate = dateTime; Context.ApplicantSkill.Add(applicantSkill); #endregion #region // ########## Table APPLICANT_REF ########## // int refNo = 0; foreach (ApplicantRefDTO refs in data.ApplicantRef) { ApplicantRef applicantRef = new ApplicantRef(); refNo++; // EMPID applicantRef.Empid = empID; // รายชื่อบุคคลอ้างอิง ซึ่งมิใช่ญาติหรือผู้ว่าจ้าง ซึ่งบริษัทฯ สามารถสอบประวัติท่านได้ applicantRef.No = refNo; applicantRef.RefName = refs.RefName; applicantRef.RefPosition = refs.RefPosition; applicantRef.RefTel = refs.RefTel; applicantRef.CrBy = "Coop"; applicantRef.CrDate = dateTime; applicantRef.UpdBy = "Coop"; applicantRef.UpdDate = dateTime; Context.ApplicantRef.Add(applicantRef); } #endregion Context.SaveChanges(); dbContextTransaction.Commit(); return(empID.ToString()); } catch (Exception ex) { dbContextTransaction.Rollback(); return("error"); } } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new JobBankContext( serviceProvider.GetRequiredService <DbContextOptions <JobBankContext> >())) { //Prepare Random Random random = new Random(); //Seed Occupations string[] occupations = new string[] { "Teacher", "Nurse", "Building Contractor", "Electrician", "Lawyer", "Doctor" }; if (!context.Occupations.Any()) { foreach (string s in occupations) { Occupation o = new Occupation { Title = s }; context.Occupations.Add(o); } context.SaveChanges(); } //Create collection of the primary keys of the Occupations int[] OccupationIDs = context.Occupations.Select(s => s.ID).ToArray(); int occupationIDCount = OccupationIDs.Count(); //Create 5 notes from Bacon ipsum string[] baconNotes = new string[] { "Bacon ipsum dolor amet meatball corned beef kevin, alcatra kielbasa biltong drumstick strip steak spare ribs swine. Pastrami shank swine leberkas bresaola, prosciutto frankfurter porchetta ham hock short ribs short loin andouille alcatra. Andouille shank meatball pig venison shankle ground round sausage kielbasa. Chicken pig meatloaf fatback leberkas venison tri-tip burgdoggen tail chuck sausage kevin shank biltong brisket.", "Sirloin shank t-bone capicola strip steak salami, hamburger kielbasa burgdoggen jerky swine andouille rump picanha. Sirloin porchetta ribeye fatback, meatball leberkas swine pancetta beef shoulder pastrami capicola salami chicken. Bacon cow corned beef pastrami venison biltong frankfurter short ribs chicken beef. Burgdoggen shank pig, ground round brisket tail beef ribs turkey spare ribs tenderloin shankle ham rump. Doner alcatra pork chop leberkas spare ribs hamburger t-bone. Boudin filet mignon bacon andouille, shankle pork t-bone landjaeger. Rump pork loin bresaola prosciutto pancetta venison, cow flank sirloin sausage.", "Porchetta pork belly swine filet mignon jowl turducken salami boudin pastrami jerky spare ribs short ribs sausage andouille. Turducken flank ribeye boudin corned beef burgdoggen. Prosciutto pancetta sirloin rump shankle ball tip filet mignon corned beef frankfurter biltong drumstick chicken swine bacon shank. Buffalo kevin andouille porchetta short ribs cow, ham hock pork belly drumstick pastrami capicola picanha venison.", "Picanha andouille salami, porchetta beef ribs t-bone drumstick. Frankfurter tail landjaeger, shank kevin pig drumstick beef bresaola cow. Corned beef pork belly tri-tip, ham drumstick hamburger swine spare ribs short loin cupim flank tongue beef filet mignon cow. Ham hock chicken turducken doner brisket. Strip steak cow beef, kielbasa leberkas swine tongue bacon burgdoggen beef ribs pork chop tenderloin.", "Kielbasa porchetta shoulder boudin, pork strip steak brisket prosciutto t-bone tail. Doner pork loin pork ribeye, drumstick brisket biltong boudin burgdoggen t-bone frankfurter. Flank burgdoggen doner, boudin porchetta andouille landjaeger ham hock capicola pork chop bacon. Landjaeger turducken ribeye leberkas pork loin corned beef. Corned beef turducken landjaeger pig bresaola t-bone bacon andouille meatball beef ribs doner. T-bone fatback cupim chuck beef ribs shank tail strip steak bacon." }; //Seed Positions string[] positions = new string[] { "Emergency Room Nurse", "Kindergarten Teacher", "Marine Electrician", "Divorce Lawyer", "Obstetrician", "Gofer", "Lackey" }; if (!context.Positions.Any()) { foreach (string s in positions) { Position p = new Position { Name = s, Description = baconNotes[random.Next(5)], Salary = random.Next(240000, 29800000) / 100m, OccupationID = OccupationIDs[random.Next(occupationIDCount)] }; context.Positions.Add(p); } context.SaveChanges(); } //Create collection of the primary keys of the Positions int[] PositionIDs = context.Positions.Select(s => s.ID).ToArray(); int positionIDCount = PositionIDs.Count(); //Seed Postings //Add a StartDate to every second Posting if (!context.Postings.Any()) { int toggle = 0; //Used to alternate for (int i = 0; i < positionIDCount; i++) { Posting p = new Posting() { NumberOpen = random.Next(11), ClosingDate = DateTime.Today.AddDays(random.Next(60)), PositionID = PositionIDs[i] }; toggle++; if (toggle % 2 == 0)//Every second Posting gets a StartDate { p.StartDate = p.ClosingDate.AddDays(random.Next(30)); } context.Postings.Add(p); } context.SaveChanges(); } //Seed Programs string[] programs = new string[] { "First Aid,", "CPR", "Computer Programming,", "Life Skills", "Carpentry" }; if (!context.RetrainingPrograms.Any()) { foreach (string s in programs) { RetrainingProgram p = new RetrainingProgram { Name = s }; context.RetrainingPrograms.Add(p); } context.SaveChanges(); } //Seed Skills string[] skills = new string[] { "Communications Skills", "Organizational Skills", "Writing", "Customer Service", "Microsoft Excel", "Problem Solving", "Planning", "Microsoft Office", "Research", "Detail Oriented", "Project Management", "Building Effective Relationships", "Computer Skills", "QA and Control", "Troubleshooting" }; if (!context.Skills.Any()) { foreach (string s in skills) { Skill o = new Skill { Name = s }; context.Skills.Add(o); } context.SaveChanges(); } //Create collection of the primary keys of the Skills int[] SkillIDs = context.Skills.Select(s => s.ID).ToArray(); int skillIDCount = SkillIDs.Count(); //Seed Applicants string[] firstNames = new string[] { "Woodstock", "Sally", "Violet", "Charlie", "Lucy", "Linus", "Franklin", "Marcie", "Schroeder", "Fred", "Barney", "Wilma", "Betty" }; string[] lastNames = new string[] { "Hightower", "Wizard", "Kingfisher", "Prometheus", "Broomspun", "Shooter", "Chuckles", "Stovell", "Jones", "Bloggs", "Flintstone", "Rubble", "Brown", "Smith", "Daniel" }; if (!context.Applicants.Any()) { List <Applicant> applicants = new List <Applicant>(); foreach (string lastName in lastNames) { foreach (string firstname in firstNames) { //Construct some Applicant details Applicant a = new Applicant() { FirstName = firstname, LastName = lastName, MiddleName = lastName[1].ToString().ToUpper(), SIN = random.Next(213214131, 989898989).ToString(), eMail = (firstname.Substring(0, 2) + lastName + random.Next(11, 111).ToString() + "@outlook.com").ToLower(), Phone = Convert.ToInt64(random.Next(2, 10).ToString() + random.Next(213214131, 989898989).ToString()) }; context.Applicants.Add(a); try { //Could be a duplicate email context.SaveChanges(); } catch (Exception) { //so skip it and go on to the next } } } } //Create collection of the primary keys of the Postings int[] PostingIDs = context.Postings.Select(s => s.ID).ToArray(); int postingIDCount = PostingIDs.Count(); //Create collection of the primary keys of the Applicants int[] ApplicantIDs = context.Applicants.Select(s => s.ID).ToArray(); int applicantIDCount = ApplicantIDs.Count(); //Seed Applications - The Loaded Intersection //Have every second Applicant applly to one posting if (!context.Applications.Any()) { for (int i = 0; i < applicantIDCount; i++) { if (i % 2 == 0)//Every second Applicant { Application a = new Application() { ApplicantID = ApplicantIDs[i], PostingID = PostingIDs[random.Next(postingIDCount)], Comments = baconNotes[random.Next(5)] }; context.Applications.Add(a); } } context.SaveChanges(); } //Seed Skills for Applicants - The No Load Intersection //Have every second Applicant get a couple of skills if (!context.ApplicantSkills.Any()) { for (int i = 0; i < applicantIDCount; i++) { if (i % 2 == 0)//Every second Applicant { //We will add 2 skills int skillID = random.Next(skillIDCount - 1); ApplicantSkill a = new ApplicantSkill() { ApplicantID = ApplicantIDs[i], SkillID = SkillIDs[skillID] }; context.ApplicantSkills.Add(a); ApplicantSkill a1 = new ApplicantSkill() { ApplicantID = ApplicantIDs[i], SkillID = SkillIDs[skillID + 1] }; context.ApplicantSkills.Add(a1); } } context.SaveChanges(); } //Project Part 3A Seed Skills for Positions - The No Load Intersection //Have every second Position get a couple of skills if (!context.PositionSkills.Any()) { for (int i = 0; i < positionIDCount; i++) { if (i % 2 == 0)//Every second Position { //We will add 2 skills int skillID = random.Next(skillIDCount - 1); PositionSkill a = new PositionSkill() { PositionID = PositionIDs[i], SkillID = SkillIDs[skillID] }; context.PositionSkills.Add(a); PositionSkill a1 = new PositionSkill() { PositionID = PositionIDs[i], SkillID = SkillIDs[skillID + 1] }; context.PositionSkills.Add(a1); } } context.SaveChanges(); } } }