public IEnumerable <GenotypeUseSummaryViewModel> GetCrossSelections(int id)
        {
            var family = u_repo.GetFamily(id);

            if (family == null)
            {
                return(null);
            }
            return(family.Genotypes.Where(t => t.IsRoot == false).ToGenotypeUseSummaryViewModel().OrderBy(t => t.OriginalName));
        }
        public ActionResult Tree(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //Constants needed by the tree
            int treeSize = 15;
            int index    = 1; //Current location in the array

            //root of tree, child to build off of
            Genotype root = m_repo.GetGenotype(id.Value);

            if (root == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Tree to pass to page
            List <Genotype> tree = new List <Genotype>();
            List <Family>   fams = new List <Family>();

            //fill list to handle off array errors
            for (int i = 0; i < treeSize; i++)
            {
                tree.Add(new Genotype {
                    GivenName = ""
                });
            }

            //fill list to handle off array errors
            for (int i = 0; i < treeSize; i++)
            {
                fams.Add(new Family());
            }

            //add male parent
            tree.Insert(index, root);
            fams.Insert(index, m_repo.GetFamily(root.FamilyId));

            //Increment index
            index++;

            //Get root parents
            Tuple <Genotype, Genotype> parents = m_repo.GetGenotypeParents(root);

            //different iteration to handle 0 index
            //Female is always first in the tuple
            if (parents.Item1 != null)
            {
                tree.Insert(index, parents.Item1);
                fams.Insert(index, m_repo.GetFamily(parents.Item1.FamilyId));
            }
            else
            {
                tree.Insert(index, new Genotype {
                    GivenName = ""
                });
                fams.Insert(index, new Family()
                {
                });
            }

            //Male is second
            if (parents.Item2 != null)
            {
                tree.Insert(index + 1, parents.Item2);
                fams.Insert(index + 1, m_repo.GetFamily(parents.Item2.FamilyId));
            }
            else
            {
                tree.Insert(index + 1, new Genotype {
                    GivenName = ""
                });
                fams.Insert(index + 1, new Family()
                {
                });
            }

            //Tree population, through grandparents (index 8), start at father (index 2)
            for (int i = 2; i < 8; i++)
            {
                if (!tree[i].Id.Equals(0))                        //if parent is not null
                {
                    parents = m_repo.GetGenotypeParents(tree[i]); //get parents
                }
                else
                {
                    parents = new Tuple <Genotype, Genotype>(item1: null, item2: null); //new tuple with null genotypes
                }

                addParents(ref index, ref tree, ref fams, parents);
            }

            //Send list to view
            tree.RemoveAt(0);
            fams.RemoveAt(0);

            //tree.RemoveRange(15, tree.Count - 15);
            ViewBag.genotypeList = tree;
            ViewBag.families     = fams;
            ViewBag.Genotype     = root;
            return(View());
        }
예제 #3
0
        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);
            }
        }