Esempio n. 1
0
 public IEnumerable <Flower> GetFlowers()
 {
     using (var dbContext = new FlowerPlotsDBContext())
     {
         return(dbContext.Flowers.ToList());
     }
 }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
 public IEnumerable <SoilType> GetSoilTypes()
 {
     using (var dbContext = new FlowerPlotsDBContext())
     {
         return(dbContext.SoilTypes.ToList());
     }
 }
Esempio n. 4
0
 public Plot GetFlowerPlot(int id)
 {
     using (var dbContext = new FlowerPlotsDBContext())
     {
         return(dbContext.FlowerPlots.FirstOrDefault(p => p.Id == id));
     }
 }
Esempio n. 5
0
 public User FindUser(string username)
 {
     using (var dbContext = new FlowerPlotsDBContext())
     {
         return(dbContext.Users.FirstOrDefault(u => u.Username.ToLower().Equals(username.ToLower())));
     }
 }
Esempio n. 6
0
        public bool AddNewSoilType(SoilType soilType)
        {
            using (var dbContext = new FlowerPlotsDBContext())
            {
                SoilType addedSoilType = dbContext.SoilTypes.Add(soilType);
                dbContext.SaveChanges();

                return(true);
            }
        }
Esempio n. 7
0
        public bool AddNewFlower(Flower flower)
        {
            using (var dbContext = new FlowerPlotsDBContext())
            {
                Flower addedFlower = dbContext.Flowers.Add(flower);
                dbContext.SaveChanges();

                return(true);
            }
        }
Esempio n. 8
0
        public Plot AddFlowerPlot(Plot flowerPlot)
        {
            using (var dbContext = new FlowerPlotsDBContext())
            {
                Plot addedFlowerPlot = dbContext.FlowerPlots.Add(flowerPlot);
                dbContext.SaveChanges();

                return(addedFlowerPlot);
            }
        }
Esempio n. 9
0
 public IEnumerable <Plot> GetFlowerPlots()
 {
     using (var dbContext = new FlowerPlotsDBContext())
     {
         var flowerPlots = dbContext.FlowerPlots
                           .Include(plot => plot.Flower).Include(plot => plot.Soil)
                           .ToList();
         return(flowerPlots);
     }
 }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        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);
                }
            }
        }
Esempio n. 13
0
        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);
            }
        }