Example #1
0
 public void GenotypeFromCrossPlan(CrossPlan cp, Genotype gen)
 {
     if (gen != null)
     {
         gen.UpdateFromCrossPlan(cp);
     }
 }
Example #2
0
        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);
        }
Example #3
0
        private CrossPlanViewModel CreateReciprocal(int id)
        {
            var original = u_repo.GetCrossPlan(id);

            if (original == null)
            {
                throw new CrossPlanException("Invalid Cross Plan");
            }

            var plan = new CrossPlan()
            {
                MaleParent   = original.FemaleParent,
                FemaleParent = original.MaleParent,
                Year         = original.Year,
                GenusId      = original.GenusId,
                CrossTypeId  = original.CrossTypeId,
                Purpose      = original.Purpose,
                Note         = original.Note,
                DateCreated  = original.DateCreated,
                Reciprocal   = true
            };

            u_repo.SaveCrossPlan(plan);

            return(GetCrossPlan(plan.Id));
        }
 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 static void UpdateFromCrossPlan(this Genotype dest, CrossPlan crossplan)
 {
     dest.Note                   = crossplan.Note;
     dest.Family.Purpose         = crossplan.Purpose;
     dest.Family.SeedNum         = crossplan.SeedNum;
     dest.Family.Unsuccessful    = crossplan.Unsuccessful;
     dest.Family.FieldPlantedNum = crossplan.FieldPlantedNum;
     dest.Family.TransplantedNum = crossplan.TransplantedNum;
 }
Example #6
0
        private bool IsEmptyCrossPlan(CrossPlan cp)
        {
            bool val = true;

            if (cp.Id > 0 || cp.CrossTypeId.HasValue || cp.FemaleParentId.HasValue || cp.MaleParentId.HasValue || !string.IsNullOrWhiteSpace(cp.Purpose))
            {
                val = false;
            }
            return(val);
        }
 public static void CopyCrossPlan(this CrossPlan dest, CrossPlan src)
 {
     dest.FemaleParentId = src.FemaleParentId;
     dest.MaleParentId   = src.MaleParentId;
     dest.Note           = src.Note;
     dest.Purpose        = src.Purpose;
     dest.CrossTypeId    = src.CrossTypeId;
     dest.Reciprocal     = src.Reciprocal;
     dest.Unsuccessful   = src.Unsuccessful;
     dest.DateCreated    = src.DateCreated;
 }
Example #8
0
 public void Save(CrossPlan crossPlan, bool restoreDefaults)
 {
     if (restoreDefaults)
     {
         GetDefaultValues(crossPlan);
     }
     u_repo.SaveCrossPlan(crossPlan);
     if (crossPlan.GenotypeId.HasValue)
     {
         UpdateAccessionFromCrossPlan(crossPlan);
     }
 }
Example #9
0
        public void CopyToNewYear(CrossPlan old, string year)
        {
            if (year.IsNullOrWhiteSpace())
            {
                throw new CrossPlanException(Properties.Settings.Default.ExceptionCrossPlanInvalidYear);
            }

            CrossPlan copyPlan = GetNext(year, old.GenusId);

            copyPlan.CopyCrossPlan(old);
            u_repo.SaveCrossPlan(copyPlan);
        }
Example #10
0
        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);
        }
Example #11
0
        public CrossPlan GetNext(string year, int genusId)
        {
            Genus     genus = u_repo.GetGenus(genusId);
            CrossPlan cross = new CrossPlan()
            {
                Genus       = genus,
                GenusId     = genus.Id,
                Year        = year,
                DateCreated = System.DateTime.MinValue
            };

            return(cross);
        }
 public static void UpdateFromAccession(this CrossPlan dest, Genotype genotype)
 {
     dest.Note            = genotype.Note;
     dest.Purpose         = genotype.Family.Purpose;
     dest.SeedNum         = genotype.Family.SeedNum;
     dest.Unsuccessful    = genotype.Family.Unsuccessful;
     dest.CrossTypeId     = genotype.Family.CrossTypeId;
     dest.CrossType       = genotype.Family.CrossType;
     dest.CrossNum        = genotype.Family.CrossNum;
     dest.GenotypeId      = genotype.Id;
     dest.FieldPlantedNum = genotype.Family.FieldPlantedNum;
     dest.TransplantedNum = genotype.Family.TransplantedNum;
 }
Example #13
0
        /// <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);
        }
Example #14
0
        public void UpdateCrossPlanFromAccession(Genotype genotype)
        {
            if (!genotype.CrossPlanId.HasValue)
            {
                throw new CrossPlanException(Properties.Settings.Default.ExceptionCrossPlanAccessionNoId);
            }

            CrossPlan crossplan = u_repo.GetCrossPlan(genotype.CrossPlanId.Value);

            if (crossplan != null)
            {
                crossplan.UpdateFromAccession(genotype);
                u_repo.SaveCrossPlan(crossplan);
            }
        }
 public static void CopyCrossPlanViewModel(this CrossPlan dest, CrossPlanViewModel src)
 {
     dest.FemaleParentId  = src.FemaleParentId;
     dest.MaleParentId    = src.MaleParentId;
     dest.CrossTypeId     = src.CrossTypeId;
     dest.Reciprocal      = src.Reciprocal;
     dest.Unsuccessful    = src.Unsuccessful;
     dest.DateCreated     = src.DateCreated;
     dest.Note            = src.Note;
     dest.CrossNum        = src.CrossNum;
     dest.SeedNum         = src.SeedNum;
     dest.TransplantedNum = src.TransplantedNum;
     dest.FieldPlantedNum = src.FieldPlantedNum;
     dest.Purpose         = src.Purpose;
 }
Example #16
0
        /// <summary>
        /// Updates a genotype from a crossplan
        /// </summary>
        /// <param name="cp"></param>
        public void UpdateAccessionFromCrossPlan(CrossPlan cp)
        {
            if (!cp.GenotypeId.HasValue)
            {
                //TODO: Throw error
                return;
            }

            Genotype genotype = u_repo.GetGenotype(cp.GenotypeId.Value);

            if (genotype != null)
            {
                genotype.UpdateFromCrossPlan(cp);
                u_repo.SaveGenotype(genotype);
            }
        }
Example #17
0
        public void SaveAccession(CrossPlanViewModel cpvm)
        {
            var accession = GetNextAccession(cpvm.Id);

            if (!accession.CrossPlanId.HasValue)
            {
                throw new CrossPlanException(Properties.Settings.Default.ExceptionCrossPlanAccessionNoId);
            }

            a_repo.SaveAccessionViewModel(accession);
            CrossPlan cp = u_repo.GetCrossPlan(cpvm.Id);

            cp.GenotypeId = accession.Id;
            u_repo.SaveCrossPlan(cp);
            cpvm = cp.ToCrossPlanningViewModel();
        }
Example #18
0
 public void Save(CrossPlanViewModel crossPlan)
 {
     if (crossPlan.Id > 0)
     {
         var oldplan = u_repo.GetCrossPlan(crossPlan.Id);
         if (oldplan == null)
         {
             throw new CrossPlanException("Invalid Plan");
         }
         oldplan.CopyCrossPlanViewModel(crossPlan);
         Save(oldplan, false);
     }
     else
     {
         CrossPlan cross = crossPlan.ToCrossPlan();
         Save(cross);
     }
 }
Example #19
0
        public void CopyToNextYear(CrossPlan old)
        {
            if (old.Year.IsNullOrWhiteSpace())
            {
                throw new CrossPlanException(Properties.Settings.Default.ExceptionCrossPlanInvalidYear);
            }

            int yearVal = 0;

            int.TryParse(old.Year, out yearVal);
            if (yearVal == 0)
            {
                throw new CrossPlanException(Properties.Settings.Default.ExceptionCrossPlanInvalidYear);
            }

            yearVal++;
            CopyToNewYear(old, yearVal.ToString());
        }
Example #20
0
        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);
        }
        public void InitializeTests()
        {
            AutoMapperConfig.Configure();
            var genus = new Genus
            {
                Id    = 3,
                Name  = "R",
                Value = "Rubus",
                DefaultPlantsInRep = 3,
                VirusLabel1        = "RBDV",
                VirusLabel2        = "ToRSV",
                VirusLabel3        = "SNSV",
                Retired            = false,
                ExternalId         = null,
                VirusLabel4        = "BCRV"
            };
            var cpivm = new CrossPlanIndexViewModel
            {
                GenusId           = 3,
                DefaultOriginName = "testDefaultName",
                NextCrossNumber   = "nextCrossNum",
                CurrentYear       = "2017",
            };
            var crossPlan = new CrossPlan
            {
                Id      = 1,
                GenusId = 3,
                Year    = "2017",
            };
            var userPref = new UserPreference
            {
                UserId  = "fakeUser",
                GenusId = 3
            };
            var defaultOrigin = new Origin
            {
                Id        = 108,
                Name      = "ORUS",
                Retired   = false,
                IsDefault = true
            };
            var families = new List <Family>
            {
                new Family
                {
                    Id               = 1,
                    CrossNum         = "4989",
                    FieldPlantedNum  = 144,
                    TransplantedNum  = null,
                    GenusId          = 3,
                    IsReciprocal     = null,
                    OriginId         = 108,
                    SeedNum          = 749,
                    CrossTypeId      = 17,
                    Purpose          = "Exe SS Y",
                    FemaleParent     = 17290,
                    MaleParent       = 10005,
                    ReciprocalString = "N",
                }
            }.AsQueryable();
            var genotypes = new List <Genotype>
            {
                new Genotype
                {
                    Id           = 1,
                    OriginalName = "OrigName",
                    GivenName    = "GiveName",
                    FamilyId     = 1,
                    Family       = families.First(),
                    CrossPlanId  = 1
                }
            };
            var locations = new List <Location>
            {
                new Location
                {
                    Id      = 1,
                    Address = "SomeAddress",
                }
            };
            var growers = new List <Grower>
            {
                new Grower
                {
                    Id        = 1,
                    FirstName = "FN",
                    LastName  = "LN"
                }
            };
            var orders = new List <Order>
            {
                new Order
                {
                    Id         = 1,
                    Name       = "A",
                    GenusId    = 3,
                    GrowerId   = 1,
                    LocationId = 1,
                    Genus      = genus,
                    Location   = locations[0],
                    Grower     = growers[0]
                }
            };
            var orderProducts = new List <OrderProduct>
            {
                new OrderProduct
                {
                    OrderId    = 1,
                    GenotypeId = 1,
                    Genotype   = genotypes[0],
                    Order      = orders[0]
                }
            };

            mockRepo.Setup(r => r.GetGenus(3)).Returns(genus);
            mockRepo.Setup(r => r.GetCrossPlan(3)).Returns(crossPlan);
            mockRepo.Object.SaveUserPreference(userPref);
            mockRepo.Setup(r => r.GetUserPreference("fakeUser")).Returns(userPref);
            mockRepo.Setup(r => r.GetDefaultOrigin()).Returns(defaultOrigin);
            mockRepo.Setup(r => r.GetOrigin(108)).Returns(defaultOrigin);
            mockRepo.Setup(r => r.GetQueryableFamilies(It.IsAny <Expression <Func <Family, bool> > >())).Returns(families);
            mockRepo.Setup(r => r.GetQueryableFamilies(It.IsAny <string>(), It.IsAny <int>())).Returns(families);
            mockRepo.Setup(r => r.GetOrders()).Returns(orders);
            mockRepo.Setup(r => r.GetOrder(It.IsAny <Expression <Func <Order, bool> > >())).Returns(orders[0]);
            mockRepo.Setup(r => r.GetLocation(1)).Returns(locations[0]);
            mockRepo.Setup(r => r.GetLocations()).Returns(locations);
            mockRepo.Setup(r => r.GetGrower(1)).Returns(growers[0]);
            mockRepo.Setup(r => r.GetGrowers()).Returns(growers);
            mockRepo.Setup(r => r.GetGenotype(1)).Returns(genotypes[0]);
            mockRepo.Setup(r => r.GetGenotypes()).Returns(genotypes);
            mockRepo.Setup(r => r.GetOrderProduct(It.IsAny <Expression <Func <OrderProduct, bool> > >())).Returns(orderProducts[0]);
            mockRepo.Setup(r => r.GetOrderProducts()).Returns(orderProducts);
            HttpContext.Current = FakeHttpContext("fakeUser");
            ordersUOW           = new OrdersUOW(mockRepo.Object);
        }
        public void InitializeTests()
        {
            AutoMapperConfig.Configure();
            var genus = new Genus
            {
                Id    = 3,
                Name  = "R",
                Value = "Rubus",
                DefaultPlantsInRep = 3,
                VirusLabel1        = "RBDV",
                VirusLabel2        = "ToRSV",
                VirusLabel3        = "SNSV",
                Retired            = false,
                ExternalId         = null,
                VirusLabel4        = "BCRV"
            };
            var cpivm = new CrossPlanIndexViewModel
            {
                GenusId           = 3,
                DefaultOriginName = "testDefaultName",
                NextCrossNumber   = "nextCrossNum",
                CurrentYear       = "2017",
            };
            var crossPlan = new CrossPlan
            {
                GenusId = 3,
                Year    = "2017",
            };
            var userPref = new UserPreference
            {
                UserId  = "fakeUser",
                GenusId = 3
            };
            var defaultOrigin = new Origin
            {
                Id        = 108,
                Name      = "ORUS",
                Retired   = false,
                IsDefault = true
            };
            var families = new List <Family>
            {
                new Family
                {
                    Id               = 1,
                    CrossNum         = "4989",
                    FieldPlantedNum  = 144,
                    TransplantedNum  = null,
                    GenusId          = 3,
                    IsReciprocal     = null,
                    OriginId         = 108,
                    SeedNum          = 749,
                    CrossTypeId      = 17,
                    Purpose          = "Exe SS Y",
                    FemaleParent     = 17290,
                    MaleParent       = 10005,
                    ReciprocalString = "N",
                }
            }.AsQueryable();

            mockRepo.Setup(r => r.GetGenus(3)).Returns(genus);
            mockRepo.Setup(r => r.GetCrossPlan(3)).Returns(crossPlan);
            mockRepo.Object.SaveUserPreference(userPref);
            mockRepo.Setup(r => r.GetUserPreference("fakeUser")).Returns(userPref);
            mockRepo.Setup(r => r.GetDefaultOrigin()).Returns(defaultOrigin);
            mockRepo.Setup(r => r.GetOrigin(108)).Returns(defaultOrigin);
            mockRepo.Setup(r => r.GetQueryableFamilies(It.IsAny <Expression <Func <Family, bool> > >())).Returns(families);
            mockRepo.Setup(r => r.GetQueryableFamilies(It.IsAny <string>(), It.IsAny <int>())).Returns(families);

            HttpContext.Current = FakeHttpContext("fakeUser");
        }
Example #23
0
 /// <summary>
 /// Refreshes properties before saving to the repo layer. This method is needed to restore references
 /// </summary>
 /// <param name="crossPlan"></param>
 private void GetDefaultValues(CrossPlan crossPlan)
 {
     GetDefaultValues(crossPlan, u_repo);
 }
Example #24
0
        public void Delete(CrossPlanViewModel crossPlan)
        {
            CrossPlan cross = u_repo.GetCrossPlan(crossPlan.Id);

            u_repo.DeleteCrossPlan(cross);
        }
Example #25
0
 public void Save(CrossPlan crossPlan)
 {
     Save(crossPlan, true);
 }
Example #26
0
        public CrossPlanViewModel GetNextCrossPlan(string year, int genusId)
        {
            CrossPlan cross = GetNext(year, genusId);

            return(cross.ToCrossPlanningViewModel());
        }
Example #27
0
        public void UpdateAccessionFromCrossPlan(CrossPlan cp)
        {
            Genotype genotype = GenotypeFromCrossPlan(cp);

            u_repo.SaveGenotype(genotype);
        }
 public static CrossPlanViewModel ToCrossPlanningViewModel(this CrossPlan crossPlan)
 {
     return(Mapper.Map <CrossPlan, CrossPlanViewModel>(crossPlan));
 }
Example #29
0
        public CrossPlanViewModel GetCrossPlan(int id)
        {
            CrossPlan crossplan = u_repo.GetCrossPlan(id);

            return(crossplan.ToCrossPlanningViewModel());
        }