Exemplo n.º 1
0
 public void InitializeEmptySeedStorage()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         dbContext.Seeds.RemoveRange(dbContext.Seeds.Where(x => 1 == 1));
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 3
0
 public void Reseed()
 {
     using (var dbContext = new PlantTycoonContext())
     {
         InitializeEmptyCatalog(dbContext);
         dbContext.AddRange(Plants);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 4
0
 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();
     }
 }
Exemplo n.º 5
0
 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());
     }
 }
Exemplo n.º 6
0
 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());
     }
 }
Exemplo n.º 7
0
 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());
     }
 }
Exemplo n.º 8
0
 public IEnumerable <Plant> GetUntestedPlants()
 {
     using (dbContext = new PlantTycoonContext())
     {
         var allPlants      = GetAllPossiblePlants();
         var testedPlants   = dbContext.Plants.ToList();
         var untestedPlants = allPlants.Except(testedPlants, plantComparer);
         return(untestedPlants);
     }
 }
Exemplo n.º 9
0
 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());
     }
 }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 15
0
        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());
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 17
0
        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();
            }
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 protected void InitializeEmptyCatalog(PlantTycoonContext dbContext)
 {
     dbContext.Plants.RemoveRange(dbContext.Plants.Where(x => 1 == 1));
 }