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(); } }
public void DeletePlant(HttpRequestMessage request, [FromBody] PlantSpecie plantSpecie) { using (var context = new PlantAppContext()) { context.Entry(plantSpecie).State = EntityState.Deleted; context.SaveChanges(); } }
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 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"); }