private MapComponent GetMapComponentFromViewModel(MapComponentViewModel mapcomponentvm) { MapComponent mapcomponent = null; if (mapcomponentvm.Id > 0) { ValidateMapComponentGenotype(mapcomponentvm.Id, mapcomponentvm.GenotypeId); mapcomponent = u_repo.GetMapComponent(mapcomponentvm.Id); mapcomponentvm.ToMapComponent(mapcomponent); } else { mapcomponent = mapcomponentvm.ToMapComponent(); mapcomponent.isRemoved = false; } if (mapcomponent.GenotypeId.HasValue) { mapcomponent.Genotype = u_repo.GetGenotype(mapcomponent.GenotypeId.Value); } if (mapcomponent.Map == null) { mapcomponent.Map = u_repo.GetMap(mapcomponent.MapId); } return(mapcomponent); }
private void GetDefaultValues(CrossPlan crossPlan, IPlantBreedingRepo repo) { if (crossPlan.Id > 0 && !crossPlan.GenotypeId.HasValue) { CrossPlan old = repo.GetCrossPlan(crossPlan.Id); if (!crossPlan.GenotypeId.HasValue) { crossPlan.GenotypeId = old.GenotypeId; } } if (crossPlan.FemaleParentId.HasValue && crossPlan.FemaleParent == null) { crossPlan.FemaleParent = repo.GetGenotype(crossPlan.FemaleParentId.Value); } if (crossPlan.MaleParentId.HasValue && crossPlan.MaleParent == null) { crossPlan.MaleParent = repo.GetGenotype(crossPlan.MaleParentId.Value); } if (crossPlan.OriginId.HasValue && crossPlan.OriginId == null) { crossPlan.Origin = repo.GetOrigin(crossPlan.OriginId.Value); } if (crossPlan.CrossTypeId.HasValue && crossPlan.CrossType == null) { crossPlan.CrossType = repo.GetCrossType(crossPlan.CrossTypeId.Value); } crossPlan.Genus = repo.GetGenus(crossPlan.GenusId); }
public PhenotypeEntryViewModel GetPhenotypeSummary(int genotypeId) { Genotype genotype = u_repo.GetGenotype(genotypeId); List <Fate> possibleFates = u_repo.GetFates().OrderBy(t => t.Order).ToList(); PhenotypeEntryViewModel vm = GenotypePhenotypeEntry(genotype, possibleFates); return(vm); }
/// <summary> /// Updates a genotype from a crossplan /// </summary> /// <param name="cp"></param> public Genotype GenotypeFromCrossPlan(CrossPlan cp) { if (!cp.GenotypeId.HasValue) { //TODO: Throw error } Genotype genotype = u_repo.GetGenotype(cp.GenotypeId.Value); if (genotype != null) { genotype.UpdateFromCrossPlan(cp); } return(genotype); }
/// <summary> /// Builds a pedigree tree for a Genotype. A Pedigree tree is a BST-like structure of parents for that genotype. /// </summary> /// <param name="id">The ID of the Genotype to build a Pedigree from.</param> /// <returns>The root node of the Pedigree Tree, or null if the ID doesn't find a match.</returns> public static TreeNode <Genotype> BuildPedigreeTree(this Genotype target, IPlantBreedingRepo repo) { if (target == null) { throw new ArgumentNullException("target"); } Genotype root = repo.GetGenotype(target.Id); Tuple <Genotype, Genotype> parents = repo.GetGenotypeParents(target); var node = new TreeNode <Genotype> { Data = root }; if (parents != null && parents.Item1 != null) { // Left side is always the male. node.Left = BuildPedigreeTree(parents.Item1, repo); } if (parents != null && parents.Item2 != null) { // Right side is always the female. node.Right = BuildPedigreeTree(parents.Item2, repo); } return(node); }
public ReportViewModel GetSelectionSummaryReport(SelectionSummaryReport vm) { string reportName = Properties.Settings.Default.ReportNameSelectionSummary; var genotype = u_repo.GetGenotype(vm.GenotypeId); string reportTitle = $"{genotype.Name} Phenotype Summary"; return(vm.ToReportViewModel(reportName, reportTitle)); }
public SelectionSummaryViewModel GetSelectionSummary(int id) { Genotype genotype = u_repo.GetGenotype(id); IEnumerable <Family> families = u_repo.GetQueryableFamilies(t => t.MaleParent == genotype.Id || t.FemaleParent == genotype.Id).ToList(); IEnumerable <FamilyUseViewModel> fuvms = families.ToFamilyUseViewModel(genotype); PhenotypeEntryViewModel pdvm = GetPhenotypeEntry(id); SelectionSummaryViewModel ssvm = genotype.ToSelectionSummaryViewModel(pdvm, fuvms); return(ssvm); }
public void SaveOrderProduct(OrderProductViewModel orderProduct) { var op = OrderProductViewModel.ToOrderProduct(orderProduct); op.Genotype = u_repo.GetGenotype(op.GenotypeId); op.Material = u_repo.GetMaterials().SingleOrDefault(m => m.Id == op.MaterialId); u_repo.SaveOrderProduct(op); var savedVM = OrderProductViewModel.Create(op); savedVM.CopyTo(orderProduct); }
/// <summary> /// Displays selection summary detail view for given genotype. /// </summary> /// <param name="id"> /// Id of genotype to display selection summary for. /// </param> /// <returns> /// Detail view for selection summary. /// </returns> public ActionResult Detail(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SelectionSummaryViewModel ssvm = s_repo.GetSelectionSummary(id.Value); if (ssvm == null) { return(HttpNotFound()); } ViewBag.GenusId = m_repo.GetGenotype(id.Value).Family.GenusId; ViewBag.FlatTypes = new SelectList(m_repo.GetFlatTypes(), "Id", "Label"); return(View(ssvm)); }
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()); }
public AccessionViewModel GetAccessionViewModel(int id) { Genotype genotype = u_repo.GetGenotype(id); if (genotype == null) { return(null); } IEnumerable <MapComponent> mapComponents = genotype.MapComponents.OrderBy(t => t.Map.EvaluationYear); var accession = genotype.ToAccessionViewModel(); if (accession.IsBase.Equals(true)) { accession.Year = null; accession.Note = null; } accession.MapComponents = mapComponents.Where(t => t.Map.Retired == false).OrderByDescending(t => t.Map.PlantingYear).ToList(); accession.MapComponentsRetired = mapComponents.Where(t => t.Map.Retired == true).OrderByDescending(t => t.Map.PlantingYear).ToList(); return(accession); }
public ActionResult Index(int?pageSize, int?genotypeId, string filter, int page = 1, string messageResult = "") { int defaultPage = 1; int baseIdResult = 0; int genotypeIdResult = 0; bool successfullResult = true; string filterResult = filter; if (!pageSize.HasValue) { if (SessionManager.SessionPageSize.HasValue) { pageSize = SessionManager.SessionPageSize; } else { pageSize = Properties.Settings.Default.PageSize; } } SetPageSizeViewBag(); SessionManager.SessionPageSize = pageSize.Value; int genusId = SessionManager.GetGenusId().Value; IPagedList <AccessionIndexViewModel> pageOfAccessions = null; try { pageOfAccessions = a_repo.GetPageInIndex(pageSize.Value, genotypeId, filter, page, genusId); } catch (SearchException e) { successfullResult = false; messageResult = e.Message; } if (successfullResult == false) { try { pageOfAccessions = a_repo.GetPageInIndex(pageSize.Value, defaultPage, genusId); } catch (SearchException) { return(RedirectToAction("Create")); //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } } Genotype genotypeSearched = null; if (!genotypeId.HasValue && !filter.IsNullOrWhiteSpace()) { genotypeSearched = m_repo.GetGenotypes(filter, genusId, 1).FirstOrDefault(); } else if (genotypeId.HasValue) { genotypeSearched = m_repo.GetGenotype(genotypeId.Value); } if (genotypeSearched != null) { successfullResult = true; genotypeIdResult = genotypeSearched.Id; if (genotypeSearched.Family.BaseGenotypeId.HasValue && pageOfAccessions.HasAny(t => t.Id == genotypeSearched.Family.BaseGenotypeId)) { baseIdResult = genotypeSearched.Family.BaseGenotypeId.Value; } else { baseIdResult = genotypeSearched.Id; } } ViewBag.GenusId = genusId; ViewBag.GenotypeId = genotypeIdResult; ViewBag.BaseId = baseIdResult; ViewBag.SuccessfulSearch = successfullResult; ViewBag.Filter = filter; ViewBag.SearchErrorMessage = messageResult; ViewBag.PageSize = pageSize.Value.ToString(); ViewBag.CurrentDate = DateTime.Now; return(View(pageOfAccessions)); }