Ejemplo n.º 1
0
 public void AddSeedling(HttpRequestMessage request,
                         [FromBody] Seedling seedling)
 {
     using (var context = new PlantAppContext())
     {
         context.Seedlings.Add(seedling);
         context.SaveChanges();
     }
 }
 public void DeletePlant(HttpRequestMessage request,
                         [FromBody] PlantSpecie plantSpecie)
 {
     using (var context = new PlantAppContext())
     {
         context.Entry(plantSpecie).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
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.º 6
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.º 7
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.º 8
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();
            }
        }