/// <summary> /// Stores multiple expertise values for one artifact. /// </summary> /// <param name="filename">The name of the artifact for which the experts are sought</param> /// <param name="devIdsWithExpertiseValues">A dictionary that maps DeveloperIds to expertise values</param> protected void storeDeveloperExpertiseValues(string filename, IEnumerable <DeveloperWithExpertise> devIdsWithExpertiseValues) { using (var repository = new ExpertiseDBEntities()) { int artifactId = SourceRepositoryManager.FindOrCreateArtifact(repository, filename, ArtifactTypeEnum.File).ArtifactId; bool fNewAdditions = false; foreach (DeveloperWithExpertise devExpertise in devIdsWithExpertiseValues) { if (fNewAdditions) { repository.SaveChanges(); // The Entity Framework does not seem to like it if multiple new entries are added in the above way. fNewAdditions = false; // Therefore we save after additions. } DeveloperExpertise developerExpertise = SourceRepositoryManager.FindOrCreateDeveloperExpertise(repository, devExpertise.DeveloperId, artifactId, true); fNewAdditions |= 0 == developerExpertise.DeveloperExpertiseId; // hack: is it a new DeveloperExpertise? DeveloperExpertiseValue devExpertiseValue = FindOrCreateDeveloperExpertiseValue(developerExpertise); devExpertiseValue.Value = devExpertise.Expertise; fNewAdditions |= 0 == devExpertiseValue.DeveloperExpertiseValueId; // hack: is it a new DeveloperExpertiseValue? } repository.SaveChanges(); } }
protected void ClearExpertiseForAllDevelopers(string filename) { using (var entities = new ExpertiseDBEntities()) { Artifact artifact = SourceRepositoryManager.FindOrCreateArtifact(entities, filename, ExpertiseExplorer.Common.ArtifactTypeEnum.File); foreach (DeveloperExpertise expertise in artifact.DeveloperExpertises) { IEnumerator <DeveloperExpertiseValue> iteratorOnValuesToClear = expertise.DeveloperExpertiseValues.Where(dev => dev.AlgorithmId == AlgorithmId).GetEnumerator(); while (iteratorOnValuesToClear.MoveNext()) { expertise.DeveloperExpertiseValues.Remove(iteratorOnValuesToClear.Current); } } entities.SaveChanges(); } }