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

                return(true);
            }
        }
Пример #7
0
        public bool AddNewFlower(Flower flower)
        {
            using (var dbContext = new FlowerPlotsDBContext())
            {
                Flower addedFlower = dbContext.Flowers.Add(flower);
                dbContext.SaveChanges();

                return(true);
            }
        }
Пример #8
0
        public Plot AddFlowerPlot(Plot flowerPlot)
        {
            using (var dbContext = new FlowerPlotsDBContext())
            {
                Plot addedFlowerPlot = dbContext.FlowerPlots.Add(flowerPlot);
                dbContext.SaveChanges();

                return(addedFlowerPlot);
            }
        }
Пример #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);
     }
 }
Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #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);
                }
            }
        }
Пример #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);
            }
        }