public bool EditFlowerPlot(Plot flowerPlot) { using (var dbContext = new FlowerPlotsDBContext()) { var isInDb = dbContext.FlowerPlots.Any(c => c.Id == flowerPlot.Id); if (isInDb) { var plot = dbContext.FlowerPlots.FirstOrDefault(c => c.Id == flowerPlot.Id); plot.Area = flowerPlot.Area; plot.MoisturePerc = flowerPlot.MoisturePerc; //plot.Flower = flowerPlot.Flower; plot.Flower = dbContext.Flowers.FirstOrDefault(c => c.Id == flowerPlot.Flower.Id); //plot.Soil = flowerPlot.Soil; plot.Soil = dbContext.SoilTypes.FirstOrDefault(c => c.Id == flowerPlot.Soil.Id); plot.PlantingDate = flowerPlot.PlantingDate; plot.HarvestDate = flowerPlot.HarvestDate; plot.Stage = flowerPlot.Stage; plot.StageImage = flowerPlot.StageImage; dbContext.SaveChanges(); return(true); } else { return(false); } } }
public bool AddNewSoilType(SoilType soilType) { using (var dbContext = new FlowerPlotsDBContext()) { SoilType addedSoilType = dbContext.SoilTypes.Add(soilType); dbContext.SaveChanges(); return(true); } }
public bool AddNewFlower(Flower flower) { using (var dbContext = new FlowerPlotsDBContext()) { Flower addedFlower = dbContext.Flowers.Add(flower); dbContext.SaveChanges(); return(true); } }
public Plot AddFlowerPlot(Plot flowerPlot) { using (var dbContext = new FlowerPlotsDBContext()) { Plot addedFlowerPlot = dbContext.FlowerPlots.Add(flowerPlot); dbContext.SaveChanges(); return(addedFlowerPlot); } }
public bool DuplicateFlowerPlot(Plot flowerPlot) { using (var dbContext = new FlowerPlotsDBContext()) { flowerPlot.Id = dbContext.FlowerPlots.Count() + 1; flowerPlot.Flower = dbContext.Flowers.FirstOrDefault(c => c.Id == flowerPlot.Flower.Id); flowerPlot.Soil = dbContext.SoilTypes.FirstOrDefault(c => c.Id == flowerPlot.Soil.Id); Plot plot = dbContext.FlowerPlots.Add(flowerPlot); dbContext.SaveChanges(); return(true); } }
public bool AddUser(User newUser) { using (var dbContext = new FlowerPlotsDBContext()) { var isInDb = dbContext.Users.Any(u => u.Username.ToLower().Equals(newUser.Username.ToLower())); if (isInDb) { return(false); } User addedUser = dbContext.Users.Add(newUser); dbContext.SaveChanges(); return(true); } }
public bool RemoveFlowerPlot(Plot flowerPlot) { using (var dbContext = new FlowerPlotsDBContext()) { bool isInDb = dbContext.FlowerPlots.Any(c => c.Id == flowerPlot.Id); if (isInDb) { var remove = dbContext.FlowerPlots.FirstOrDefault(c => c.Id == flowerPlot.Id); dbContext.FlowerPlots.Remove(remove); dbContext.SaveChanges(); return(true); } else { return(false); } } }
public bool EditUser(User user) { using (var dbContext = new FlowerPlotsDBContext()) { var isInDb = dbContext.Users.Any(u => u.Username.ToLower().Equals(user.Username.ToLower())); if (isInDb) { var edit = dbContext.Users.FirstOrDefault(u => u.Username.ToLower().Equals(user.Username.ToLower())); edit.Name = user.Name; edit.Password = user.Password; edit.Role = user.Role; edit.Surname = user.Surname; edit.Username = user.Username; dbContext.SaveChanges(); return(true); } return(false); } }