public PlantSpecieDTO GetPlantSpecieById(int id)
 {
     using (var context = new PlantAppContext())
     {
         return(context.PlantSpecies.Where(x => x.Id == id).ToList().Select(x => PlantSpecieDTO.FromEntity(x)).FirstOrDefault());
     }
 }
Ejemplo n.º 2
0
 public SeedlingDTO GetSeedlingById(int id)
 {
     using (var context = new PlantAppContext())
     {
         return(context.Seedlings.Where(x => x.Id == id).ToList().Select(x => SeedlingDTO.FromEntity(x)).FirstOrDefault());
     }
 }
 public List <PlantSpecieDTO> GetAllPlantSpecies()
 {
     using (var context = new PlantAppContext())
     {
         return(context.PlantSpecies.ToList().Select(x => PlantSpecieDTO.FromEntity(x)).ToList());
     }
 }
Ejemplo n.º 4
0
 public List <SeedlingDTO> GetAllSeedlings()
 {
     using (var context = new PlantAppContext())
     {
         var seedlings = context.Seedlings.ToList().Select(x => SeedlingDTO.FromEntity(x)).ToList();
         return(seedlings);
     }
 }
 public void DeletePlant(HttpRequestMessage request,
                         [FromBody] PlantSpecie plantSpecie)
 {
     using (var context = new PlantAppContext())
     {
         context.Entry(plantSpecie).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void AddSeedling(HttpRequestMessage request,
                         [FromBody] Seedling seedling)
 {
     using (var context = new PlantAppContext())
     {
         context.Seedlings.Add(seedling);
         context.SaveChanges();
     }
 }
Ejemplo n.º 7
0
        public void DeletePlant(int id)
        {
            using (var context = new PlantAppContext())
            {
                var plant = context.Plants.Where(x => x.Id == id).FirstOrDefault();

                context.Entry(plant).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
        // syntax to receive a complex object:
        public string UpdatePlant(HttpRequestMessage request,
                                  [FromBody] PlantSpecie plantSpecie)
        {
            using (var context = new PlantAppContext())
            {
                context.Entry(plantSpecie).State = EntityState.Modified;
                context.SaveChanges();
            }

            return("Changes have been saved");
        }
        public string AddNewPlantSpecie(HttpRequestMessage request,
                                        [FromBody] PlantSpecie newPlantSpecie)
        {
            using (var context = new PlantAppContext())
            {
                context.PlantSpecies.Add(newPlantSpecie);
                context.SaveChanges();

                return("Added new plant specie");
            }
        }
Ejemplo n.º 10
0
        public void DeleteSeedling(int id)
        {
            using (var context = new PlantAppContext())
            {
                var seedling = context.Seedlings.Where(x => x.Id == id).FirstOrDefault();

                for (int i = 0; i < seedling.Plants.ToList().Count(); i++)
                {
                    context.Entry(seedling.Plants.ToList()[i]).State = EntityState.Deleted;
                }

                context.Entry(seedling).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public int CalculateWaterVolume(int id)
        {
            int totalVolume = 0;

            using (var context = new PlantAppContext())
            {
                var seedling = context.Seedlings.Where(x => x.Id == id).FirstOrDefault();

                foreach (var plant in seedling.Plants)
                {
                    totalVolume += DateTime.Now.Subtract((DateTime)plant.TimeAndDateLastWatered).TotalDays > plant.PlantSpecie.WateringFrequencyDays ? plant.PlantSpecie.MinimalWaterAmountForWatering : 0;
                }

                return(totalVolume);
            }
        }
Ejemplo n.º 12
0
        public string WaterPlants(int id)
        {
            using (var context = new PlantAppContext())
            {
                var plants = context.Seedlings.Where(x => x.Id == id).FirstOrDefault().Plants;

                foreach (var plant in plants)
                {
                    plant.TimeAndDateLastWatered = DateTime.Now;
                    context.Entry(plant).State   = EntityState.Modified;
                    context.SaveChanges();
                }
            }

            return("Plants have been watered");
        }
Ejemplo n.º 13
0
        public void AddPlant(string newName, int id)
        {
            using (var context = new PlantAppContext())
            {
                var seedling = context.Seedlings.Where(x => x.Id == id).FirstOrDefault();

                Plant plant = new Plant()
                {
                    PlantSpecie            = context.PlantSpecies.Where(x => x.Name == newName).FirstOrDefault(),
                    Seedling               = seedling,
                    TimeAndDateLastWatered = DateTime.Now
                };

                context.Plants.Add(plant);
                context.SaveChanges();
            }
        }