private void createAccessionPopulation(AccessionViewModel accession) { Family family = accession.ToFamily(); try { u_repo.SaveFamily(family); } catch (Exception e) { //TODO:write to logging throw new AccessionException("Unable to create population"); } Genotype genotype = accession.ToGenotype(); genotype.Family = family; genotype.FamilyId = family.Id; if (accession.IsBase) { genotype.Year = accession.FamilyBaseGenotypeYear; genotype.Note = accession.FamilyBaseGenotypeNote; genotype.IsRoot = true; } try { u_repo.SaveGenotype(genotype); } catch (Exception e) { u_repo.DeleteFamily(family); //TODO:write to logging throw new AccessionException("Unable to create selection"); } family.BaseGenotype = genotype; family.BaseGenotypeId = genotype.Id; u_repo.SaveFamily(family); accession.Id = genotype.Id; }
private void updateAccession(AccessionViewModel accession) { // update genotype information Genotype oldGenotype = u_repo.GetGenotype(accession.Id); var oldGivenName = oldGenotype.GivenName; var oldOriginalName = oldGenotype.OriginalName; Genotype genotype = accession.ToGenotype(); genotype.Family = oldGenotype.Family; genotype.FamilyId = oldGenotype.FamilyId; genotype.CrossPlanId = oldGenotype.CrossPlanId; genotype.IsPopulation = accession.IsPopulation; if (accession.Id <= 0) { genotype.Family = u_repo.GetFamily(genotype.FamilyId); } if (accession.IsBase) { genotype.Year = accession.FamilyBaseGenotypeYear; genotype.Note = accession.FamilyBaseGenotypeNote; genotype.IsRoot = true; } if (genotype.GivenName != oldGivenName && !oldGivenName.IsNullOrWhiteSpace()) { genotype.Alias2 = genotype.Alias1; genotype.Alias1 = oldGivenName; } // update family information if (accession.IsBase) { Family oldFamily = u_repo.GetFamily(accession.FamilyId); // check origin name and cross number Family family = accession.ToFamily(); if (family.CrossTypeId.HasValue) { family.CrossType = u_repo.GetCrossType(accession.FamilyCrossTypeId.Value); } if (family.OriginId.HasValue) { family.Origin = u_repo.GetOrigin(accession.FamilyOriginId.Value); } if (oldFamily.OriginalName != family.OriginalName && !oldFamily.OriginalName.IsNullOrWhiteSpace()) { genotype.Alias2 = genotype.Alias1; genotype.Alias1 = oldOriginalName; u_repo.UpdateGeotypesAlias(family.Id, oldOriginalName); } family.BaseGenotype = oldFamily.BaseGenotype; family.BaseGenotypeId = oldFamily.BaseGenotypeId; family.Genus = oldFamily.Genus; family.Genotypes = oldFamily.Genotypes; if (family.FemaleParent.HasValue) { family.FemaleGenotype = u_repo.GetGenotype(family.FemaleParent.Value); } if (family.MaleParent.HasValue) { family.MaleGenotype = u_repo.GetGenotype(family.MaleParent.Value); } if (family.OriginId.HasValue) { family.Origin = u_repo.GetOrigin(family.OriginId.Value); } u_repo.SaveFamily(family); } u_repo.SaveGenotype(genotype); if (genotype.CrossPlanId.HasValue) { UpdateCrossPlanFromAccession(genotype); } }