public void InitializeEmptySeedStorage()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         dbContext.Seeds.RemoveRange(dbContext.Seeds.Where(x => 1 == 1));
         dbContext.SaveChanges();
     }
 }
示例#2
0
 public static IEnumerable <Plant> GetPlantsFromSeedStorage()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         var seedsInStorage  = dbContext.Seeds.ToList().Distinct(new SeedComparer());
         var plantsFromSeeds = seedsInStorage.Select(x => new Plant(x.Flower, x.Stem));
         return(plantsFromSeeds);
     }
 }
示例#3
0
 public void Reseed()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         InitializeEmptyCatalog(dbContext);
         dbContext.AddRange(Plants);
         dbContext.SaveChanges();
     }
 }
 public void SetSeed(Tuple <char, int, int> position, FlowerType flower, StemType stem)
 {
     using (var dbContext = new PlantTycoonContext())
     {
         //var seed = dbContext.Seeds.FirstOrDefault(x => x.Position == position);
         var seed = new Seed(position, flower, stem);
         dbContext.Seeds.Add(seed);
         dbContext.SaveChanges();
     }
 }
 public List <FlowerFormula> ReportAllOrdered()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         var flowerFormulas = dbContext.FlowerFormulas
                              .OrderBy(x => x.FlowerA.ToString())
                              .ThenBy(x => x.FlowerB.ToString());
         return(flowerFormulas.ToList());
     }
 }
 public IEnumerable <Seed> GetSeedsOfUntestedPlants()
 {
     using (dbContext = new PlantTycoonContext())
     {
         var seedsOfTestedPlants   = dbContext.Plants.Select(x => new Seed(Tuple.Create('A', 1, 1), x.Flower, x.Stem));
         var seedsInStorage        = dbContext.Seeds.ToList();
         var seedsOfUntestedPlants = seedsInStorage.Except(seedsOfTestedPlants, seedComparer);
         return(seedsOfUntestedPlants.ToList());
     }
 }
 public List <StemFormula> ReportAllOrdered()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         var stemFormulas = dbContext.StemFormulas
                            .OrderBy(x => x.StemA.ToString())
                            .ThenBy(x => x.StemB.ToString());
         return(stemFormulas.ToList());
     }
 }
 public IEnumerable <Plant> GetUntestedPlants()
 {
     using (dbContext = new PlantTycoonContext())
     {
         var allPlants      = GetAllPossiblePlants();
         var testedPlants   = dbContext.Plants.ToList();
         var untestedPlants = allPlants.Except(testedPlants, plantComparer);
         return(untestedPlants);
     }
 }
 public List <FlowerFormula> ReportForFlowerType(FlowerType flowerType)
 {
     using (var dbContext = new PlantTycoonContext())
     {
         var flowerFormulas = dbContext.FlowerFormulas
                              .Where(x => x.FlowerA == flowerType || x.FlowerB == flowerType)
                              .OrderBy(x => x.FlowerA.ToString())
                              .ThenBy(x => x.FlowerB.ToString());
         return(flowerFormulas.ToList());
     }
 }
        public void InitializeEmptyFlowerResults()
        {
            var flowerFormulas = CalculateAllOrderedFlowerFormulasWithEmptyResult();

            using (var dbContext = new PlantTycoonContext())
            {
                dbContext.FlowerFormulas.RemoveRange(dbContext.FlowerFormulas.Where(x => 1 == 1));
                dbContext.FlowerFormulas.AddRange(flowerFormulas);
                dbContext.SaveChanges();
            }
        }
示例#11
0
 public List <StemFormula> ReportForStemType(StemType stemType)
 {
     using (var dbContext = new PlantTycoonContext())
     {
         var stemFormulas = dbContext.StemFormulas
                            .Where(x => x.StemA == stemType || x.StemB == stemType)
                            .OrderBy(x => x.StemA.ToString())
                            .ThenBy(x => x.StemB.ToString());
         return(stemFormulas.ToList());
     }
 }
示例#12
0
 public List <Seed> ReportSeedsReverse()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         var seeds = dbContext.Seeds
                     .OrderBy(x => x.Stem)
                     .ThenBy(x => x.Flower)
                     .ToList();
         return(seeds);
     }
 }
        public IEnumerable <PlantFormula> GetUntestedPlantFormulasForCurrentPlants(IEnumerable <Plant> currentPlants)
        {
            var formulas = new List <PlantFormula>();

            using (dbContext = new PlantTycoonContext())
            {
                currentPlants.ToList().ForEach(x => formulas.AddRange(GetUntestedPlantFormulasContainingPlant(x)));
            }
            var distinctFormulas = formulas.Distinct(formulaComparer);

            return(distinctFormulas);
        }
示例#14
0
        static void ReseedFormulas()
        {
            //TODO: it's time to rethink dbContext scopes. Use UnitOfWork.
            using (var dbContext = new PlantTycoonContext())
            {
                PlantTycoonDbInitializer.Initialize(dbContext);
            }

            flowerSeeder.Reseed();
            stemSeeder.Reseed();
            seedSeeder.Reseed();
            catalog.Reseed();
        }
        public List <FlowerType?> ReportFlowerTypesWithNoFormula()
        {
            using (var dbContext = new PlantTycoonContext())
            {
                var flowerTypes            = Enum.GetValues(typeof(FlowerType)).Cast <FlowerType?>();
                var flowerTypesWithFormula = dbContext.FlowerFormulas
                                             .Where(x => x.Result != null)
                                             .Select(x => x.Result)
                                             .Distinct();

                var flowerTypesWithNoFormula = flowerTypes
                                               .Except(flowerTypesWithFormula);

                return(flowerTypesWithNoFormula.ToList());
            }
        }
示例#16
0
        private void SetStemFormula(StemType stemA, StemType stemB, StemType?result, bool inProgress)
        {
            using (var dbContext = new PlantTycoonContext())
            {
                var stemFormulas = dbContext.StemFormulas.Where(x => x.StemA == stemA && x.StemB == stemB ||
                                                                x.StemA == stemB && x.StemB == stemA);

                if (stemFormulas.Count() != 1)
                {
                    throw new InvalidOperationException($"There should be one and only one formula for those two stems, but we found {stemFormulas.Count()}");
                }

                stemFormulas.First().SetResultAndInProgress(result, inProgress);
                dbContext.SaveChanges();
            }
        }
        private void SetFlowerFormula(FlowerType flowerA, FlowerType flowerB, FlowerType?result, bool inProgress)
        {
            using (var dbContext = new PlantTycoonContext())
            {
                var flowerFormulas = dbContext.FlowerFormulas.Where(x => x.FlowerA == flowerA && x.FlowerB == flowerB ||
                                                                    x.FlowerA == flowerB && x.FlowerB == flowerA);

                if (flowerFormulas.Count() != 1)
                {
                    throw new InvalidOperationException($"There should be one and only one formula for those two flowers, but we found {flowerFormulas.Count()}");
                }

                flowerFormulas.First().SetResultAndInProgress(result, inProgress);
                dbContext.SaveChanges();
            }
        }
        public IEnumerable <PlantFormula> GetFormulasWithResult(Plant result)
        {
            var formulas = new List <PlantFormula>();

            using (dbContext = new PlantTycoonContext())
            {
                var flowerFormulasWithResult = dbContext.FlowerFormulas.Where(x => x.Result == result.Flower).ToList();
                flowerFormulasWithResult.Add(new FlowerFormula(result.Flower, result.Flower));
                var stemFormulasWithResult = dbContext.StemFormulas.Where(x => x.Result == result.Stem).ToList();
                stemFormulasWithResult.Add(new StemFormula(result.Stem, result.Stem));
                formulas =
                    flowerFormulasWithResult.SelectMany(flowerFormula =>
                                                        stemFormulasWithResult.Select(stemFormula =>
                                                                                      new PlantFormula
                {
                    PlantA = new Plant(flowerFormula.FlowerA, stemFormula.StemA, false),
                    PlantB = new Plant(flowerFormula.FlowerB, stemFormula.StemB, false)
                })).ToList();
            }
            formulas.RemoveAll(x => plantComparer.Equals(x.PlantA, result) || plantComparer.Equals(x.PlantB, result));

            return(formulas);
        }
示例#19
0
 protected void InitializeEmptyCatalog(PlantTycoonContext dbContext)
 {
     dbContext.Plants.RemoveRange(dbContext.Plants.Where(x => 1 == 1));
 }