public void POSTCreateInvalidSessionTest() { var genotype = new Genotype { Id = 12, }; var viewModel = new AccessionViewModel { Id = 12, }; var mockRepo = new Mock <IPlantBreedingRepo>(); mockRepo.Setup(m => m.GetGenotype(12)).Returns(genotype); var controller = new DefaultController(mockRepo.Object); controller.ModelState.AddModelError("err", "errerr"); var response = controller.Create(viewModel) as ViewResult; Assert.IsNotNull(response); Console.WriteLine(response.ViewData.ToArray()); Assert.IsNotNull((response.ViewData.Model as AccessionViewModel).FamilyId); }
public static void CopyCrossToAccession(this AccessionViewModel accession, CrossPlan cross) { if (cross.MaleParentId.HasValue) { accession.FamilyMaleParent = cross.MaleParentId; accession.FamilyMaleGenotypeName = cross.MaleParent.Name; } if (cross.FemaleParentId.HasValue) { accession.FamilyFemaleParent = cross.FemaleParentId; accession.FamilyFemaleGenotypeName = cross.FemaleParent.Name; } accession.Year = cross.Year; // accession.IsPopulation = //TODO: add this? accession.FamilyBaseGenotypeYear = cross.Year; accession.FamilyGenusId = cross.GenusId; accession.FamilyTransplantedNum = cross.TransplantedNum; accession.FamilySeedNum = cross.SeedNum; accession.FamilyFieldPlantedNum = cross.FieldPlantedNum; accession.FamilyCrossNum = cross.CrossNum; accession.FamilyBaseGenotypeNote = cross.Note; accession.FamilyUnsuccessful = cross.Unsuccessful; accession.FamilyCrossTypeId = cross.CrossTypeId; accession.CrossPlanId = cross.Id; accession.FamilyPurpose = cross.Purpose; }
public ActionResult Create() { AccessionViewModel accession = a_repo.GetNextAccession(SessionManager.GetGenusId().Value); SetViewBagForPlant(accession); ViewBag.Create = true; return(View(accession)); }
/// <summary> /// Gets the next available accession with origin and next available cross number /// </summary> /// <param name="id">genus id of the accession</param> /// <param name="originId">origin id to get the next available number</param> /// <returns></returns> public AccessionViewModel GetNextAccession(int id, int originId) { Origin origin = u_repo.GetOrigin(originId); AccessionViewModel accession = GetNextAccession(id); accession.FamilyCrossNum = GetNextCross(origin.Id, id); accession.FamilyOriginId = origin.Id; accession.FamilyOriginName = origin.Name; return(accession); }
public void SaveAccessionViewModel(AccessionViewModel accession) { if (accession.Id <= 0 && accession.FamilyId <= 0) { createAccessionPopulation(accession); } else { updateAccession(accession); } }
/// <summary> /// Get the next available accession /// </summary> /// <param name="id">Genus Id of next accession</param> /// <returns></returns> public AccessionViewModel GetNextAccession(int id) { AccessionViewModel accession = new AccessionViewModel { FamilyGenusId = id, FamilyBaseGenotypeYear = DateTime.Now.Year.ToString(), IsBase = true, MapComponents = new List <MapComponent>() }; return(accession); }
public AccessionViewModel GetNextAccession(int crossId) { CrossPlan crossPlan = u_repo.GetCrossPlan(crossId); int genusId = crossPlan.GenusId; Origin origin = u_repo.GetDefaultOrigin(); AccessionViewModel accession = a_repo.GetNextAccession(genusId, origin.Id); accession.CopyCrossToAccession(crossPlan); accession.IsBase = true; accession.IsRoot = true; accession.Id = 0; return(accession); }
public void RestoreProperties(AccessionViewModel accession) { AccessionViewModel oldAccession = GetAccessionViewModel(accession.Id); // restore map components accession.MapComponents = oldAccession.MapComponents; // restore family properties if not base if (!accession.IsBase) { // Genotype genotype = u_repo.GetGenotype(accession.Id); // Family family = genotype.Family; Family family = u_repo.GetFamily(accession.FamilyId); Mapper.Map(family, accession); } }
public ActionResult Details(AccessionViewModel accession) { if (accession == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { a_repo.SaveAccessionViewModel(accession); return(RedirectToAction("Details", "Default", new { id = accession.Id })); } SetViewBagForPlant(accession); a_repo.RestoreProperties(accession); return(View(accession)); }
private void SetViewBagForPlant(AccessionViewModel accession) { // TODO: use accession unit of work methods IEnumerable <SelectListItem> crossTypes = m_repo .GetCrossTypes() .Where(c => !c.Retired && c.GenusId == accession.FamilyGenusId || c.Id == accession.FamilyCrossTypeId) .Select(c => new SelectListItem() { Value = c.Id.ToString(), Text = c.Name, Disabled = c.Retired }).OrderBy(t => t.Text); ViewBag.CrossTypeId = crossTypes; }
public ActionResult Details(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AccessionViewModel accession = a_repo.GetAccessionViewModel(id.Value); if (accession == null) { return(HttpNotFound()); } SetViewBagForPlant(accession); ViewBag.Create = false; return(View(accession)); }
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; }
public void POSTCreateHappyTest() { var genotype = new Genotype() { Id = 12, GivenName = "bananas" }; var viewModel = new AccessionViewModel() { Id = 12, GivenName = "bananas" }; var mockRepo = new Mock <IPlantBreedingRepo>(); mockRepo.Setup(m => m.GetGenotype(12)).Returns(genotype); var response = new DefaultController(mockRepo.Object).Create(viewModel) as RedirectToRouteResult; Assert.IsNotNull(response); Assert.IsNotNull(response.RouteValues); Assert.AreEqual("Details", response.RouteValues["action"]); }
public void SaveAccession(AccessionViewModel accession) { if (!accession.CrossPlanId.HasValue) { throw new CrossPlanException(Properties.Settings.Default.ExceptionCrossPlanAccessionNoId); } if (!accession.CrossPlanId.HasValue || accession.FamilyCrossNum.IsNullOrWhiteSpace()) { throw new CrossPlanException("Invalid Cross Number"); } if (a_repo.IsDuplicatePopulation(accession.FamilyId, accession.FamilyOriginId.Value, accession.FamilyCrossNum, accession.FamilyGenusId)) { throw new CrossPlanException("Invalid Cross Number"); } a_repo.SaveAccessionViewModel(accession); CrossPlan cp = u_repo.GetCrossPlan(accession.CrossPlanId.Value); cp.GenotypeId = accession.Id; u_repo.SaveCrossPlan(cp); }
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); } }
public static Family ToFamily(this AccessionViewModel accession) { return(Mapper.Map <AccessionViewModel, Family>(accession)); }
public static Genotype ToGenotype(this AccessionViewModel accession) { return(Mapper.Map <AccessionViewModel, Genotype>(accession)); }
public void SaveFamily(int crossPlanId) { AccessionViewModel vm = GetNextAccession(crossPlanId); SaveAccession(vm); }