Beispiel #1
0
        public void SaveIndex(CrossPlanIndexViewModel crossIndex)
        {
            List <CrossPlan> allPlans            = crossIndex.CrossPlans.ToCrossPlan().ToList();
            List <CrossPlan> crossPlans          = new List <CrossPlan>();
            List <Task>      saveCrossPlansTasks = new List <Task>();
            int size = 12;

            foreach (CrossPlan cp in allPlans)
            {
                if (!IsEmptyCrossPlan(cp))
                {
                    crossPlans.Add(cp);
                }
            }

            List <List <CrossPlan> > planLists = crossPlans.Partition(size).ToList();

            foreach (List <CrossPlan> cplan in planLists)
            {
                Task task = new Task(() => SaveCrossPlanAsync(cplan));
                task.Start();
                saveCrossPlansTasks.Add(task);
            }
            Task updateAccessionTask = new Task(() => UpdateAccessionFromCrossPlan(crossPlans));

            updateAccessionTask.Start();

            Task.WaitAll(saveCrossPlansTasks.ToArray());
        }
        public ActionResult OrderByParent(CrossPlanIndexViewModel cpvm)
        {
            var plans = cpvm.CrossPlans;

            plans           = c_repo.OrderByParents(plans).ToList();
            cpvm.CrossPlans = plans.OrderBy(t => t.FemaleParentName).ToList();

            return(Json(cpvm));
        }
        public ActionResult OrderByDefault(CrossPlanIndexViewModel cpvm)
        {
            var plans = cpvm.CrossPlans;

            plans           = c_repo.DefaultOrder(plans).ToList();
            cpvm.CrossPlans = plans;

            return(Json(cpvm));
        }
        public ActionResult Index(CrossPlanIndexViewModel cpvm)
        {
            if (ModelState.IsValid)
            {
                c_repo.SaveIndex(cpvm);
                int    genusId = SessionManager.GetGenusId().Value;
                string year    = cpvm.CurrentYear;
                cpvm = c_repo.GetIndex(year, genusId);
            }

            return(Json(cpvm));
        }
        public ActionResult Index(string year, int?genusId)
        {
            if (genusId == null)
            {
                genusId = SessionManager.GetGenusId().Value;
            }
            Genus genus = m_repo.GetGenus(genusId.Value);

            //TODO: check for valid year
            if (year.IsNullOrWhiteSpace())
            {
                year = DateTime.Now.Year.ToString();
            }
            CrossPlanIndexViewModel crossPlanIndex = c_repo.GetIndex(year, genusId.Value);

            ViewBag.GenusId    = genusId;
            ViewBag.CrossTypes = crossPlanIndex.CrossTypes;
            return(View(crossPlanIndex));
        }
        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");
        }