public ReferenceInfo(string name) { this.InfoType = "ReferenceInfo"; Reference reference = new ReferenceRepo().GetReference(name); this.ID = reference.ID; this.Name = reference.Name; this.ArticleID = reference.ArticleID; this.Title = new ArticleRepo().GetArticleWithId(ArticleID).Title; }
public void Sync() { // 1. Sync information _logs.ForEach((log) => { User user = new UserRepo().GetUserByName(log.Username); switch (log.Type) { case "Create": // Create article if (log.Info.InfoType == "ArticleInfo") { ArticleInfo local_info = log.Info as ArticleInfo; Article article = new Article(local_info); ArticleRepo repo = new ArticleRepo(); // Edge case: Article already exists if (repo.GetArticleWithTitle(article.Title) != null) { string mismatch = $"Article '{local_info.Title}' already exists."; _mismatches.Add(mismatch); return; } // 1. Add article to database repo.SaveArticle(article, user); // 2. Copy file string fileName = repo.GetFileWithTitle(local_info.Title); File.Copy( Path.Combine(_filesPath, local_info.FileName + ".pdf"), Path.Combine(Path.Combine(Environment.CurrentDirectory, "Files"), fileName + ".pdf")); Article dbArticle = repo.GetArticleWithTitle(local_info.Title); // 3. Add references and bookmarks BookmarkRepo bookmarkRepo = new BookmarkRepo(); ReferenceRepo referenceRepo = new ReferenceRepo(); // Bookmarks local_info.Bookmarks.ForEach((bookmark) => { Bookmark dbBookmark = bookmarkRepo.GetBookmark(bookmark.Name, user); bookmarkRepo.AddArticleToBookmark(dbBookmark, dbArticle); }); // References local_info.References.ForEach((reference) => { Reference dbReference = referenceRepo.GetReference(reference.Name); referenceRepo.AddArticleToReference(dbReference, dbArticle); }); } // Create bookmark else if (log.Info.InfoType == "BookmarkInfo") { BookmarkInfo local_info = log.Info as BookmarkInfo; BookmarkRepo repo = new BookmarkRepo(); // Edge case: Bookmark already exists if (repo.GetBookmark(local_info.Name, user) != null) { string mismatch = $"Bookmark '{local_info.Name}' already exists."; _mismatches.Add(mismatch); return; } repo.AddBookmark(local_info.Name, local_info.Global, user); } // Create reference else if (log.Info.InfoType == "ReferenceInfo") { ReferenceInfo local_info = log.Info as ReferenceInfo; ReferenceRepo repo = new ReferenceRepo(); // Edge case: Reference already exists if (repo.GetReference(local_info.Name) != null) { string mismatch = $"Reference '{local_info.Name}' already exists."; _mismatches.Add(mismatch); return; } new ReferenceRepo().AddReference(local_info.Name); } break; case "Update": // Update article if (log.Info.InfoType == "ArticleInfo") { ArticleInfo local_info = (ArticleInfo)log.Info; ArticleRepo repo = new ArticleRepo(); Article existingArticle = repo.GetFullArticleWithTitle(user, log.Changed); // Edge case: Article I am trying to update doesn't exist if (existingArticle == null) { string mismatch = $"Article '{log.Changed}' doesn't exist and can't be updated."; _mismatches.Add(mismatch); return; } Article newArticle = new Article(local_info); newArticle.ID = existingArticle.ID; repo.UpdateArticle(newArticle, user); } // Update bookmark else if (log.Info.InfoType == "BookmarkInfo") { BookmarkInfo local_info = (BookmarkInfo)log.Info; BookmarkRepo repo = new BookmarkRepo(); Bookmark existingBookmark = repo.GetBookmark(log.Changed, user); // Edge case: Bookmark I am trying to update doesn't exist if (existingBookmark == null) { string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated."; _mismatches.Add(mismatch); return; } Bookmark newBookmark = new Bookmark(local_info); newBookmark.ID = existingBookmark.ID; repo.UpdateBookmark(newBookmark); } // Update reference else if (log.Info.InfoType == "ReferenceInfo") { ReferenceInfo local_info = (ReferenceInfo)log.Info; ReferenceRepo repo = new ReferenceRepo(); Reference existingReference = repo.GetReference(log.Changed); // Edge case: Reference I am trying to update doesn't exist if (existingReference == null) { string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated."; _mismatches.Add(mismatch); return; } Reference newReference = new Reference(local_info); newReference.ID = existingReference.ID; if (local_info.Title != null) { newReference.ArticleID = (int)new ArticleRepo().GetArticleWithTitle(local_info.Title).ID; } repo.UpdateReference(newReference); } break; case "Coupling": Couple info = (Couple)log.Info; // Couple bookmark if (info.CollectionType == "Bookmark") { BookmarkRepo bookmarkRepo = new BookmarkRepo(); ArticleRepo articleRepo = new ArticleRepo(); Bookmark bookmark = bookmarkRepo.GetBookmark(info.Name, user); Article article = articleRepo.GetArticleWithTitle(info.Title); // Edge case: Article or bookmark doesn't exist or Article is already in bookmark if (bookmark == null) { string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because bookmark doesn't exist"; _mismatches.Add(mismatch); return; } else if (article == null) { string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because article doesn't exist"; _mismatches.Add(mismatch); return; } // Add if (info.ActionType == "Add") { // Edge case: Article is already in bookmark if (bookmarkRepo.CheckArticleInBookmark(bookmark, article)) { string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'"; _mismatches.Add(mismatch); return; } bookmarkRepo.AddArticleToBookmark(bookmark, article); } // Remove else if (info.ActionType == "Remove") { // Edge case: Article is not in bookmark if (!bookmarkRepo.CheckArticleInBookmark(bookmark, article)) { string mismatch = $"Article - '{info.Title}' can not be removed from bookmark '{info.Name}' (Its not there)"; _mismatches.Add(mismatch); return; } bookmarkRepo.RemoveArticleFromBookmark(bookmark, article); } } // Couple reference else if (info.CollectionType == "Reference") { ReferenceRepo referenceRepo = new ReferenceRepo(); ArticleRepo articleRepo = new ArticleRepo(); Reference reference = referenceRepo.GetReference(info.Name); Article article = articleRepo.GetArticleWithTitle(info.Title); // Edge case: Article or bookmark doesn't exist if (reference == null) { string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because reference doesn't exist"; _mismatches.Add(mismatch); return; } else if (article == null) { string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because article doesn't exist"; _mismatches.Add(mismatch); return; } // Add if (info.ActionType == "Add") { if (referenceRepo.CheckArticleInReference(reference, article)) { string mismatch = $"Article - '{info.Title}' is already in reference '{info.Name}'"; _mismatches.Add(mismatch); return; } referenceRepo.AddArticleToReference(reference, article); } // Remove else if (info.ActionType == "Remove") { if (!referenceRepo.CheckArticleInReference(reference, article)) { string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'"; _mismatches.Add(mismatch); return; } referenceRepo.RemoveArticleFromReference(reference, article); } } break; case "Delete": DeleteInfo local_info1 = (DeleteInfo)log.Info; // Delete article if (local_info1.ObjectType == "Article") { ArticleRepo repo = new ArticleRepo(); Article article = repo.GetArticleWithTitle(local_info1.Name); // Edge case: Article I am trying to delete doesn't exist if (article == null) { string mismatch = $"Can't delete article '{local_info1.Name}' because it doesn't exist"; _mismatches.Add(mismatch); return; } string file = repo.GetFileWithTitle(local_info1.Name); repo.DeleteArticle(article); File.Delete(Path.Combine(Environment.CurrentDirectory, "Files", file + ".pdf")); } // Delete bookmark else if (local_info1.ObjectType == "Bookmark") { BookmarkRepo repo = new BookmarkRepo(); Bookmark bookmark = repo.GetBookmark(local_info1.Name, user); // Edge case: Bookmark I am trying to delete doesn't exist if (bookmark == null) { string mismatch = $"Can't delete bookmark '{local_info1.Name}' because it doesn't exist"; _mismatches.Add(mismatch); return; } repo.DeleteBookmark(bookmark); } // Delete reference else if (local_info1.ObjectType == "Reference") { ReferenceRepo repo = new ReferenceRepo(); Reference reference = repo.GetReference(local_info1.Name); // Edge case: Reference I am trying to delete doesn't exist if (reference == null) { string mismatch = $"Can't delete reference '{local_info1.Name}' because it doesn't exist"; _mismatches.Add(mismatch); return; } repo.DeleteReference(reference); } break; case "Personal": PersonalInfo local_info2 = (PersonalInfo)log.Info; ArticleRepo repo1 = new ArticleRepo(); Article article3 = repo1.GetArticleWithTitle(local_info2.Title); // Edge case: Article I am trying to add personal doesn't exist if (article3 == null) { string mismatch = $"Can't add personal to article '{local_info2.Title}' because it doesn't exist"; _mismatches.Add(mismatch); return; } article3.PersonalComment = local_info2.PersonalComment; article3.SIC = local_info2.SIC; repo1.UpdatePersonal(article3, user); break; case "Pending": PendingInfo l_info = (PendingInfo)log.Info; // 1. Remove pending section status from db new GlobalRepo().RemovePending(l_info.Section); // 2. Remove section from json string path = Path.Combine(Environment.CurrentDirectory, "sections.json"); string textInfo = File.ReadAllText(path); List <string> sections = JsonConvert.DeserializeObject <List <string> >(textInfo); sections.Remove(l_info.Section); textInfo = JsonConvert.SerializeObject(sections); File.WriteAllText(path, textInfo); break; default: break; } }); // 2. Write mismatches WriteMismatches(); }
// Command actions public void SaveReference(object input) { try { ReferenceRepo referenceRepo = new ReferenceRepo(); // 0. Get old reference name _name = referenceRepo.GetReferenceNameWithId(Reference.ID); bool hasMainArticle = !string.IsNullOrWhiteSpace(MainArticleTitle); if (hasMainArticle) { Reference.ArticleID = (new ArticleRepo()).CheckArticleWithTitle(MainArticleTitle); } // 1. Update reference in database if (hasMainArticle) { referenceRepo.UpdateReference(Reference, true); } else { referenceRepo.UpdateReference(Reference, false); } // 1.1 Track reference update ReferenceInfo info = new ReferenceInfo(Reference.Name); new Tracker(new User() { Username = "******", Admin = 1 }).TrackUpdate <ReferenceInfo>(info, _name); } catch (Exception e) { // Reference with that name already exists (ask merge dialog) if (e.Message.Contains("UNIQUE")) { if ( _dialogService.OpenDialog(new DialogYesNoViewModel("Reference with that name already exists, do you want to merge?", "Merge reference", DialogType.Question)) ) { ReferenceRepo repo = new ReferenceRepo(); Reference referenceFrom = repo.GetReference(_name); Reference referenceInto = repo.GetReference(Reference.Name); List <Article> articlesFrom = repo.LoadArticlesForReference(referenceFrom); List <Article> articlesInto = repo.LoadArticlesForReference(referenceInto); // 1. Get unique articles between 2 references List <Article> uniques = articlesFrom.Where(art => !articlesInto.Exists(el => el.Title == art.Title)).ToList(); // 2. Add those articles into merged reference repo.AddListOfArticlesToReference(referenceInto, uniques); // 3. Delete old reference repo.DeleteReference(referenceFrom); } } // Generic exception else { new BugTracker().Track("Refernce Editor", "Save Reference", e.Message, e.StackTrace); _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error)); } } finally { _parent.PopulateReferences(); // Close window (input as ICommand).Execute(null); } }
public ApplicantModel(ApplicantSubmitted app, int acquisitionid) { ApplicantId = app.ApplicantId; NewIcNo = app.NewICNo; NoTentera = app.NoTentera; FullName = app.FullName; MrtlStatusCd = app.MrtlStatusCd; GenderCd = app.GenderCd; Height = app.Height; Weight = app.Weight; Bmi = app.BMI; NationalityCd = app.NationalityCd; NationalityCertNo = app.NationalityCertNo; BirthCertNo = app.BirthCertNo; ReligionCd = app.ReligionCd; RaceCd = app.RaceCd; EthnicCd = !string.IsNullOrWhiteSpace(app.EthnicCd) ? app.EthnicCd.Trim() : app.EthnicCd; BirthCountryCd = app.BirthCountryCd; BirthStateCd = app.BirthStateCd; BirthCityCd = !string.IsNullOrWhiteSpace(app.BirthCityCd) ? app.BirthCityCd.Trim() : app.BirthCityCd; BirthPlace = app.BirthPlace; BloodTypeCd = app.BloodTypeCd; SpectaclesUserInd = app.SpectaclesUserInd; ColorBlindInd = app.ColorBlindInd; ResidenceTypeInd = app.ResidenceTypeInd; CorresponAddr1 = app.CorresponAddr1; CorresponAddr2 = app.CorresponAddr2; CorresponAddr3 = app.CorresponAddr3; CorresponAddrPostCd = app.CorresponAddrPostCd; CorresponAddrCityCd = !string.IsNullOrWhiteSpace(app.CorresponAddrCityCd) ? app.CorresponAddrCityCd.Trim() : app.CorresponAddrCityCd; CorresponAddrStateCd = app.CorresponAddrStateCd; CorresponAddrCountryCd = app.CorresponAddrCountryCd; MobilePhoneNo = app.MobilePhoneNo; HomePhoneNo = app.HomePhoneNo; Email = app.Email; ChildNo = app.ChildNo; NoOfSibling = app.NoOfSibling; MomName = app.MomName; MomIcNo = app.MomICNo; MomNationalityCd = app.MomNationalityCd; MomOccupation = app.MomOccupation; MomSalary = app.MomSalary; MomPhoneNo = app.MomPhoneNo; DadName = app.DadName; DadIcNo = app.DadICNo; DadNationalityCd = app.DadNationalityCd; DadOccupation = app.DadOccupation; DadSalary = app.DadSalary; DadPhoneNo = app.DadPhoneNo; GuardianName = app.GuardianName; GuardianIcNo = app.GuardianICNo; GuardianNationalityCd = app.GuardianNationalityCd; GuardianOccupation = app.GuardianOccupation; GuardianSalary = app.GuardianSalary; GuardianPhoneNo = app.GuardianPhoneNo; FamilyHighestEduLevel = app.FamilyHighestEduLevel; CurrentOccupation = app.CurrentOccupation; CurrentOrganisation = app.CurrentOrganisation; CurrentSalary = app.CurrentSalary; PalapesInd = app.PalapesInd ?? false; PalapesYear = app.PalapesYear; PalapesArmyNo = app.PalapesArmyNo; PalapesInstitution = app.PalapesInstitution; PalapesRemark = app.PalapesRemark; PalapesTauliahEndDt = app.PalapesTauliahEndDt; ScholarshipInd = app.ScholarshipInd ?? false; ScholarshipBody = app.ScholarshipBody; ScholarshipBodyAddr = app.ScholarshipBodyAddr; ScholarshipNoOfYrContract = app.ScholarshipNoOfYrContract; ArmySelectionInd = app.ArmySelectionInd ?? false; ArmySelectionVenue = app.ArmySelectionVenue; ArmyServiceInd = app.ArmyServiceInd ?? false; ArmyServiceYrOfServ = app.ArmyServiceYrOfServ; ArmyServiceResignRemark = app.ArmyServiceResignRemark; SelectionTD = app.SelectionTD; SelectionTL = app.SelectionTL; SelectionTU = app.SelectionTU; ComputerMSWord = app.ComputerMSWord; ComputerMSExcel = app.ComputerMSExcel; ComputerMSPwrPoint = app.ComputerMSPwrPoint; ComputerICT = app.ComputerICT; ComputerOthers = app.ComputerOthers; CrimeInvolvement = app.CrimeInvolvement; DrugCaseInvolvement = app.DrugCaseInvolvement; CreatedBy = app.CreatedBy; LastModifiedBy = app.LastModifiedBy; CreatedDateTime = app.CreatedDt; LastModifiedDatetTime = app.LastModifiedDt; BirthDate = app.BirthDt; EmployeeAggreeInd = app.EmployeeAggreeInd ?? false; CronicIlnessInd = app.CronicIlnessInd; ScholarshipContractStDate = app.ScholarshipContractStDate; OriginalPelepasanDocument = app.OriginalPelepasanDocument; PelepasanDocument = app.PelepasanDocument; ArmySelectionDt = app.ArmySelectionDt; MomNotApplicable = app.MomNotApplicable ?? false; DadNotApplicable = app.DadNotApplicable ?? false; GuardianNotApplicable = app.GuardianNotApplicable ?? false; if (!string.IsNullOrWhiteSpace(NewIcNo)) { var lastid = NewIcNo.Substring(NewIcNo.Length - 1); var checkgend = 0; int.TryParse(lastid, out checkgend); var even = new List<int>() { 0, 2, 4, 6, 8 }; var odd = new List<int>() { 1, 3, 5, 7, 9 }; if (string.IsNullOrWhiteSpace(app.GenderCd)) { if (even.Contains(checkgend)) GenderCd = "P"; if (odd.Contains(checkgend)) GenderCd = "L"; } } if (string.IsNullOrWhiteSpace(app.NationalityCd)) NationalityCd = "MYS"; if (string.IsNullOrWhiteSpace(app.DadNationalityCd)) DadNationalityCd = "MYS"; if (string.IsNullOrWhiteSpace(app.MomNationalityCd)) MomNationalityCd = "MYS"; if (string.IsNullOrWhiteSpace(app.GuardianNationalityCd)) GuardianNationalityCd = "MYS"; if (string.IsNullOrWhiteSpace(BirthCountryCd)) BirthCountryCd = "MYS"; if (string.IsNullOrWhiteSpace(app.CorresponAddrCountryCd)) CorresponAddrCountryCd = "MYS"; if (string.IsNullOrWhiteSpace(BirthStateCd)) { if (!string.IsNullOrWhiteSpace(NewIcNo)) { NewIcNo = NewIcNo.Trim(); if (NewIcNo.Length == 12) { var icbirthstatecode = NewIcNo.Substring(6, 2); var birthstatecode = ObjectBuilder.GetObject<IReferencePersistence>("ReferencePersistence").GetStatesByBirthStateCode(icbirthstatecode); if (null != birthstatecode) BirthStateCd = birthstatecode.StateCd; } } } if (!string.IsNullOrWhiteSpace(NewIcNo)) { var yearstr = NewIcNo.Substring(0, 2); var monthstr = NewIcNo.Substring(2, 2); var daystr = NewIcNo.Substring(4, 2); var yearint = Convert.ToInt32(yearstr); if (yearint == 0) yearint = 2000; if (yearint < 10) yearint = 2000 + yearint; if (yearint > 10) yearint = 1900 + yearint; var bdate = new DateTime(yearint, Convert.ToInt16(monthstr), Convert.ToInt16(daystr)); BirthDate = bdate; BirthDateString = string.Format("{0:dd/MM/yyyy}", bdate); DateTime zeroTime = DateTime.Now; var daterange = DateTime.Now - bdate; int years = (zeroTime + daterange).Year - 1; DateTime today = DateTime.Today; int months = zeroTime.Month - bdate.Month; Age = zeroTime.Year - bdate.Year; Month = months; } if (ApplicantId != 0) { // get educations var education = ObjectBuilder.GetObject<IApplicantSubmittedPersistence>("ApplicantSubmittedPersistence").GetEducation(ApplicantId, acquisitionid); if (null != education && education.Any()) { ApplicantEducationSubmitteds.Clear(); ApplicantEducationSubmitteds.AddRange(education.ToList()); } // get skills var skills = ObjectBuilder.GetObject<IApplicantSubmittedPersistence>("ApplicantSubmittedPersistence").GetSkill(ApplicantId, acquisitionid); if (null != skills && skills.Any()) { SkillSubmitteds.AddRange(skills.ToList()); if (SkillSubmitteds.Count <= 2) SkillSubmitteds.Add(new ApplicantSkillSubmitted() { SkillCd = "", SkillCatCd = "L", Skill = "" }); } // get sports var sports = ObjectBuilder.GetObject<IApplicantSubmittedPersistence>("ApplicantSubmittedPersistence").GetSport(ApplicantId, acquisitionid); if (null != sports && sports.Any()) { SportSubmitteds.AddRange(sports.Where(a => a.SportAndAssociation != null && a.SportAndAssociation.SportAssociatType == "S").ToList().DistinctBy(a => a.SportAssocId)); KokoSubmitteds.AddRange(sports.Where(a => a.SportAndAssociation != null && a.SportAndAssociation.SportAssociatType == "A").ToList().DistinctBy(a => a.SportAssocId)); OtherSubmitteds.AddRange(sports.Where(a => !string.IsNullOrWhiteSpace(a.Others))); } } if (!string.IsNullOrWhiteSpace(app.ComputerOthers)) ComputerOthersInd = true; if (acquisitionid != 0) { var acq = ObjectBuilder.GetObject<IAcquisitionPersistence>("AcquisitionPersistence").GetAcquisition(acquisitionid); if (acq != null && acq.AcquisitionTypeCd != 0) { var selectededucation = new string[] { }; var refrepos = new ReferenceRepo(); //var acqtype = ObjectBuilder.GetObject<IReferencePersistence>("ReferencePersistence").GetAcquisitionType(acq.AcquisitionTypeCd); if (null != acq.AcquisitionType) { // pegawai if (acq.AcquisitionType.ServiceCd == "10") selectededucation = new string[] { "14", "13", "25", "11", "08", "20" }; // td if (acq.AcquisitionType.ServiceCd == "01") selectededucation = new string[] { "14", "13", "25", "26", "11" }; // tl if (acq.AcquisitionType.ServiceCd == "02") selectededucation = new string[] { "14", "13", "25", "15", "26", "11" }; // tu if (acq.AcquisitionType.ServiceCd == "03") selectededucation = new string[] { "14", "13", "25", "26", "08", "11" }; var he = refrepos.GetHighEduLevels().Where(a => selectededucation.Contains(a.HighEduLevelCd)); if (he.Any()) { he = he.OrderBy(a => a.IndexNo); if (ApplicantEducationSubmitteds != null && ApplicantEducationSubmitteds.Any()) { var ledu = new List<ApplicantEducationSubmitted>(); ledu.AddRange(ApplicantEducationSubmitteds); foreach (var ed in ledu.ToList()) { if (ed.HighEduLevelCd == "14") { var selectedsubject = ed.ApplicantEduSubjectSubmittedCollection.ToList().RemoveAll(a => !string.IsNullOrEmpty(a.GradeCd)); var subjects = refrepos.GetSubjects(ed.HighEduLevelCd); if (subjects.Any()) { foreach (var s in subjects.Take(10)) { // check already exist or not in subjects if (ed.ApplicantEduId != 0) { var subbs = ObjectBuilder.GetObject<IApplicantSubmittedPersistence>("ApplicantSubmittedPersistence").GetSubject(ed.ApplicantEduId, s.SubjectCd); if (null != subbs) { if (ed.ApplicantEduSubjectSubmittedCollection.All(a => a.SubjectCd != subbs.SubjectCd)) ed.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted() { SubjectCd = subbs.SubjectCd, Subject = subbs.Subject }); } else { if (!ed.ApplicantEduSubjectSubmittedCollection.Any(a => subbs != null && a.SubjectCd == subbs.SubjectCd)) ed.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted() { SubjectCd = s.SubjectCd, Subject = s.SubjectDescription }); } } else { if (ed.ApplicantEduSubjectSubmittedCollection.All(a => a.SubjectCd != s.SubjectCd)) ed.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted() { SubjectCd = s.SubjectCd, Subject = s.SubjectDescription }); } } } var totalsubject = 16 - ed.ApplicantEduSubjectSubmittedCollection.Count(); for (int i = 0; i < totalsubject; i++) { ed.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted()); } } foreach (var h in he) { if (ledu.All(a => a.HighEduLevelCd != h.HighEduLevelCd)) { var edu = new ApplicantEducationSubmitted() { HighEduLevelCd = h.HighEduLevelCd, HighEduLevel = h.HighestEduLevel }; if (h.HighEduLevelCd == "14") { var subjects = refrepos.GetSubjects(h.HighEduLevelCd); if (subjects.Any()) foreach (var s in subjects.Take(10)) edu.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted() { SubjectCd = s.SubjectCd, Subject = s.SubjectDescription }); var totalsubject = 16 - ed.ApplicantEduSubjectSubmittedCollection.Count(); for (int i = 0; i < totalsubject; i++) { edu.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted()); } } ledu.Add(edu); } } } ApplicantEducationSubmitteds.Clear(); ApplicantEducationSubmitteds.AddRange(ledu.DistinctBy(a => a.HighEduLevelCd)); } else { foreach (var h in he) { var edu = new ApplicantEducationSubmitted() { HighEduLevelCd = h.HighEduLevelCd, HighEduLevel = h.HighestEduLevel }; if (h.HighEduLevelCd == "14") { var subjects = refrepos.GetSubjects(h.HighEduLevelCd); if (subjects.Any()) foreach (var s in subjects.Take(10)) edu.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted() { SubjectCd = s.SubjectCd, Subject = s.SubjectDescription }); for (int i = 0; i < 6; i++) { edu.ApplicantEduSubjectSubmittedCollection.Add(new ApplicantEduSubjectSubmitted()); } } ApplicantEducationSubmitteds.Add(edu); } } } var scount = 0; var kcount = 0; if (SportSubmitteds != null) { scount = SportSubmitteds.Count(); if (scount == 0) scount = 2; else if (scount == 1) scount = 1; else scount = 0; for (int i = 0; i < scount; i++) { SportSubmitteds.Add(new ApplicantSportSubmitted()); } kcount = KokoSubmitteds.Count(); if (kcount == 0) kcount = 2; else if (kcount == 1) kcount = 1; else kcount = 0; for (int i = 0; i < kcount; i++) { KokoSubmitteds.Add(new ApplicantSportSubmitted()); } } var skills = ObjectBuilder.GetObject<IReferencePersistence>("ReferencePersistence").GetSkills("L"); if (skills != null && skills.Any()) { skills = skills.Take(2); foreach (var s in skills) { if (!SkillSubmitteds.Any(a => a.SkillCd.Trim() == s.SkillCd.Trim())) SkillSubmitteds.Add(new ApplicantSkillSubmitted() { SkillCd = s.SkillCd.Trim(), SkillCatCd = "L", Skill = s.SkillDescription.Trim() }); } if (SkillSubmitteds.Count <= 2) SkillSubmitteds.Add(new ApplicantSkillSubmitted() { SkillCd = "", SkillCatCd = "L", Skill = "" }); } if (!OtherSubmitteds.Any()) { for (int i = 0; i < 2; i++) { OtherSubmitteds.Add(new ApplicantSportSubmitted()); } } else if (OtherSubmitteds.Count() == 1) { OtherSubmitteds.Add(new ApplicantSportSubmitted()); } } } } }